Code

Updated graphs
[gosa.git] / gosa-core / contrib / make-gosa-package
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]
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         if [ "$GOTO" = "use" ]
115                 then
116                 echo "Loading svn information for goto '${BRANCH}'..."
117                 svn co -N https://oss.gonicus.de/repositories/goto/${BRANCH} goto-info/ > /dev/null
118                 GOTO_BRANCH_REV=$(LANG=C svn info goto-info | sed -n -e 's/^Last Changed Rev: \([0-9]*\).*$/\1/p')
119                 rm -rf goto-info
120         fi
121 else
122         echo "Loading svn information for gosa '${BRANCH}' from local checkout ..."
123         BRANCH_REV=$(LANG=C svn info $EXTRACT/gosa-core | sed -n -e 's/^Last Changed Rev: \([0-9]*\).*$/\1/p')
125         if [ "$GOTO" = "use" ]
126         then
127                 echo "Loading svn information for goto '${BRANCH}' from local checkout ..."
128                 GOTO_BRANCH_REV=$(LANG=C svn info $EXTRACT/goto | sed -n -e 's/^Last Changed Rev: \([0-9]*\).*$/\1/p')
129         fi
130 fi
132 if [ "$NO_SVN" = "use" ]
133 then
134         # Load current revision from logs
135         VERSION=$(svn cat -r "${BRANCH_REV}" https://oss.gonicus.de/repositories/gosa/${BRANCH}/gosa-core/debian/changelog \
136                 | head -n 1 | sed -n -e 's/.*(\([^-]*\).*/\1/p')
137         if [ "$BRANCH" == "trunk" ]; then
138                 GOSA_VER="${VERSION}+svn${BRANCH_REV}"
140                 if [ "$GOTO" = "use" ]
141                 then
142                         GOTO_VER="+svn${GOTO_BRANCH_REV}"
143                 fi
144         else
145                 GOSA_VER="${VERSION}"
147                 if [ "$GOTO" = "use" ]
148                 then
149                         GOTO_VER=""
150                 fi
152         fi
154 else
155         # Load current revision from logs
156         VERSION=$(cat $EXTRACT/gosa-core/debian/changelog | head -n 1 | sed -n -e 's/.*(\([^-]*\).*/\1/p')
158         if [ "$BRANCH" == "trunk" ]; then
159                 GOSA_VER="${VERSION}+svn${BRANCH_REV}"
160         else
161                 GOSA_VER="${VERSION}"
162         fi
163         echo $GOSA_VER
164 fi
166 GOSA_DIR="gosa-${GOSA_VER}"
168 ORIG_FILE="gosa_${GOSA_VER}.orig.tar.gz"
170 if [ "$NO_SVN" = "use" ]
171 then
172         # Export from svn...
173         BNAME=$(basename $BRANCH)
174         [ -d "gosa-${BNAME}" ] && rm -rf gosa-$BNAME
175         echo "Exporting current GOsa (rev: ${BRANCH_REV}) from '${BRANCH}'..."
176         svn export -r "${BRANCH_REV}" https://oss.gonicus.de/repositories/gosa/${BRANCH}/gosa-core gosa-${BNAME} > /dev/null
177         svn export -r "${BRANCH_REV}" https://oss.gonicus.de/repositories/gosa/${BRANCH}/gosa-si gosa-si-${BNAME} > /dev/null
178         svn export -r "${BRANCH_REV}" https://oss.gonicus.de/repositories/gosa/${BRANCH}/gosa-plugins gosa-plugins-${BNAME} > /dev/null
180         if [ "$GOTO" = "use" ]
181         then
182                 echo "Exporting current GOto (rev: ${GOTO_BRANCH_REV}) from '${BRANCH}'..."
183                 svn export -r "${GOTO_BRANCH_REV}" https://oss.gonicus.de/repositories/goto/${BRANCH}/ goto-${BNAME} > /dev/null
184         fi
185 else
186         # Export from local checkout...
187         echo "Exporting current GOsa (rev: ${BRANCH_REV}) from localcheckout '${BRANCH}'..."
188         BNAME=$(basename $BRANCH)
189         cp -r gosa-core gosa-${GOSA_VER}
190         mv gosa-si gosa-si-${GOSA_VER}
191         mv gosa-plugins gosa-plugins-${BNAME}
193         if [ "$GOTO" = "use" ]
194         then
195                 echo "Exporting current GOto (rev: ${GOTO_BRANCH_REV}) from localcheckout '${BRANCH}'..."
196                 BNAME=$(basename $BRANCH)
197                 mv goto goto-${BNAME}
198         fi
199 fi
201 if [ "$NO_SVN" = "use" ]
202 then
203         VERSION=$(cat "gosa-${BNAME}/debian/changelog" | head -n 1 | sed -n -e 's/.*(\([^-]*\).*/\1/p')
204 fi
206 GOSA_DIR="gosa-${GOSA_VER}"
207 GOSA_SI_DIR="gosa-si-${GOSA_VER}"
208 GOTO_DIR="goto-${BNAME}"
210 if [ "$NO_SVN" = "use" ]
211 then
212         if [ "$BNAME" != "$GOSA_VER" ]
213         then
214                 rm -rf "gosa-${GOSA_VER}"
215         fi
216 fi
218 if [ "$NO_SVN" = "use" ]
219 then
220         if [ "$BNAME" != "$GOSA_VER" ]
221         then
222                 mv "gosa-${BNAME}" "gosa-${GOSA_VER}"
223                 mv "gosa-si-${BNAME}" "gosa-si-${GOSA_VER}"
224         fi
225 fi
227 echo "cleaning svn entries from sources"
228 find ${GOSA_DIR} -type d -name ".svn" -exec rm -rf {} \; >/dev/null 2>&1
229 find ${GOSA_SI_DIR} -type d -name ".svn" -exec rm -rf {} \; >/dev/null 2>&1
230 find gosa-plugins-${BNAME} -type d -name ".svn" -exec rm -rf {} \; >/dev/null 2>&1
232 if [ "$GOTO" = "use" ]
233 then
234         find goto-${BNAME} -type d -name ".svn" -exec rm -rf {} \; >/dev/null 2>&1
235 fi
237 echo "Creating original sources 'gosa-${GOSA_VER}'..."
238 tar -c --exclude "${GOSA_DIR}"/debian -f "gosa_${GOSA_VER}.orig.tar" "${GOSA_DIR}"
239 tar -c --exclude "${GOSA_SI_DIR}"/debian -f "gosa-si_${GOSA_VER}.orig.tar" "${GOSA_SI_DIR}"
241 echo "Compressing sources..."
242 gzip -f -9 "gosa_${GOSA_VER}.orig.tar"
243 gzip -f -9 "gosa-si_${GOSA_VER}.orig.tar"
245 export OVERRIDE_VERSION="$GOSA_VER"
246 if [ -z "$MAKE_PLUGINS" ]; then
247         MAKE_PLUGINS=$(ls -1 gosa-plugins-${BNAME}/*/plugin.dsc | sed 's/^.*\/\([^\/]*\)\/plugin.dsc$/\1/')
248         for i in $NOT_RELEASED; do
249                 MAKE_PLUGINS=$(echo -n $MAKE_PLUGINS | sed "s/$i//")
250         done
251 fi
253 if [ "TARGET_RELEASE" == "etch" ]; then
254   NOBREAKS="--no-break"
255 fi
257 for plugin in $MAKE_PLUGINS; do
259         GOSA_PLUG_DIR="gosa-plugin-$plugin-${GOSA_VER}"
261         echo "gosa plugin dir" $GOSA_PLUG_DIR
263         mv "gosa-plugins-${BNAME}/$plugin" .
265         echo "Debianizing plugin $plugin"
266         yes | dh-make-gosa $NOBREAKS --section $SECTION $plugin
267         rm -rf "$plugin"
269         echo "Packing original sources 'gosa-plugin-$plugin-${GOSA_VER}'..."
270         tar -c --exclude "gosa-plugin-${plugin}-${GOSA_VER}/debian" -f "gosa-plugin-${plugin}_${GOSA_VER}.orig.tar" "${GOSA_PLUG_DIR}"
272         echo "Compressing sources..."
273         gzip -f -9 "gosa-plugin-${plugin}_${GOSA_VER}.orig.tar"
274 done
276 rm -rf gosa-plugins-${BNAME}
278 if [ "$GOTO" = "use" ]
279 then
280         MAKE_GOTO=$(ls -1 goto-${BNAME}/)
282         for i in $GOTO_NOT_RELEASED; do
283                 MAKE_GOTO=$(echo -n $MAKE_GOTO | sed "s/$i//")
284         done
286         for goto in $MAKE_GOTO; do
288                 mv "goto-${BNAME}/$goto" .
290                 echo "Packing original sources '$goto'..."
291                 GOTO_VERSION=$(cat $goto/debian/changelog | head -n 1 | sed -n -e 's/.*(\([^-]*\).*/\1/p')
293                 if [ "$GOTO_VER" = "" ]
294                 then
295                         tar -c --exclude "$goto/debian" -f "${goto}_${GOTO_VERSION}.orig.tar" $goto
296                         echo "Compressing sources..."
297                         gzip -f -9 "${goto}_${GOTO_VERSION}.orig.tar"
298                 else
299                         tar -c --exclude "$goto/debian" -f "${goto}_${GOTO_VERSION}${GOTO_VER}.orig.tar" $goto
301                         echo "Compressing svn sources..."
302                         gzip -f -9 "${goto}_${GOTO_VERSION}${GOTO_VER}.orig.tar"
304                         echo "Adapting version in $goto"
305                         (cd "$goto"; echo | debchange -v "${GOTO_VERSION}${GOTO_VER}-1${TARGET_RELEASE}1" -D "$TARGET_RELEASE" "$RELEASE_REASON")
306                 fi
308         done
310         rm -rf goto-${BNAME}
311 fi
313 echo "Deploying patches..."
314 for patch in $(find patches -type f | grep -v .svn); do
316         if echo $patch | grep -q gosa-plugin; then
317                 plugin=$(echo $patch | sed 's/^.*gosa-plugin-\([^-]*\).*$/\1/g')
318                 echo "* gosa-plugin-$plugin patch: $patch"
319                 [ -d "gosa-plugin-${plugin}-${GOSA_VER}/debian/patches" ] || mkdir -p "gosa-plugin-${plugin}-${GOSA_VER}/debian/patches"
320                 cp "$patch" gosa-plugin-${plugin}-${GOSA_VER}/debian/patches
321         else
322                 echo "* gosa-core patch: $patch"
323                 [ -d "${GOSA_DIR}/debian/patches" ] && mkdir -p "${GOSA_DIR}/debian/patches"
324                 cp "$patch" ${GOSA_DIR}/debian/patches
325         fi
326 done
328 # Put section in GOsa_DIR
329 sed -i "s#^Section: web#Section: $SECTION#g" ${GOSA_DIR}/debian/control
330 sed -i "s#^Section: utils#Section: $SI_SECTION#g" ${GOSA_SI_DIR}/debian/control
332 for plugin in $MAKE_PLUGINS; do
333         GOSA_PLUGIN_DIRS="$GOSA_PLUGIN_DIRS gosa-plugin-$plugin-${GOSA_VER}"
334 done
336 if [ "$GOTO" = "use" ]
337 then
338         for goto in $MAKE_GOTO; do
339                 GOTO_DIRS="$GOTO_DIRS $goto"
340         done
341 fi
343 for dir in $GOSA_DIR $GOSA_SI_DIR $GOSA_PLUGIN_DIRS; do
344         echo "Adapting version in $dir"
345         if [ "$TARGET_RELEASE" == "unstable" ]; then
346                 (cd "$dir"; echo | debchange -v "${GOSA_VER}" "$RELEASE_REASON" >/dev/null 2>&1)
347         else
348                 (cd "$dir"; echo | debchange -v "${GOSA_VER}-1${TARGET_RELEASE}1" -D "$TARGET_RELEASE" "$RELEASE_REASON" >/dev/null 2>&1)
349         fi
350         [ -d $dir/debian/patches ] || continue
351         echo "Creating patch list for $dir"
352         ls -1 $dir/debian/patches | grep -v 00list | sed 's%^.*/%%g' > $dir/debian/patches/00list
353 done
355 # Update revision
356 sed -i "s/^\$svn_revision = .*$/\$svn_revision = '\$Revision: $BRANCH_REV \$';/g" $GOSA_DIR/include/functions.inc
358 if [ "$1" = "-s" ]
359 then
360         echo "Creating debian sources..."
361         for dir in $GOSA_DIR $GOSA_SI_DIR $GOSA_PLUGIN_DIRS; do
362                 dpkg-source -b "$dir"
363         done
365         if [ "$GOTO" = "use" ]
366         then
367                 echo "Creating GOto sources..."
368                 for dir in $GOTO_DIRS; do
369                         dpkg-source -b "$dir"
370                 done
371         fi
372 else
373         echo "Creating debian packages..."
375         for dir in $GOSA_DIR $GOSA_SI_DIR $GOSA_PLUGIN_DIRS; do
376         if [ "$PBUILDER" = "use" ]
377         then
378                 echo "using pbuilder to build gosa gosa-si gosa-plugins"
379                 (cd "$dir"; pdebuild --debbuildopts -sa; debsign)
380         else
381                 (cd "$dir"; dpkg-buildpackage -k$DEBSIGN_KEYID -rfakeroot -sa)
382         fi
383         done
385         if [ "$GOTO" = "use" ]
386         then
387                 echo "Creating GOto debian packages..."
388                 for dir in $GOTO_DIRS; do
389                 if [ "$PBUILDER" = "use" ]
390                 then
391                         echo "using pbuilder to build goto debian packages"
392                         (cd "$dir"; pdebuild --debbuildopts -sa; debsign -k$DEBSIGN_KEYID)
393                 else
394                         (cd "$dir"; dpkg-buildpackage -k$DEBSIGN_KEYID -rfakeroot -sa)
395                 fi
396                 done
397         fi
398 fi
400 echo "Removing gosa snapshot..."
401 if [ -z "$DEBIAN_PKG" ]
402 then
403         if [ "$NO_SVN" = "use" ]
404         then
405                 for dir in $GOSA_DIR; do
406                 rm -rf "$dir"
407                 done
408         fi
409 else
410         for dir in $GOSA_DIR $GOSA_SI_DIR $GOSA_PLUGIN_DIRS; do
411         rm -rf "$dir"
412         done
414         if [ "$GOTO" = "use" ]
415         then
416                 for dir in $GOTO_DIRs; do
417                 rm -rf "$dir"
418                 done
419         fi
420 fi