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 opsi apache2 ssh"
30 usage() {
31 cat <<-EOF
32 GOsa Debian package build tool. Build snapshots from selected SVN locations.
33 Usage: ${0##*/} [options]
35 Options:
36 -b|--branch Branch to export [$BRANCH]
37 -p|--plugins Comma seperate list of plugins to build. Leave empty to build all.
38 -r|--release Debian release to build for [$TARGET_RELEASE]
39 -c|--changelog Debian changelog entry [$RELEASE_REASON]
40 -s|--section Debian section to place GOsa in [$SECTION]
41 -i|--si-section Debian section to place GOsa-SI in [$SI_SECTION]
42 -d|--debian-pkg Don't clear up debian packages for plugins (for developers only)
43 -h|--help this help
45 EOF
46 exit 1
47 }
49 for cmd in dh-make-gosa debchange dpkg-buildpackage dpkg-source svn; do
50 if ! which $cmd >/dev/null; then
51 echo "Error: cannot find '$cmd' command in path!";
52 exit 1
53 fi
54 done
56 # Import command line parameters
57 PARMS=`getopt -o d::b:r:s:c:i:p:,h --long branch:,changelog:,plugins:,section:,si-section:,release:,help -n "${0##*/}" -- "$@"`
58 eval set -- "$PARMS"
60 while true; do
61 case "$1" in
62 -b|--branch)
63 BRANCH=$2; shift 2 ;;
64 -r|--release)
65 TARGET_RELEASE=$2; shift 2 ;;
66 -c|--changelog)
67 RELEASE_REASON=$2; shift 2 ;;
68 -p|--plugins)
69 MAKE_PLUGINS=$(echo $2 | tr ',' ' '); shift 2 ;;
70 -s|--section)
71 SECTION=$2; shift 2 ;;
72 -i|--si-section)
73 SI_SECTION=$2; shift 2 ;;
74 -d|--debian-pkg)
75 DEBIAN_PKG=$2; shift 2 ;;
76 -h|--help)
77 usage ;;
78 --)
79 shift; break ;;
80 *)
81 echo "getopt error" ;;
82 esac
83 done
85 echo "Loading svn information for '${BRANCH}'..."
86 svn co -N https://oss.gonicus.de/repositories/gosa/${BRANCH} gosa-info/ > /dev/null
87 BRANCH_REV=$(LANG=C svn info gosa-info | sed -n -e 's/^Last Changed Rev: \([0-9]*\).*$/\1/p')
88 rm -rf gosa-info
90 # Load current revision from logs
91 VERSION=$(svn cat -r "${BRANCH_REV}" https://oss.gonicus.de/repositories/gosa/${BRANCH}/gosa-core/debian/changelog \
92 | head -n 1 | sed -n -e 's/.*(\([^-]*\).*/\1/p')
93 if [ "$BRANCH" == "trunk" ]; then
94 GOSA_VER="${VERSION}+svn${BRANCH_REV}"
95 else
96 GOSA_VER="${VERSION}"
97 fi
98 GOSA_DIR="gosa-${GOSA_VER}"
100 ORIG_FILE="gosa_${GOSA_VER}.orig.tar.gz"
102 # Export from svn...
103 BNAME=$(basename $BRANCH)
104 [ -d "gosa-${BNAME}" ] && rm -rf gosa-$BNAME
105 echo "Exporting current GOsa (rev: ${BRANCH_REV}) from '${BRANCH}'..."
106 svn export -r "${BRANCH_REV}" https://oss.gonicus.de/repositories/gosa/${BRANCH}/gosa-core gosa-${BNAME} > /dev/null
107 svn export -r "${BRANCH_REV}" https://oss.gonicus.de/repositories/gosa/${BRANCH}/gosa-si gosa-si-${BNAME} > /dev/null
108 svn export -r "${BRANCH_REV}" https://oss.gonicus.de/repositories/gosa/${BRANCH}/gosa-plugins gosa-plugins-${BNAME} > /dev/null
110 VERSION=$(cat "gosa-${BNAME}/debian/changelog" | head -n 1 | sed -n -e 's/.*(\([^-]*\).*/\1/p')
111 if [ "$BRANCH" == "trunk" ]; then
112 GOSA_VER="${VERSION}+svn${BRANCH_REV}"
113 else
114 GOSA_VER="${VERSION}"
115 fi
116 GOSA_DIR="gosa-${GOSA_VER}"
117 GOSA_SI_DIR="gosa-si-${GOSA_VER}"
119 if [ "$BNAME" != "$GOSA_VER" ]
120 then
121 rm -rf "gosa-${GOSA_VER}"
122 fi
123 mv "gosa-${BNAME}" "gosa-${GOSA_VER}"
124 mv "gosa-si-${BNAME}" "gosa-si-${GOSA_VER}"
126 echo "Creating original sources 'gosa-${GOSA_VER}'..."
127 tar -c -f "gosa_${GOSA_VER}.orig.tar" "${GOSA_DIR}"
128 tar -c -f "gosa-si_${GOSA_VER}.orig.tar" "${GOSA_SI_DIR}"
130 echo "Compressing sources..."
131 gzip -f -9 "gosa_${GOSA_VER}.orig.tar"
132 gzip -f -9 "gosa-si_${GOSA_VER}.orig.tar"
134 export OVERRIDE_VERSION="$GOSA_VER"
135 if [ -z "$MAKE_PLUGINS" ]; then
136 MAKE_PLUGINS=$(ls -1 gosa-plugins-${BNAME}/*/plugin.dsc | sed 's/^.*\/\([^\/]*\)\/plugin.dsc$/\1/')
137 for i in $NOT_RELEASED; do
138 MAKE_PLUGINS=$(echo -n $MAKE_PLUGINS | sed "s/$i//")
139 done
140 fi
141 for plugin in $MAKE_PLUGINS; do
143 GOSA_PLUG_DIR="gosa-plugin-$plugin-${GOSA_VER}"
144 mv "gosa-plugins-${BNAME}/$plugin" .
146 echo "Debianizing plugin $plugin"
147 yes | dh-make-gosa --section $SECTION $plugin
148 rm -rf "$plugin"
150 echo "Packing original sources 'gosa-plugin-$plugin-${GOSA_VER}'..."
151 tar -c -f "gosa-plugin-${plugin}_${GOSA_VER}.orig.tar" "${GOSA_PLUG_DIR}"
153 echo "Compressing sources..."
154 gzip -f -9 "gosa-plugin-${plugin}_${GOSA_VER}.orig.tar"
155 done
157 rm -rf gosa-plugins-${BNAME}
159 echo "Deploying patches..."
160 for patch in $(find patches -type f | grep -v .svn); do
162 if echo $patch | grep -q gosa-plugin; then
163 plugin=$(echo $patch | sed 's/^.*gosa-plugin-\([^-]*\).*$/\1/g')
164 echo "* gosa-plugin-$plugin patch: $patch"
165 [ -d "gosa-plugin-${plugin}-${GOSA_VER}/debian/patches" ] || mkdir -p "gosa-plugin-${plugin}-${GOSA_VER}/debian/patches"
166 cp "$patch" gosa-plugin-${plugin}-${GOSA_VER}/debian/patches
167 else
168 echo "* gosa-core patch: $patch"
169 [ -d "${GOSA_DIR}/debian/patches" ] && mkdir -p "${GOSA_DIR}/debian/patches"
170 cp "$patch" ${GOSA_DIR}/debian/patches
171 fi
172 done
174 # Passe section im GOsa_DIR an
175 sed -i "s#^Section: web#Section: $SECTION#g" ${GOSA_DIR}/debian/control
176 sed -i "s#^Section: utils#Section: $SI_SECTION#g" ${GOSA_SI_DIR}/debian/control
178 for plugin in $MAKE_PLUGINS; do
179 GOSA_PLUGIN_DIRS="$GOSA_PLUGIN_DIRS gosa-plugin-$plugin-${GOSA_VER}"
180 done
181 for dir in $GOSA_DIR $GOSA_SI_DIR $GOSA_PLUGIN_DIRS; do
182 echo "Adapting version in $dir"
183 if [ "$TARGET_RELEASE" == "unstable" ]; then
184 (cd "$dir"; echo | debchange -v "${GOSA_VER}" "$RELEASE_REASON" >/dev/null 2>&1)
185 else
186 (cd "$dir"; echo | debchange -v "${GOSA_VER}-1${TARGET_RELEASE}1" -D "$TARGET_RELEASE" "$RELEASE_REASON" >/dev/null 2>&1)
187 fi
188 [ -d $dir/debian/patches ] || continue
189 echo "Creating patch list for $dir"
190 ls -1 $dir/debian/patches | grep -v 00list | sed 's%^.*/%%g' > $dir/debian/patches/00list
191 done
193 # Update revision
194 sed -i "s/^\$svn_revision = .*$/\$svn_revision = '\$Revision: $BRANCH_REV \$';/g" $GOSA_DIR/include/functions.inc
196 if [ "$1" = "-s" ]
197 then
198 echo "Creating debian sources..."
199 for dir in $GOSA_DIR $GOSA_SI_DIR $GOSA_PLUGIN_DIRS; do
200 dpkg-source -b "$dir"
201 done
202 else
203 echo "Creating debian packages..."
204 for dir in $GOSA_DIR $GOSA_SI_DIR $GOSA_PLUGIN_DIRS; do
205 (cd "$dir"; dpkg-buildpackage -k$DEBSIGN_KEYID -rfakeroot -sa)
206 done
207 fi
209 echo "Removing gosa snapshot..."
210 if [ -z "$DEBIAN_PKG" ]
211 then
212 for dir in $GOSA_DIR; do
213 rm -rf "$dir"
214 done
215 else
216 for dir in $GOSA_DIR $GOSA_SI_DIR $GOSA_PLUGIN_DIRS; do
217 rm -rf "$dir"
218 done
219 fi