1 #!/bin/sh
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"
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}"
137 else
138 GOSA_VER="${VERSION}"
139 fi
141 else
142 # Load current revision from logs
143 VERSION=$(cat $EXTRACT/gosa-core/debian/changelog | head -n 1 | sed -n -e 's/.*(\([^-]*\).*/\1/p')
145 if [ "$BRANCH" == "trunk" ]; then
146 GOSA_VER="${VERSION}+svn${BRANCH_REV}"
147 else
148 GOSA_VER="${VERSION}"
149 fi
150 echo $GOSA_VER
151 fi
153 GOSA_DIR="gosa-${GOSA_VER}"
155 ORIG_FILE="gosa_${GOSA_VER}.orig.tar.gz"
157 if [ "$NO_SVN" = "use" ]
158 then
159 # Export from svn...
160 BNAME=$(basename $BRANCH)
161 [ -d "gosa-${BNAME}" ] && rm -rf gosa-$BNAME
162 echo "Exporting current GOsa (rev: ${BRANCH_REV}) from '${BRANCH}'..."
163 svn export -r "${BRANCH_REV}" https://oss.gonicus.de/repositories/gosa/${BRANCH}/gosa-core gosa-${BNAME} > /dev/null
164 svn export -r "${BRANCH_REV}" https://oss.gonicus.de/repositories/gosa/${BRANCH}/gosa-si gosa-si-${BNAME} > /dev/null
165 svn export -r "${BRANCH_REV}" https://oss.gonicus.de/repositories/gosa/${BRANCH}/gosa-plugins gosa-plugins-${BNAME} > /dev/null
167 if [ "$GOTO" = "use" ]
168 then
169 echo "Exporting current GOto (rev: ${GOTO_BRANCH_REV}) from '${BRANCH}'..."
170 svn export -r "${GOTO_BRANCH_REV}" https://oss.gonicus.de/repositories/goto/${BRANCH}/ goto-${BNAME} > /dev/null
171 fi
172 else
173 # Export from local checkout...
174 echo "Exporting current GOsa (rev: ${BRANCH_REV}) from localcheckout '${BRANCH}'..."
175 BNAME=$(basename $BRANCH)
176 cp -r gosa-core gosa-${GOSA_VER}
177 mv gosa-si gosa-si-${GOSA_VER}
178 mv gosa-plugins gosa-plugins-${BNAME}
180 if [ "$GOTO" = "use" ]
181 then
182 echo "Exporting current GOto (rev: ${GOTO_BRANCH_REV}) from localcheckout '${BRANCH}'..."
183 BNAME=$(basename $BRANCH)
184 mv goto goto-${BNAME}
185 fi
186 fi
188 if [ "$NO_SVN" = "use" ]
189 then
190 VERSION=$(cat "gosa-${BNAME}/debian/changelog" | head -n 1 | sed -n -e 's/.*(\([^-]*\).*/\1/p')
191 fi
193 GOSA_DIR="gosa-${GOSA_VER}"
194 GOSA_SI_DIR="gosa-si-${GOSA_VER}"
195 GOTO_DIR="goto-${BNAME}"
197 if [ "$NO_SVN" = "use" ]
198 then
199 if [ "$BNAME" != "$GOSA_VER" ]
200 then
201 rm -rf "gosa-${GOSA_VER}"
202 fi
203 fi
205 if [ "$NO_SVN" = "use" ]
206 then
207 if [ "$BNAME" != "$GOSA_VER" ]
208 then
209 mv "gosa-${BNAME}" "gosa-${GOSA_VER}"
210 mv "gosa-si-${BNAME}" "gosa-si-${GOSA_VER}"
211 fi
212 fi
214 echo "cleaning svn entries from sources"
215 find ${GOSA_DIR} -type d -name ".svn" -exec rm -rf {} \; >/dev/null 2>&1
216 find ${GOSA_SI_DIR} -type d -name ".svn" -exec rm -rf {} \; >/dev/null 2>&1
217 find gosa-plugins-${BNAME} -type d -name ".svn" -exec rm -rf {} \; >/dev/null 2>&1
219 if [ "$GOTO" = "use" ]
220 then
221 find goto-${BNAME} -type d -name ".svn" -exec rm -rf {} \; >/dev/null 2>&1
222 fi
224 echo "Creating original sources 'gosa-${GOSA_VER}'..."
225 tar -c --exclude "${GOSA_DIR}"/debian -f "gosa_${GOSA_VER}.orig.tar" "${GOSA_DIR}"
226 tar -c --exclude "${GOSA_SI_DIR}"/debian -f "gosa-si_${GOSA_VER}.orig.tar" "${GOSA_SI_DIR}"
228 echo "Compressing sources..."
229 gzip -f -9 "gosa_${GOSA_VER}.orig.tar"
230 gzip -f -9 "gosa-si_${GOSA_VER}.orig.tar"
232 export OVERRIDE_VERSION="$GOSA_VER"
233 if [ -z "$MAKE_PLUGINS" ]; then
234 MAKE_PLUGINS=$(ls -1 gosa-plugins-${BNAME}/*/plugin.dsc | sed 's/^.*\/\([^\/]*\)\/plugin.dsc$/\1/')
235 for i in $NOT_RELEASED; do
236 MAKE_PLUGINS=$(echo -n $MAKE_PLUGINS | sed "s/$i//")
237 done
238 fi
240 for plugin in $MAKE_PLUGINS; do
242 GOSA_PLUG_DIR="gosa-plugin-$plugin-${GOSA_VER}"
244 echo "gosa plugin dir" $GOSA_PLUG_DIR
246 mv "gosa-plugins-${BNAME}/$plugin" .
248 echo "Debianizing plugin $plugin"
249 yes | dh-make-gosa --section $SECTION $plugin
250 rm -rf "$plugin"
252 echo "Packing original sources 'gosa-plugin-$plugin-${GOSA_VER}'..."
253 tar -c --exclude "gosa-plugin-${plugin}-${GOSA_VER}/debian" -f "gosa-plugin-${plugin}_${GOSA_VER}.orig.tar" "${GOSA_PLUG_DIR}"
255 echo "Compressing sources..."
256 gzip -f -9 "gosa-plugin-${plugin}_${GOSA_VER}.orig.tar"
257 done
259 rm -rf gosa-plugins-${BNAME}
261 if [ "$GOTO" = "use" ]
262 then
263 MAKE_GOTO=$(ls -1 goto-${BNAME}/)
265 for i in $GOTO_NOT_RELEASED; do
266 MAKE_GOTO=$(echo -n $MAKE_GOTO | sed "s/$i//")
267 done
269 for goto in $MAKE_GOTO; do
270 mv "goto-${BNAME}/$goto" .
271 done
273 rm -rf goto-${BNAME}
274 fi
276 echo "Deploying patches..."
277 for patch in $(find patches -type f | grep -v .svn); do
279 if echo $patch | grep -q gosa-plugin; then
280 plugin=$(echo $patch | sed 's/^.*gosa-plugin-\([^-]*\).*$/\1/g')
281 echo "* gosa-plugin-$plugin patch: $patch"
282 [ -d "gosa-plugin-${plugin}-${GOSA_VER}/debian/patches" ] || mkdir -p "gosa-plugin-${plugin}-${GOSA_VER}/debian/patches"
283 cp "$patch" gosa-plugin-${plugin}-${GOSA_VER}/debian/patches
284 else
285 echo "* gosa-core patch: $patch"
286 [ -d "${GOSA_DIR}/debian/patches" ] && mkdir -p "${GOSA_DIR}/debian/patches"
287 cp "$patch" ${GOSA_DIR}/debian/patches
288 fi
289 done
291 # Put section in GOsa_DIR
292 sed -i "s#^Section: web#Section: $SECTION#g" ${GOSA_DIR}/debian/control
293 sed -i "s#^Section: utils#Section: $SI_SECTION#g" ${GOSA_SI_DIR}/debian/control
295 for plugin in $MAKE_PLUGINS; do
296 GOSA_PLUGIN_DIRS="$GOSA_PLUGIN_DIRS gosa-plugin-$plugin-${GOSA_VER}"
297 done
299 if [ "$GOTO" = "use" ]
300 then
301 for goto in $MAKE_GOTO; do
302 GOTO_DIRS="$GOTO_DIRS $goto"
303 done
304 fi
306 for dir in $GOSA_DIR $GOSA_SI_DIR $GOSA_PLUGIN_DIRS; do
307 echo "Adapting version in $dir"
308 if [ "$TARGET_RELEASE" == "unstable" ]; then
309 (cd "$dir"; echo | debchange -v "${GOSA_VER}" "$RELEASE_REASON" >/dev/null 2>&1)
310 else
311 (cd "$dir"; echo | debchange -v "${GOSA_VER}-1${TARGET_RELEASE}1" -D "$TARGET_RELEASE" "$RELEASE_REASON" >/dev/null 2>&1)
312 fi
313 [ -d $dir/debian/patches ] || continue
314 echo "Creating patch list for $dir"
315 ls -1 $dir/debian/patches | grep -v 00list | sed 's%^.*/%%g' > $dir/debian/patches/00list
316 done
318 # Update revision
319 sed -i "s/^\$svn_revision = .*$/\$svn_revision = '\$Revision: $BRANCH_REV \$';/g" $GOSA_DIR/include/functions.inc
321 if [ "$1" = "-s" ]
322 then
323 echo "Creating debian sources..."
324 for dir in $GOSA_DIR $GOSA_SI_DIR $GOSA_PLUGIN_DIRS; do
325 dpkg-source -b "$dir"
326 done
328 if [ "$GOTO" = "use" ]
329 then
330 echo "Creating GOto sources..."
331 for dir in $GOTO_DIRS; do
332 dpkg-source -b "$dir"
333 done
334 fi
335 else
336 echo "Creating debian packages..."
338 for dir in $GOSA_DIR $GOSA_SI_DIR $GOSA_PLUGIN_DIRS; do
339 if [ "$PBUILDER" = "use" ]
340 then
341 echo "using pbuilder to build gosa gosa-si gosa-plugins"
342 (cd "$dir"; pdebuild)
343 else
344 (cd "$dir"; dpkg-buildpackage -k$DEBSIGN_KEYID -rfakeroot -sa)
345 fi
346 done
348 if [ "$GOTO" = "use" ]
349 then
350 echo "Creating GOto debian packages..."
351 for dir in $GOTO_DIRS; do
352 if [ "$PBUILDER" = "use" ]
353 then
354 echo "using pbuilder to build goto debian packages"
355 (cd "$dir"; pdebuild)
356 else
357 (cd "$dir"; dpkg-buildpackage -k$DEBSIGN_KEYID -rfakeroot -sa)
358 fi
359 done
360 fi
361 fi
363 echo "Removing gosa snapshot..."
364 if [ -z "$DEBIAN_PKG" ]
365 then
366 if [ "$NO_SVN" = "use" ]
367 then
368 for dir in $GOSA_DIR; do
369 rm -rf "$dir"
370 done
371 fi
372 else
373 for dir in $GOSA_DIR $GOSA_SI_DIR $GOSA_PLUGIN_DIRS; do
374 rm -rf "$dir"
375 done
377 if [ "$GOTO" = "use" ]
378 then
379 for dir in $GOTO_DIRs; do
380 rm -rf "$dir"
381 done
382 fi
383 fi