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 NOT_RELEASED="heimdal dak dfs glpi apache2 ssh"
31 GOTO_NOT_RELEASED="apache-directory-studio goto-cd libresourcepool-net-ldap-perl-1.002 libresourcepool-perl-1.0104 openproj ptc syslinux"
32 DEBIAN_PKG="remove"
33 NO_SVN="use"
34 EXTRACT=`pwd`
36 usage() {
37 cat <<-EOF
38 GOsa Debian package build tool. Build snapshots from selected SVN locations.
39 Usage: ${0##*/} [options]
41 Options:
42 -b|--branch Branch to export [$BRANCH]
43 -p|--plugins Comma seperate list of plugins to build. Leave empty to build all.
44 -e|--experimental Build not released plugins (for testers and developers only)
45 -r|--release Debian release to build for [$TARGET_RELEASE]
46 -c|--changelog Debian changelog entry [$RELEASE_REASON]
47 -s|--section Debian section to place GOsa in [$SECTION]
48 -i|--si-section Debian section to place GOsa-SI in [$SI_SECTION]
49 -d|--debian-pkg Don't clear up debian packages for plugins (for developers only)
50 -n|--no-svn Don't extract gosa from svn (when internet connectivity is not present)
51 -x|--extract-dir Directory where the checkout is for no-svn
52 -g|--build-goto Build the goto2 packages
53 -h|--help this help
55 EOF
56 exit 1
57 }
59 for cmd in dh-make-gosa debchange dpkg-buildpackage dpkg-source svn; do
60 if ! which $cmd >/dev/null; then
61 echo "Error: cannot find '$cmd' command in path!";
62 exit 1
63 fi
64 done
66 # Import command line parameters
67 PARMS=`getopt -o e::d::b:r:s:c:i:p:n:x:g::,h --long branch:,changelog:,plugins:,section:,si-section:,release:,help -n "${0##*/}" -- "$@"`
68 eval set -- "$PARMS"
70 while true; do
71 case "$1" in
72 -b|--branch)
73 BRANCH=$2; shift 2 ;;
74 -r|--release)
75 TARGET_RELEASE=$2; shift 2 ;;
76 -c|--changelog)
77 RELEASE_REASON=$2; shift 2 ;;
78 -p|--plugins)
79 MAKE_PLUGINS=$(echo $2 | tr ',' ' '); shift 2 ;;
80 -e|--experimental)
81 NOT_RELEASED=""; shift 2;;
82 -s|--section)
83 SECTION=$2; shift 2 ;;
84 -i|--si-section)
85 SI_SECTION=$2; shift 2 ;;
86 -d|--debian-pkg)
87 DEBIAN_PKG=""; shift 2 ;;
88 -n|--no-svn)
89 NO_SVN=""; shift 2;;
90 -x|--extract-dir)
91 EXTRACT=$2; shift 2;;
92 -g|--build-goto)
93 GOTO="use"; shift 2;;
94 -h|--help)
95 usage ;;
96 --)
97 shift; break ;;
98 *)
99 echo "getopt error" ;;
100 esac
101 done
103 if [ "$NO_SVN" = "use" ]
104 then
105 echo "Loading svn information for gosa '${BRANCH}'..."
106 svn co -N https://oss.gonicus.de/repositories/gosa/${BRANCH} gosa-info/ > /dev/null
107 BRANCH_REV=$(LANG=C svn info gosa-info | sed -n -e 's/^Last Changed Rev: \([0-9]*\).*$/\1/p')
108 rm -rf gosa-info
110 echo "Loading svn information for goto '${BRANCH}'..."
111 svn co -N https://oss.gonicus.de/repositories/goto/${BRANCH} goto-info/ > /dev/null
112 GOTO_BRANCH_REV=$(LANG=C svn info goto-info | sed -n -e 's/^Last Changed Rev: \([0-9]*\).*$/\1/p')
113 rm -rf goto-info
115 else
116 echo "Loading svn information for gosa '${BRANCH}' from local checkout ..."
117 BRANCH_REV=$(LANG=C svn info $EXTRACT/gosa-core | sed -n -e 's/^Last Changed Rev: \([0-9]*\).*$/\1/p')
119 if [ "$GOTO" = "use" ]
120 then
121 echo "Loading svn information for goto '${BRANCH}' from local checkout ..."
122 GOTO_BRANCH_REV=$(LANG=C svn info $EXTRACT/goto | sed -n -e 's/^Last Changed Rev: \([0-9]*\).*$/\1/p')
123 fi
124 fi
126 if [ "$NO_SVN" = "use" ]
127 then
128 # Load current revision from logs
129 VERSION=$(svn cat -r "${BRANCH_REV}" https://oss.gonicus.de/repositories/gosa/${BRANCH}/gosa-core/debian/changelog \
130 | head -n 1 | sed -n -e 's/.*(\([^-]*\).*/\1/p')
131 if [ "$BRANCH" == "trunk" ]; then
132 GOSA_VER="${VERSION}+svn${BRANCH_REV}"
133 else
134 GOSA_VER="${VERSION}"
135 fi
137 else
138 # Load current revision from logs
139 VERSION=$(cat $EXTRACT/gosa-core/debian/changelog | head -n 1 | sed -n -e 's/.*(\([^-]*\).*/\1/p')
141 if [ "$BRANCH" == "trunk" ]; then
142 GOSA_VER="${VERSION}+svn${BRANCH_REV}"
143 else
144 GOSA_VER="${VERSION}"
145 fi
146 echo $GOSA_VER
147 fi
149 GOSA_DIR="gosa-${GOSA_VER}"
151 ORIG_FILE="gosa_${GOSA_VER}.orig.tar.gz"
153 if [ "$NO_SVN" = "use" ]
154 then
155 # Export from svn...
156 BNAME=$(basename $BRANCH)
157 [ -d "gosa-${BNAME}" ] && rm -rf gosa-$BNAME
158 echo "Exporting current GOsa (rev: ${BRANCH_REV}) from '${BRANCH}'..."
159 svn export -r "${BRANCH_REV}" https://oss.gonicus.de/repositories/gosa/${BRANCH}/gosa-core gosa-${BNAME} > /dev/null
160 svn export -r "${BRANCH_REV}" https://oss.gonicus.de/repositories/gosa/${BRANCH}/gosa-si gosa-si-${BNAME} > /dev/null
161 svn export -r "${BRANCH_REV}" https://oss.gonicus.de/repositories/gosa/${BRANCH}/gosa-plugins gosa-plugins-${BNAME} > /dev/null
163 if [ "$GOTO" = "use" ]
164 then
165 echo "Exporting current GOto (rev: ${GOTO_BRANCH_REV}) from '${BRANCH}'..."
166 svn export -r "${GOTO_BRANCH_REV}" https://oss.gonicus.de/repositories/goto/${BRANCH}/ goto-${BNAME} > /dev/null
167 fi
168 else
169 # Export from local checkout...
170 echo "Exporting current GOsa (rev: ${BRANCH_REV}) from localcheckout '${BRANCH}'..."
171 BNAME=$(basename $BRANCH)
172 cp -r gosa-core gosa-${GOSA_VER}
173 mv gosa-si gosa-si-${GOSA_VER}
174 mv gosa-plugins gosa-plugins-${BNAME}
176 if [ "$GOTO" = "use" ]
177 then
178 echo "Exporting current GOto (rev: ${GOTO_BRANCH_REV}) from localcheckout '${BRANCH}'..."
179 BNAME=$(basename $BRANCH)
180 mv goto goto-${BNAME}
181 fi
182 fi
184 if [ "$NO_SVN" = "use" ]
185 then
186 VERSION=$(cat "gosa-${BNAME}/debian/changelog" | head -n 1 | sed -n -e 's/.*(\([^-]*\).*/\1/p')
187 fi
189 GOSA_DIR="gosa-${GOSA_VER}"
190 GOSA_SI_DIR="gosa-si-${GOSA_VER}"
191 GOTO_DIR="goto-${BNAME}"
193 if [ "$NO_SVN" = "use" ]
194 then
195 if [ "$BNAME" != "$GOSA_VER" ]
196 then
197 rm -rf "gosa-${GOSA_VER}"
198 fi
199 fi
201 if [ "$NO_SVN" = "use" ]
202 then
203 if [ "$BNAME" != "$GOSA_VER" ]
204 then
205 mv "gosa-${BNAME}" "gosa-${GOSA_VER}"
206 mv "gosa-si-${BNAME}" "gosa-si-${GOSA_VER}"
207 fi
208 fi
210 echo "cleaning svn entries from sources"
211 find ${GOSA_DIR} -type d -name ".svn" -exec rm -rf {} \; >/dev/null 2>&1
212 find ${GOSA_SI_DIR} -type d -name ".svn" -exec rm -rf {} \; >/dev/null 2>&1
213 find gosa-plugins-${BNAME} -type d -name ".svn" -exec rm -rf {} \; >/dev/null 2>&1
215 if [ "$GOTO" = "use" ]
216 then
217 find goto-${BNAME} -type d -name ".svn" -exec rm -rf {} \; >/dev/null 2>&1
218 fi
220 echo "Creating original sources 'gosa-${GOSA_VER}'..."
221 tar -c -f "gosa_${GOSA_VER}.orig.tar" "${GOSA_DIR}"
222 tar -c -f "gosa-si_${GOSA_VER}.orig.tar" "${GOSA_SI_DIR}"
224 echo "Compressing sources..."
225 gzip -f -9 "gosa_${GOSA_VER}.orig.tar"
226 gzip -f -9 "gosa-si_${GOSA_VER}.orig.tar"
228 export OVERRIDE_VERSION="$GOSA_VER"
229 if [ -z "$MAKE_PLUGINS" ]; then
230 MAKE_PLUGINS=$(ls -1 gosa-plugins-${BNAME}/*/plugin.dsc | sed 's/^.*\/\([^\/]*\)\/plugin.dsc$/\1/')
231 for i in $NOT_RELEASED; do
232 MAKE_PLUGINS=$(echo -n $MAKE_PLUGINS | sed "s/$i//")
233 done
234 fi
236 for plugin in $MAKE_PLUGINS; do
238 GOSA_PLUG_DIR="gosa-plugin-$plugin-${GOSA_VER}"
240 echo "gosa plugin dir" $GOSA_PLUG_DIR
242 mv "gosa-plugins-${BNAME}/$plugin" .
244 echo "Debianizing plugin $plugin"
245 yes | dh-make-gosa --section $SECTION $plugin
246 rm -rf "$plugin"
248 echo "Packing original sources 'gosa-plugin-$plugin-${GOSA_VER}'..."
249 tar -c -f "gosa-plugin-${plugin}_${GOSA_VER}.orig.tar" "${GOSA_PLUG_DIR}"
251 echo "Compressing sources..."
252 gzip -f -9 "gosa-plugin-${plugin}_${GOSA_VER}.orig.tar"
253 done
255 rm -rf gosa-plugins-${BNAME}
257 if [ "$GOTO" = "use" ]
258 then
259 MAKE_GOTO=$(ls -1 goto-${BNAME}/)
261 for i in $GOTO_NOT_RELEASED; do
262 MAKE_GOTO=$(echo -n $MAKE_GOTO | sed "s/$i//")
263 done
265 for goto in $MAKE_GOTO; do
266 mv "goto-${BNAME}/$goto" .
267 done
269 rm -rf goto-${BNAME}
270 fi
272 echo "Deploying patches..."
273 for patch in $(find patches -type f | grep -v .svn); do
275 if echo $patch | grep -q gosa-plugin; then
276 plugin=$(echo $patch | sed 's/^.*gosa-plugin-\([^-]*\).*$/\1/g')
277 echo "* gosa-plugin-$plugin patch: $patch"
278 [ -d "gosa-plugin-${plugin}-${GOSA_VER}/debian/patches" ] || mkdir -p "gosa-plugin-${plugin}-${GOSA_VER}/debian/patches"
279 cp "$patch" gosa-plugin-${plugin}-${GOSA_VER}/debian/patches
280 else
281 echo "* gosa-core patch: $patch"
282 [ -d "${GOSA_DIR}/debian/patches" ] && mkdir -p "${GOSA_DIR}/debian/patches"
283 cp "$patch" ${GOSA_DIR}/debian/patches
284 fi
285 done
287 # Put section in GOsa_DIR
288 sed -i "s#^Section: web#Section: $SECTION#g" ${GOSA_DIR}/debian/control
289 sed -i "s#^Section: utils#Section: $SI_SECTION#g" ${GOSA_SI_DIR}/debian/control
291 for plugin in $MAKE_PLUGINS; do
292 GOSA_PLUGIN_DIRS="$GOSA_PLUGIN_DIRS gosa-plugin-$plugin-${GOSA_VER}"
293 done
295 if [ "$GOTO" = "use" ]
296 then
297 for goto in $MAKE_GOTO; do
298 GOTO_DIRS="$GOTO_DIRS $goto"
299 done
300 fi
302 for dir in $GOSA_DIR $GOSA_SI_DIR $GOSA_PLUGIN_DIRS; do
303 echo "Adapting version in $dir"
304 if [ "$TARGET_RELEASE" == "unstable" ]; then
305 (cd "$dir"; echo | debchange -v "${GOSA_VER}" "$RELEASE_REASON" >/dev/null 2>&1)
306 else
307 (cd "$dir"; echo | debchange -v "${GOSA_VER}-1${TARGET_RELEASE}1" -D "$TARGET_RELEASE" "$RELEASE_REASON" >/dev/null 2>&1)
308 fi
309 [ -d $dir/debian/patches ] || continue
310 echo "Creating patch list for $dir"
311 ls -1 $dir/debian/patches | grep -v 00list | sed 's%^.*/%%g' > $dir/debian/patches/00list
312 done
314 # Update revision
315 sed -i "s/^\$svn_revision = .*$/\$svn_revision = '\$Revision: $BRANCH_REV \$';/g" $GOSA_DIR/include/functions.inc
317 if [ "$1" = "-s" ]
318 then
319 echo "Creating debian sources..."
320 for dir in $GOSA_DIR $GOSA_SI_DIR $GOSA_PLUGIN_DIRS; do
321 dpkg-source -b "$dir"
322 done
324 if [ "$GOTO" = "use" ]
325 then
326 echo "Creating GOto sources..."
327 for dir in $GOTO_DIRS; do
328 dpkg-source -b "$dir"
329 done
330 fi
331 else
332 echo "Creating debian packages..."
333 for dir in $GOSA_DIR $GOSA_SI_DIR $GOSA_PLUGIN_DIRS; do
334 (cd "$dir"; dpkg-buildpackage -k$DEBSIGN_KEYID -rfakeroot -sa)
335 done
337 if [ "$GOTO" = "use" ]
338 then
339 echo "Creating GOto debian packages..."
340 for dir in $GOTO_DIRS; do
341 (cd "$dir"; dpkg-buildpackage -k$DEBSIGN_KEYID -rfakeroot -sa)
342 done
343 fi
344 fi
346 echo "Removing gosa snapshot..."
347 if [ -z "$DEBIAN_PKG" ]
348 then
349 for dir in $GOSA_DIR; do
350 rm -rf "$dir"
351 done
352 else
353 for dir in $GOSA_DIR $GOSA_SI_DIR $GOSA_PLUGIN_DIRS; do
354 rm -rf "$dir"
355 done
357 if [ "$GOTO" = "use" ]
358 then
359 for dir in $GOTO_DIRs; do
360 rm -rf "$dir"
361 done
362 fi
363 fi