972bb9554942f6a7e4ad55ba5276dd26f7d38994
1 #!/bin/bash
2 # This code is part of GOsa (http://www.gosa-project.org)
3 # Copyright (C) 2008 GONICUS GmbH
4 #
5 # ID: $$Id$$
6 #
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
11 #
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 # Define defaults
22 RELEASE_REASON="GOsa svn snapshot"
23 BRANCH="trunk"
24 SECTION="web"
25 SI_SECTION="utils"
26 TARGET_RELEASE="etch"
27 MAKE_PLUGINS=""
28 MAKE_GOTO=""
29 GOTO=""
30 PBUILDER=""
31 NOT_RELEASED="heimdal dak dfs glpi apache2"
32 GOTO_NOT_RELEASED="apache-directory-studio goto-cd libresourcepool-net-ldap-perl-1.002 libresourcepool-perl-1.0104 openproj ptc syslinux konch ldm openssh-4.3p2"
33 DEBIAN_PKG="remove"
34 NO_SVN="use"
35 EXTRACT=`pwd`
37 usage() {
38 cat <<-EOF
39 GOsa Debian package build tool. Build snapshots from selected SVN locations or local directories.
40 Usage: ${0##*/} [options]
42 Options:
43 -b|--branch Branch to export [$BRANCH]
44 -p|--plugins Comma seperate list of plugins to build. Leave empty to build all.
45 -e|--experimental Build not released plugins (for testers and developers only)
46 -r|--release Debian release to build for [$TARGET_RELEASE]
47 -c|--changelog Debian changelog entry [$RELEASE_REASON]
48 -s|--section Debian section to place GOsa in [$SECTION]
49 -i|--si-section Debian section to place GOsa-SI in [$SI_SECTION]
50 -d|--debian-pkg Don't clear up debian packages for plugins (for developers only)
51 -n|--no-svn Don't extract gosa from svn (when internet connectivity is not present)
52 -x|--extract-dir Directory where the checkout is for no-svn
53 -g|--build-goto Build the goto2 packages
54 -l|--use-pbuilder Use pbuilder to build the packages
55 -h|--help this help
57 EOF
58 exit 1
59 }
61 for cmd in dh-make-gosa debchange dpkg-buildpackage dpkg-source svn; do
62 if ! which $cmd >/dev/null; then
63 echo "Error: cannot find '$cmd' command in path!";
64 exit 1
65 fi
66 done
68 # Import command line parameters
69 PARMS=`getopt -o e::d::b:r:s:c:i:p:n:x:g::l::,h --long branch:,changelog:,plugins:,section:,si-section:,release:,help -n "${0##*/}" -- "$@"`
70 eval set -- "$PARMS"
72 while true; do
73 case "$1" in
74 -b|--branch)
75 BRANCH=$2; shift 2 ;;
76 -r|--release)
77 TARGET_RELEASE=$2; shift 2 ;;
78 -c|--changelog)
79 RELEASE_REASON=$2; shift 2 ;;
80 -p|--plugins)
81 MAKE_PLUGINS=$(echo $2 | tr ',' ' '); shift 2 ;;
82 -e|--experimental)
83 NOT_RELEASED=""; shift 2;;
84 -s|--section)
85 SECTION=$2; shift 2 ;;
86 -i|--si-section)
87 SI_SECTION=$2; shift 2 ;;
88 -d|--debian-pkg)
89 DEBIAN_PKG=""; shift 2 ;;
90 -n|--no-svn)
91 NO_SVN=""; shift 2;;
92 -x|--extract-dir)
93 EXTRACT=$2; shift 2;;
94 -g|--build-goto)
95 GOTO="use"; shift 2;;
96 -l|--use-pbuilder)
97 PBUILDER="use"; shift 2;;
98 -h|--help)
99 usage ;;
100 --)
101 shift; break ;;
102 *)
103 echo "getopt error" ;;
104 esac
105 done
107 if [ "$NO_SVN" = "use" ]
108 then
109 echo "Loading svn information for gosa '${BRANCH}'..."
110 svn co -N https://oss.gonicus.de/repositories/gosa/${BRANCH} gosa-info/ > /dev/null
111 BRANCH_REV=$(LANG=C svn info gosa-info | sed -n -e 's/^Last Changed Rev: \([0-9]*\).*$/\1/p')
112 rm -rf gosa-info
114 echo "Loading svn information for goto '${BRANCH}'..."
115 svn co -N https://oss.gonicus.de/repositories/goto/${BRANCH} goto-info/ > /dev/null
116 GOTO_BRANCH_REV=$(LANG=C svn info goto-info | sed -n -e 's/^Last Changed Rev: \([0-9]*\).*$/\1/p')
117 rm -rf goto-info
119 else
120 echo "Loading svn information for gosa '${BRANCH}' from local checkout ..."
121 BRANCH_REV=$(LANG=C svn info $EXTRACT/gosa-core | sed -n -e 's/^Last Changed Rev: \([0-9]*\).*$/\1/p')
123 if [ "$GOTO" = "use" ]
124 then
125 echo "Loading svn information for goto '${BRANCH}' from local checkout ..."
126 GOTO_BRANCH_REV=$(LANG=C svn info $EXTRACT/goto | sed -n -e 's/^Last Changed Rev: \([0-9]*\).*$/\1/p')
127 fi
128 fi
130 if [ "$NO_SVN" = "use" ]
131 then
132 # Load current revision from logs
133 VERSION=$(svn cat -r "${BRANCH_REV}" https://oss.gonicus.de/repositories/gosa/${BRANCH}/gosa-core/debian/changelog \
134 | head -n 1 | sed -n -e 's/.*(\([^-]*\).*/\1/p')
135 if [ "$BRANCH" == "trunk" ]; then
136 GOSA_VER="${VERSION}+svn${BRANCH_REV}"
138 if [ "$GOTO" = "use" ]
139 then
140 GOTO_VER="+svn${GOTO_BRANCH_REV}"
141 fi
142 else
143 GOSA_VER="${VERSION}"
145 if [ "$GOTO" = "use" ]
146 then
147 GOTO_VER=""
148 fi
150 fi
152 else
153 # Load current revision from logs
154 VERSION=$(cat $EXTRACT/gosa-core/debian/changelog | head -n 1 | sed -n -e 's/.*(\([^-]*\).*/\1/p')
156 if [ "$BRANCH" == "trunk" ]; then
157 GOSA_VER="${VERSION}+svn${BRANCH_REV}"
158 else
159 GOSA_VER="${VERSION}"
160 fi
161 echo $GOSA_VER
162 fi
164 GOSA_DIR="gosa-${GOSA_VER}"
166 ORIG_FILE="gosa_${GOSA_VER}.orig.tar.gz"
168 if [ "$NO_SVN" = "use" ]
169 then
170 # Export from svn...
171 BNAME=$(basename $BRANCH)
172 [ -d "gosa-${BNAME}" ] && rm -rf gosa-$BNAME
173 echo "Exporting current GOsa (rev: ${BRANCH_REV}) from '${BRANCH}'..."
174 svn export -r "${BRANCH_REV}" https://oss.gonicus.de/repositories/gosa/${BRANCH}/gosa-core gosa-${BNAME} > /dev/null
175 svn export -r "${BRANCH_REV}" https://oss.gonicus.de/repositories/gosa/${BRANCH}/gosa-si gosa-si-${BNAME} > /dev/null
176 svn export -r "${BRANCH_REV}" https://oss.gonicus.de/repositories/gosa/${BRANCH}/gosa-plugins gosa-plugins-${BNAME} > /dev/null
178 if [ "$GOTO" = "use" ]
179 then
180 echo "Exporting current GOto (rev: ${GOTO_BRANCH_REV}) from '${BRANCH}'..."
181 svn export -r "${GOTO_BRANCH_REV}" https://oss.gonicus.de/repositories/goto/${BRANCH}/ goto-${BNAME} > /dev/null
182 fi
183 else
184 # Export from local checkout...
185 echo "Exporting current GOsa (rev: ${BRANCH_REV}) from localcheckout '${BRANCH}'..."
186 BNAME=$(basename $BRANCH)
187 cp -r gosa-core gosa-${GOSA_VER}
188 mv gosa-si gosa-si-${GOSA_VER}
189 mv gosa-plugins gosa-plugins-${BNAME}
191 if [ "$GOTO" = "use" ]
192 then
193 echo "Exporting current GOto (rev: ${GOTO_BRANCH_REV}) from localcheckout '${BRANCH}'..."
194 BNAME=$(basename $BRANCH)
195 mv goto goto-${BNAME}
196 fi
197 fi
199 if [ "$NO_SVN" = "use" ]
200 then
201 VERSION=$(cat "gosa-${BNAME}/debian/changelog" | head -n 1 | sed -n -e 's/.*(\([^-]*\).*/\1/p')
202 fi
204 GOSA_DIR="gosa-${GOSA_VER}"
205 GOSA_SI_DIR="gosa-si-${GOSA_VER}"
206 GOTO_DIR="goto-${BNAME}"
208 if [ "$NO_SVN" = "use" ]
209 then
210 if [ "$BNAME" != "$GOSA_VER" ]
211 then
212 rm -rf "gosa-${GOSA_VER}"
213 fi
214 fi
216 if [ "$NO_SVN" = "use" ]
217 then
218 if [ "$BNAME" != "$GOSA_VER" ]
219 then
220 mv "gosa-${BNAME}" "gosa-${GOSA_VER}"
221 mv "gosa-si-${BNAME}" "gosa-si-${GOSA_VER}"
222 fi
223 fi
225 echo "cleaning svn entries from sources"
226 find ${GOSA_DIR} -type d -name ".svn" -exec rm -rf {} \; >/dev/null 2>&1
227 find ${GOSA_SI_DIR} -type d -name ".svn" -exec rm -rf {} \; >/dev/null 2>&1
228 find gosa-plugins-${BNAME} -type d -name ".svn" -exec rm -rf {} \; >/dev/null 2>&1
230 if [ "$GOTO" = "use" ]
231 then
232 find goto-${BNAME} -type d -name ".svn" -exec rm -rf {} \; >/dev/null 2>&1
233 fi
235 echo "Creating original sources 'gosa-${GOSA_VER}'..."
236 tar -c --exclude "${GOSA_DIR}"/debian -f "gosa_${GOSA_VER}.orig.tar" "${GOSA_DIR}"
237 tar -c --exclude "${GOSA_SI_DIR}"/debian -f "gosa-si_${GOSA_VER}.orig.tar" "${GOSA_SI_DIR}"
239 echo "Compressing sources..."
240 gzip -f -9 "gosa_${GOSA_VER}.orig.tar"
241 gzip -f -9 "gosa-si_${GOSA_VER}.orig.tar"
243 export OVERRIDE_VERSION="$GOSA_VER"
244 if [ -z "$MAKE_PLUGINS" ]; then
245 MAKE_PLUGINS=$(ls -1 gosa-plugins-${BNAME}/*/plugin.dsc | sed 's/^.*\/\([^\/]*\)\/plugin.dsc$/\1/')
246 for i in $NOT_RELEASED; do
247 MAKE_PLUGINS=$(echo -n $MAKE_PLUGINS | sed "s/$i//")
248 done
249 fi
251 if [ "TARGET_RELEASE" == "etch" ]; then
252 NOBREAKS="--no-break"
253 fi
255 for plugin in $MAKE_PLUGINS; do
257 GOSA_PLUG_DIR="gosa-plugin-$plugin-${GOSA_VER}"
259 echo "gosa plugin dir" $GOSA_PLUG_DIR
261 mv "gosa-plugins-${BNAME}/$plugin" .
263 echo "Debianizing plugin $plugin"
264 yes | dh-make-gosa $NOBREAKS --section $SECTION $plugin
265 rm -rf "$plugin"
267 echo "Packing original sources 'gosa-plugin-$plugin-${GOSA_VER}'..."
268 tar -c --exclude "gosa-plugin-${plugin}-${GOSA_VER}/debian" -f "gosa-plugin-${plugin}_${GOSA_VER}.orig.tar" "${GOSA_PLUG_DIR}"
270 echo "Compressing sources..."
271 gzip -f -9 "gosa-plugin-${plugin}_${GOSA_VER}.orig.tar"
272 done
274 rm -rf gosa-plugins-${BNAME}
276 if [ "$GOTO" = "use" ]
277 then
278 MAKE_GOTO=$(ls -1 goto-${BNAME}/)
280 for i in $GOTO_NOT_RELEASED; do
281 MAKE_GOTO=$(echo -n $MAKE_GOTO | sed "s/$i//")
282 done
284 for goto in $MAKE_GOTO; do
286 mv "goto-${BNAME}/$goto" .
288 echo "Packing original sources '$goto'..."
289 GOTO_VERSION=$(cat $goto/debian/changelog | head -n 1 | sed -n -e 's/.*(\([^-]*\).*/\1/p')
291 if [ "$GOTO_VER" = "" ]
292 then
293 tar -c --exclude "$goto/debian" -f "${goto}_${GOTO_VERSION}.orig.tar" $goto
294 echo "Compressing sources..."
295 gzip -f -9 "${goto}_${GOTO_VERSION}.orig.tar"
296 else
297 tar -c --exclude "$goto/debian" -f "${goto}_${GOTO_VERSION}${GOTO_VER}.orig.tar" $goto
299 echo "Compressing svn sources..."
300 gzip -f -9 "${goto}_${GOTO_VERSION}${GOTO_VER}.orig.tar"
302 echo "Adapting version in $goto"
303 (cd "$goto"; echo | debchange -v "${GOTO_VERSION}${GOTO_VER}-1${TARGET_RELEASE}1" -D "$TARGET_RELEASE" "$RELEASE_REASON")
304 fi
306 done
308 rm -rf goto-${BNAME}
309 fi
311 echo "Deploying patches..."
312 for patch in $(find patches -type f | grep -v .svn); do
314 if echo $patch | grep -q gosa-plugin; then
315 plugin=$(echo $patch | sed 's/^.*gosa-plugin-\([^-]*\).*$/\1/g')
316 echo "* gosa-plugin-$plugin patch: $patch"
317 [ -d "gosa-plugin-${plugin}-${GOSA_VER}/debian/patches" ] || mkdir -p "gosa-plugin-${plugin}-${GOSA_VER}/debian/patches"
318 cp "$patch" gosa-plugin-${plugin}-${GOSA_VER}/debian/patches
319 else
320 echo "* gosa-core patch: $patch"
321 [ -d "${GOSA_DIR}/debian/patches" ] && mkdir -p "${GOSA_DIR}/debian/patches"
322 cp "$patch" ${GOSA_DIR}/debian/patches
323 fi
324 done
326 # Put section in GOsa_DIR
327 sed -i "s#^Section: web#Section: $SECTION#g" ${GOSA_DIR}/debian/control
328 sed -i "s#^Section: utils#Section: $SI_SECTION#g" ${GOSA_SI_DIR}/debian/control
330 for plugin in $MAKE_PLUGINS; do
331 GOSA_PLUGIN_DIRS="$GOSA_PLUGIN_DIRS gosa-plugin-$plugin-${GOSA_VER}"
332 done
334 if [ "$GOTO" = "use" ]
335 then
336 for goto in $MAKE_GOTO; do
337 GOTO_DIRS="$GOTO_DIRS $goto"
338 done
339 fi
341 for dir in $GOSA_DIR $GOSA_SI_DIR $GOSA_PLUGIN_DIRS; do
342 echo "Adapting version in $dir"
343 if [ "$TARGET_RELEASE" == "unstable" ]; then
344 (cd "$dir"; echo | debchange -v "${GOSA_VER}" "$RELEASE_REASON" >/dev/null 2>&1)
345 else
346 (cd "$dir"; echo | debchange -v "${GOSA_VER}-1${TARGET_RELEASE}1" -D "$TARGET_RELEASE" "$RELEASE_REASON" >/dev/null 2>&1)
347 fi
348 [ -d $dir/debian/patches ] || continue
349 echo "Creating patch list for $dir"
350 ls -1 $dir/debian/patches | grep -v 00list | sed 's%^.*/%%g' > $dir/debian/patches/00list
351 done
353 # Update revision
354 sed -i "s/^\$svn_revision = .*$/\$svn_revision = '\$Revision: $BRANCH_REV \$';/g" $GOSA_DIR/include/functions.inc
356 if [ "$1" = "-s" ]
357 then
358 echo "Creating debian sources..."
359 for dir in $GOSA_DIR $GOSA_SI_DIR $GOSA_PLUGIN_DIRS; do
360 dpkg-source -b "$dir"
361 done
363 if [ "$GOTO" = "use" ]
364 then
365 echo "Creating GOto sources..."
366 for dir in $GOTO_DIRS; do
367 dpkg-source -b "$dir"
368 done
369 fi
370 else
371 echo "Creating debian packages..."
373 for dir in $GOSA_DIR $GOSA_SI_DIR $GOSA_PLUGIN_DIRS; do
374 if [ "$PBUILDER" = "use" ]
375 then
376 echo "using pbuilder to build gosa gosa-si gosa-plugins"
377 (cd "$dir"; pdebuild --debbuildopts -sa; debsign)
378 else
379 (cd "$dir"; dpkg-buildpackage -k$DEBSIGN_KEYID -rfakeroot -sa)
380 fi
381 done
383 if [ "$GOTO" = "use" ]
384 then
385 echo "Creating GOto debian packages..."
386 for dir in $GOTO_DIRS; do
387 if [ "$PBUILDER" = "use" ]
388 then
389 echo "using pbuilder to build goto debian packages"
390 (cd "$dir"; pdebuild --debbuildopts -sa; debsign -k$DEBSIGN_KEYID)
391 else
392 (cd "$dir"; dpkg-buildpackage -k$DEBSIGN_KEYID -rfakeroot -sa)
393 fi
394 done
395 fi
396 fi
398 echo "Removing gosa snapshot..."
399 if [ -z "$DEBIAN_PKG" ]
400 then
401 if [ "$NO_SVN" = "use" ]
402 then
403 for dir in $GOSA_DIR; do
404 rm -rf "$dir"
405 done
406 fi
407 else
408 for dir in $GOSA_DIR $GOSA_SI_DIR $GOSA_PLUGIN_DIRS; do
409 rm -rf "$dir"
410 done
412 if [ "$GOTO" = "use" ]
413 then
414 for dir in $GOTO_DIRs; do
415 rm -rf "$dir"
416 done
417 fi
418 fi