Code

- Yeah, we have complete svn build of GOsa, GOto, GOsa-si with svn tags and
[gosa.git] / gosa-core / contrib / make-gosa-package
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 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]
41         
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 for plugin in $MAKE_PLUGINS; do
253         GOSA_PLUG_DIR="gosa-plugin-$plugin-${GOSA_VER}"
255         echo "gosa plugin dir" $GOSA_PLUG_DIR
257         mv "gosa-plugins-${BNAME}/$plugin" .
259         echo "Debianizing plugin $plugin"
260         yes | dh-make-gosa --section $SECTION $plugin
261         rm -rf "$plugin"
263         echo "Packing original sources 'gosa-plugin-$plugin-${GOSA_VER}'..."
264         tar -c --exclude "gosa-plugin-${plugin}-${GOSA_VER}/debian" -f "gosa-plugin-${plugin}_${GOSA_VER}.orig.tar" "${GOSA_PLUG_DIR}"
266         echo "Compressing sources..."
267         gzip -f -9 "gosa-plugin-${plugin}_${GOSA_VER}.orig.tar"
268 done
270 rm -rf gosa-plugins-${BNAME}
272 if [ "$GOTO" = "use" ]
273 then
274         MAKE_GOTO=$(ls -1 goto-${BNAME}/)
276         for i in $GOTO_NOT_RELEASED; do
277                 MAKE_GOTO=$(echo -n $MAKE_GOTO | sed "s/$i//")
278         done
280         for goto in $MAKE_GOTO; do
282                 mv "goto-${BNAME}/$goto" .
284                 echo "Packing original sources '$goto'..."
285                 GOTO_VERSION=$(cat $goto/debian/changelog | head -n 1 | sed -n -e 's/.*(\([^-]*\).*/\1/p')
287                 if [ "$GOTO_VER" = "" ]
288                 then
289                         tar -c --exclude "$goto/debian" -f "${goto}_${GOTO_VERSION}.orig.tar" $goto
290                         echo "Compressing sources..."
291                         gzip -f -9 "${goto}_${GOTO_VERSION}.orig.tar"
292                 else
293                         tar -c --exclude "$goto/debian" -f "${goto}_${GOTO_VERSION}${GOTO_VER}.orig.tar" $goto
295                         echo "Compressing svn sources..."
296                         gzip -f -9 "${goto}_${GOTO_VERSION}${GOTO_VER}.orig.tar"
298                         echo "Adapting version in $goto"
299                         (cd "$goto"; echo | debchange -v "${GOTO_VERSION}${GOTO_VER}-1${TARGET_RELEASE}1" -D "$TARGET_RELEASE" "$RELEASE_REASON")
300                 fi
302         done
304         rm -rf goto-${BNAME}
305 fi
307 echo "Deploying patches..."
308 for patch in $(find patches -type f | grep -v .svn); do
310         if echo $patch | grep -q gosa-plugin; then
311                 plugin=$(echo $patch | sed 's/^.*gosa-plugin-\([^-]*\).*$/\1/g')
312                 echo "* gosa-plugin-$plugin patch: $patch"
313                 [ -d "gosa-plugin-${plugin}-${GOSA_VER}/debian/patches" ] || mkdir -p "gosa-plugin-${plugin}-${GOSA_VER}/debian/patches"
314                 cp "$patch" gosa-plugin-${plugin}-${GOSA_VER}/debian/patches
315         else
316                 echo "* gosa-core patch: $patch"
317                 [ -d "${GOSA_DIR}/debian/patches" ] && mkdir -p "${GOSA_DIR}/debian/patches"
318                 cp "$patch" ${GOSA_DIR}/debian/patches
319         fi
320 done
322 # Put section in GOsa_DIR
323 sed -i "s#^Section: web#Section: $SECTION#g" ${GOSA_DIR}/debian/control
324 sed -i "s#^Section: utils#Section: $SI_SECTION#g" ${GOSA_SI_DIR}/debian/control
326 for plugin in $MAKE_PLUGINS; do
327         GOSA_PLUGIN_DIRS="$GOSA_PLUGIN_DIRS gosa-plugin-$plugin-${GOSA_VER}"
328 done
330 if [ "$GOTO" = "use" ]
331 then
332         for goto in $MAKE_GOTO; do
333                 GOTO_DIRS="$GOTO_DIRS $goto"
334         done
335 fi
337 for dir in $GOSA_DIR $GOSA_SI_DIR $GOSA_PLUGIN_DIRS; do
338         echo "Adapting version in $dir"
339         if [ "$TARGET_RELEASE" == "unstable" ]; then
340                 (cd "$dir"; echo | debchange -v "${GOSA_VER}" "$RELEASE_REASON" >/dev/null 2>&1)
341         else
342                 (cd "$dir"; echo | debchange -v "${GOSA_VER}-1${TARGET_RELEASE}1" -D "$TARGET_RELEASE" "$RELEASE_REASON" >/dev/null 2>&1)
343         fi
344         [ -d $dir/debian/patches ] || continue
345         echo "Creating patch list for $dir"
346         ls -1 $dir/debian/patches | grep -v 00list | sed 's%^.*/%%g' > $dir/debian/patches/00list
347 done
349 # Update revision
350 sed -i "s/^\$svn_revision = .*$/\$svn_revision = '\$Revision: $BRANCH_REV \$';/g" $GOSA_DIR/include/functions.inc
352 if [ "$1" = "-s" ]
353 then
354         echo "Creating debian sources..."
355         for dir in $GOSA_DIR $GOSA_SI_DIR $GOSA_PLUGIN_DIRS; do
356                 dpkg-source -b "$dir"
357         done
359         if [ "$GOTO" = "use" ]
360         then
361                 echo "Creating GOto sources..."
362                 for dir in $GOTO_DIRS; do
363                         dpkg-source -b "$dir"
364                 done
365         fi
366 else
367         echo "Creating debian packages..."
369         for dir in $GOSA_DIR $GOSA_SI_DIR $GOSA_PLUGIN_DIRS; do
370         if [ "$PBUILDER" = "use" ]
371         then
372                 echo "using pbuilder to build gosa gosa-si gosa-plugins"
373                 (cd "$dir"; pdebuild --debbuildopts -sa; debsign)
374         else
375                 (cd "$dir"; dpkg-buildpackage -k$DEBSIGN_KEYID -rfakeroot -sa)
376         fi
377         done
379         if [ "$GOTO" = "use" ]
380         then
381                 echo "Creating GOto debian packages..."
382                 for dir in $GOTO_DIRS; do
383                 if [ "$PBUILDER" = "use" ]
384                 then
385                         echo "using pbuilder to build goto debian packages"
386                         (cd "$dir"; pdebuild --debbuildopts -sa; debsign -k$DEBSIGN_KEYID)
387                 else
388                         (cd "$dir"; dpkg-buildpackage -k$DEBSIGN_KEYID -rfakeroot -sa)
389                 fi
390                 done
391         fi
392 fi
394 echo "Removing gosa snapshot..."
395 if [ -z "$DEBIAN_PKG" ]
396 then
397         if [ "$NO_SVN" = "use" ]
398         then
399                 for dir in $GOSA_DIR; do
400                 rm -rf "$dir"
401                 done
402         fi
403 else
404         for dir in $GOSA_DIR $GOSA_SI_DIR $GOSA_PLUGIN_DIRS; do
405         rm -rf "$dir"
406         done
408         if [ "$GOTO" = "use" ]
409         then
410                 for dir in $GOTO_DIRs; do
411                 rm -rf "$dir"
412                 done
413         fi
414 fi