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 NOT_RELEASED="heimdal dak dfs glpi apache2 ssh"
29 DEBIAN_PKG="remove"
30 NO_SVN="use"
31 EXTRACT=`pwd`
33 usage() {
34 cat <<-EOF
35 GOsa Debian package build tool. Build snapshots from selected SVN locations.
36 Usage: ${0##*/} [options]
38 Options:
39 -b|--branch Branch to export [$BRANCH]
40 -p|--plugins Comma seperate list of plugins to build. Leave empty to build all.
41 -e|--experimental Build not released plugins (for testers and developers only)
42 -r|--release Debian release to build for [$TARGET_RELEASE]
43 -c|--changelog Debian changelog entry [$RELEASE_REASON]
44 -s|--section Debian section to place GOsa in [$SECTION]
45 -i|--si-section Debian section to place GOsa-SI in [$SI_SECTION]
46 -d|--debian-pkg Don't clear up debian packages for plugins (for developers only)
47 -n|--no-svn Don't extract gosa from svn (when internet connectivity is not present)
48 -x|--extract-dir Directory where the checkout is for no-svn
49 -h|--help this help
51 EOF
52 exit 1
53 }
55 for cmd in dh-make-gosa debchange dpkg-buildpackage dpkg-source svn; do
56 if ! which $cmd >/dev/null; then
57 echo "Error: cannot find '$cmd' command in path!";
58 exit 1
59 fi
60 done
62 # Import command line parameters
63 PARMS=`getopt -o e::d::b:r:s:c:i:p:n:x:,h --long branch:,changelog:,plugins:,section:,si-section:,release:,help -n "${0##*/}" -- "$@"`
64 eval set -- "$PARMS"
66 while true; do
67 case "$1" in
68 -b|--branch)
69 BRANCH=$2; shift 2 ;;
70 -r|--release)
71 TARGET_RELEASE=$2; shift 2 ;;
72 -c|--changelog)
73 RELEASE_REASON=$2; shift 2 ;;
74 -p|--plugins)
75 MAKE_PLUGINS=$(echo $2 | tr ',' ' '); shift 2 ;;
76 -e|--experimental)
77 NOT_RELEASED=""; shift 2;;
78 -s|--section)
79 SECTION=$2; shift 2 ;;
80 -i|--si-section)
81 SI_SECTION=$2; shift 2 ;;
82 -d|--debian-pkg)
83 DEBIAN_PKG=""; shift 2 ;;
84 -n|--no-svn)
85 NO_SVN=""; shift 2;;
86 -x|--extract-dir)
87 EXTRACT=$2; shift 2;;
88 -h|--help)
89 usage ;;
90 --)
91 shift; break ;;
92 *)
93 echo "getopt error" ;;
94 esac
95 done
97 if [ "$NO_SVN" = "use" ]
98 then
99 echo "Loading svn information for '${BRANCH}'..."
100 svn co -N https://oss.gonicus.de/repositories/gosa/${BRANCH} gosa-info/ > /dev/null
101 BRANCH_REV=$(LANG=C svn info gosa-info | sed -n -e 's/^Last Changed Rev: \([0-9]*\).*$/\1/p')
102 rm -rf gosa-info
103 else
104 echo "Loading svn information for '${BRANCH}' from local checkout ..."
105 BRANCH_REV=$(LANG=C svn info $EXTRACT/gosa-core | sed -n -e 's/^Last Changed Rev: \([0-9]*\).*$/\1/p')
106 fi
108 if [ "$NO_SVN" = "use" ]
109 then
110 # Load current revision from logs
111 VERSION=$(svn cat -r "${BRANCH_REV}" https://oss.gonicus.de/repositories/gosa/${BRANCH}/gosa-core/debian/changelog \
112 | head -n 1 | sed -n -e 's/.*(\([^-]*\).*/\1/p')
113 if [ "$BRANCH" == "trunk" ]; then
114 GOSA_VER="${VERSION}+svn${BRANCH_REV}"
115 else
116 GOSA_VER="${VERSION}"
117 fi
118 else
119 # Load current revision from logs
120 VERSION=$(cat $EXTRACT/gosa-core/debian/changelog | head -n 1 | sed -n -e 's/.*(\([^-]*\).*/\1/p')
122 if [ "$BRANCH" == "trunk" ]; then
123 GOSA_VER="${VERSION}+svn${BRANCH_REV}"
124 else
125 GOSA_VER="${VERSION}"
126 fi
127 echo $GOSA_VER
128 fi
130 GOSA_DIR="gosa-${GOSA_VER}"
132 ORIG_FILE="gosa_${GOSA_VER}.orig.tar.gz"
134 if [ "$NO_SVN" = "use" ]
135 then
136 # Export from svn...
137 BNAME=$(basename $BRANCH)
138 [ -d "gosa-${BNAME}" ] && rm -rf gosa-$BNAME
139 echo "Exporting current GOsa (rev: ${BRANCH_REV}) from '${BRANCH}'..."
140 svn export -r "${BRANCH_REV}" https://oss.gonicus.de/repositories/gosa/${BRANCH}/gosa-core gosa-${BNAME} > /dev/null
141 svn export -r "${BRANCH_REV}" https://oss.gonicus.de/repositories/gosa/${BRANCH}/gosa-si gosa-si-${BNAME} > /dev/null
142 svn export -r "${BRANCH_REV}" https://oss.gonicus.de/repositories/gosa/${BRANCH}/gosa-plugins gosa-plugins-${BNAME} > /dev/null
143 else
144 # Export from local checkout...
145 echo "Exporting current GOsa (rev: ${BRANCH_REV}) from localcheckout '${BRANCH}'..."
146 BNAME=$(basename $BRANCH)
147 cp -r gosa-core gosa-${GOSA_VER}
148 mv gosa-si gosa-si-${GOSA_VER}
149 mv gosa-plugins gosa-plugins-${BNAME}
150 fi
152 if [ "$NO_SVN" = "use" ]
153 then
154 VERSION=$(cat "gosa-${BNAME}/debian/changelog" | head -n 1 | sed -n -e 's/.*(\([^-]*\).*/\1/p')
155 fi
157 #if [ "$BRANCH" == "trunk" ]; then
158 # GOSA_VER="${VERSION}+svn${BRANCH_REV}"
159 #else
160 # GOSA_VER="${VERSION}"
161 #fi
163 GOSA_DIR="gosa-${GOSA_VER}"
164 GOSA_SI_DIR="gosa-si-${GOSA_VER}"
166 if [ "$NO_SVN" = "use" ]
167 then
168 if [ "$BNAME" != "$GOSA_VER" ]
169 then
170 rm -rf "gosa-${GOSA_VER}"
171 fi
172 fi
174 if [ "$NO_SVN" = "use" ]
175 then
176 if [ "$BNAME" != "$GOSA_VER" ]
177 then
178 mv "gosa-${BNAME}" "gosa-${GOSA_VER}"
179 mv "gosa-si-${BNAME}" "gosa-si-${GOSA_VER}"
180 fi
181 fi
183 echo "cleaning svn entries from sources"
184 find ${GOSA_DIR} -type d -name ".svn" -exec rm -rf {} \; >/dev/null 2>&1
185 find ${GOSA_SI_DIR} -type d -name ".svn" -exec rm -rf {} \; >/dev/null 2>&1
186 find gosa-plugins-${BNAME} -type d -name ".svn" -exec rm -rf {} \; >/dev/null 2>&1
188 echo "Creating original sources 'gosa-${GOSA_VER}'..."
189 tar -c -f "gosa_${GOSA_VER}.orig.tar" "${GOSA_DIR}"
190 tar -c -f "gosa-si_${GOSA_VER}.orig.tar" "${GOSA_SI_DIR}"
192 echo "Compressing sources..."
193 gzip -f -9 "gosa_${GOSA_VER}.orig.tar"
194 gzip -f -9 "gosa-si_${GOSA_VER}.orig.tar"
196 export OVERRIDE_VERSION="$GOSA_VER"
197 if [ -z "$MAKE_PLUGINS" ]; then
198 MAKE_PLUGINS=$(ls -1 gosa-plugins-${BNAME}/*/plugin.dsc | sed 's/^.*\/\([^\/]*\)\/plugin.dsc$/\1/')
199 for i in $NOT_RELEASED; do
200 MAKE_PLUGINS=$(echo -n $MAKE_PLUGINS | sed "s/$i//")
201 done
202 fi
204 for plugin in $MAKE_PLUGINS; do
206 GOSA_PLUG_DIR="gosa-plugin-$plugin-${GOSA_VER}"
208 echo "gosa plugin dir" $GOSA_PLUG_DIR
210 mv "gosa-plugins-${BNAME}/$plugin" .
212 echo "Debianizing plugin $plugin"
213 yes | dh-make-gosa --section $SECTION $plugin
214 rm -rf "$plugin"
216 echo "Packing original sources 'gosa-plugin-$plugin-${GOSA_VER}'..."
217 tar -c -f "gosa-plugin-${plugin}_${GOSA_VER}.orig.tar" "${GOSA_PLUG_DIR}"
219 echo "Compressing sources..."
220 gzip -f -9 "gosa-plugin-${plugin}_${GOSA_VER}.orig.tar"
221 done
223 rm -rf gosa-plugins-${BNAME}
225 echo "Deploying patches..."
226 for patch in $(find patches -type f | grep -v .svn); do
228 if echo $patch | grep -q gosa-plugin; then
229 plugin=$(echo $patch | sed 's/^.*gosa-plugin-\([^-]*\).*$/\1/g')
230 echo "* gosa-plugin-$plugin patch: $patch"
231 [ -d "gosa-plugin-${plugin}-${GOSA_VER}/debian/patches" ] || mkdir -p "gosa-plugin-${plugin}-${GOSA_VER}/debian/patches"
232 cp "$patch" gosa-plugin-${plugin}-${GOSA_VER}/debian/patches
233 else
234 echo "* gosa-core patch: $patch"
235 [ -d "${GOSA_DIR}/debian/patches" ] && mkdir -p "${GOSA_DIR}/debian/patches"
236 cp "$patch" ${GOSA_DIR}/debian/patches
237 fi
238 done
240 # Put section in GOsa_DIR
241 sed -i "s#^Section: web#Section: $SECTION#g" ${GOSA_DIR}/debian/control
242 sed -i "s#^Section: utils#Section: $SI_SECTION#g" ${GOSA_SI_DIR}/debian/control
244 for plugin in $MAKE_PLUGINS; do
245 GOSA_PLUGIN_DIRS="$GOSA_PLUGIN_DIRS gosa-plugin-$plugin-${GOSA_VER}"
246 done
247 for dir in $GOSA_DIR $GOSA_SI_DIR $GOSA_PLUGIN_DIRS; do
248 echo "Adapting version in $dir"
249 if [ "$TARGET_RELEASE" == "unstable" ]; then
250 (cd "$dir"; echo | debchange -v "${GOSA_VER}" "$RELEASE_REASON" >/dev/null 2>&1)
251 else
252 (cd "$dir"; echo | debchange -v "${GOSA_VER}-1${TARGET_RELEASE}1" -D "$TARGET_RELEASE" "$RELEASE_REASON" >/dev/null 2>&1)
253 fi
254 [ -d $dir/debian/patches ] || continue
255 echo "Creating patch list for $dir"
256 ls -1 $dir/debian/patches | grep -v 00list | sed 's%^.*/%%g' > $dir/debian/patches/00list
257 done
259 # Update revision
260 sed -i "s/^\$svn_revision = .*$/\$svn_revision = '\$Revision: $BRANCH_REV \$';/g" $GOSA_DIR/include/functions.inc
262 if [ "$1" = "-s" ]
263 then
264 echo "Creating debian sources..."
265 for dir in $GOSA_DIR $GOSA_SI_DIR $GOSA_PLUGIN_DIRS; do
266 dpkg-source -b "$dir"
267 done
268 else
269 echo "Creating debian packages..."
270 for dir in $GOSA_DIR $GOSA_SI_DIR $GOSA_PLUGIN_DIRS; do
271 (cd "$dir"; dpkg-buildpackage -k$DEBSIGN_KEYID -rfakeroot -sa)
272 done
273 fi
275 echo "Removing gosa snapshot..."
276 if [ -z "$DEBIAN_PKG" ]
277 then
278 for dir in $GOSA_DIR; do
279 rm -rf "$dir"
280 done
281 else
282 for dir in $GOSA_DIR $GOSA_SI_DIR $GOSA_PLUGIN_DIRS; do
283 rm -rf "$dir"
284 done
285 fi