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