1 #!/bin/bash
3 usage() {
4 echo "Usage: ${0##*/} [--download] [-b|--branch branch] [-e|--email mail] [--depends] plugin-dir|plugin.tar.gz" >&2
5 exit 1
6 }
9 load_dsc() {
10 if [ -r "$1" ]; then
11 PL_NAME=$(sed -n 's/"//g;s/^name\s*=\s*\(.*\)$/\1/p' "$1")
12 PL_VERSION=$(sed -n 's/"//g;s/^version\s*=\s*\(.*\)$/\1/p' "$1")
13 TDEPENDS=$(sed -n 's/"//g;s/^depends\s*=\s*\(.*\)$/\1/p' "$1")
14 for dep in $TDEPENDS; do
15 PL_DEPENDS="gosa-plugin-$dep, $PL_DEPENDS"
16 done
17 TCONFLICTS=$(sed -n 's/"//g;s/^conflicts\s*=\s*\(.*\)$/\1/p' "$1")
18 for dep in $TCONFLICTS; do
19 PL_CONFLICTS="gosa-plugin-$dep, $PL_CONFLICTS"
20 done
21 PL_DESCRIPTION=$(sed -n 's/"//g;s/^description\s*=\s*\(.*\)$/\1/p' "$1")
22 PL_AUTHOR=$(sed -n 's/"//g;s/^author\s*=\s*\([^<]*\).*$/\1/p' "$1")
23 PL_MAIL=$(sed -n 's/"//g;s/^author\s*=[^<].*<\([^>]*\).*$/\1/p' "$1")
24 else
25 echo "Error: cannot find description file" >&2
26 exit 1
27 fi
28 }
31 TEMP=`getopt -o e:r: --long download,release:,email:,depends: -n 'dh-make-gosa' -- "$@"`
32 if [ $? != 0 ] ; then
33 echo "Error: cannot get command line information" >&2
34 exit 1
35 fi
37 eval set -- "$TEMP"
39 # Load command line vars
40 RELEASE=trunk
41 DOWNLOAD=
42 DEPENDS=
43 DEST=
44 while true; do
45 case "$1" in
46 -e|--email) DEBMAIL=$2
47 shift 2
48 ;;
49 -r|--release)
50 if [ "$2" != "trunk" ]; then
51 RELEASE=tags/$2
52 fi
53 shift 2
54 ;;
55 --depends) DEPENDS="$2"
56 shift 2
57 ;;
58 --dest) DEST=$2/
59 shift 2
60 ;;
61 --download) DOWNLOAD=yes
62 shift 1
63 ;;
64 --) shift
65 break
66 ;;
67 *) usage
68 ;;
69 esac
70 done
72 [ $# -ne 1 ] && usage
73 file=$*
75 # Three possiblities
76 if [ -d "$file" ]; then
78 # It's a local directory
79 load_dsc $file/plugin.dsc
81 # Setup build environment
82 if [ "$OVERRIDE_VERSION" ]; then
83 BUILD_PATH=${DEST}gosa-plugin-${PL_NAME}-${OVERRIDE_VERSION}
84 else
85 BUILD_PATH=${DEST}gosa-plugin-${PL_NAME}-${PL_VERSION}
86 fi
87 if [ -d "$BUILD_PATH" ]; then
88 echo "Error: build path $BUILD_PATH already exists" >&2
89 exit 2
90 fi
91 cp -a "$PL_NAME" "$BUILD_PATH"
93 elif [ -f "$file" ]; then
95 # It's a compressed user contributed file
96 TMPDIR="/tmp/dh-make-gosa-$PPID"
97 if [ -d "/tmp/dh-make-gosa-$PPID" ]; then
98 echo "Error: directory $TMPDIR exists" >&2
99 exit 4
100 fi
102 # Untar
103 mkdir -p "$TMPDIR"
104 tar --extract --directory "$TMPDIR" -fz "$file" &> /dev/null
105 if [ $? -ne 0 ]; then
106 echo "Error: cannot extract plugin file - invalid file format" >&2
107 exit 5
108 fi
110 # It's a local directory
111 load_dsc TMPDIR/*/plugin.dsc
113 # Setup build environment
114 BUILD_PATH=${DEST}gosa-plugin-${PL_NAME}-${PL_VERSION}
115 mv "$TMPDIR/*" "$BUILD_PATH"
117 else
119 echo "Error: cannot find plugin $file" >&2
120 exit 5
122 fi
125 PL_DEPENDS=$(echo $PL_DEPENDS$DEPENDS | sed 's/,\s*$//')
126 echo "Debian package summary ========================================"
127 echo "Plugin: $PL_NAME"
128 echo "Version: $PL_VERSION"
129 echo "Description: $PL_DESCRIPTION"
130 echo "Depends: $PL_DEPENDS"
131 echo "Conflicts: $PL_CONFLICTS"
132 echo "Author name: $PL_AUTHOR"
133 echo "Author email: $PL_MAIL"
134 echo
135 read -s -n 1 -p "Do you want to continue? (y/n)" ans; echo
136 [ "$ans" != "y" ] && exit 0
138 pushd . &> /dev/null
140 cd "$BUILD_PATH"
142 # Use gosa-plugin skelleton
143 echo "Calling dh_make..."
144 echo | dh_make -e "$PL_MAIL" -c gpl -s -n -f gosa-plugin-${PL_NAME}-${PL_VERSION}.tar.gz &> /dev/null
145 if [ $? -ne 0 ]; then
146 echo "Failed to call dh_make - aborting!"
147 exit 1
148 fi
150 echo "Apdapting debian descriptive files..."
152 # Generate install file
153 for dir in admin personal addons gofax gofon generic; do
154 [ -d $dir ] && echo -e "$dir\t\t\t/usr/share/gosa/plugins" >> debian/install
155 done
156 for dir in help/*; do
157 echo -e "$dir\t\t\t/usr/share/gosa/doc/plugins/$PL_NAME" >> debian/install
158 done
159 for dir in $(ls -1 locale | grep -v "^en$" | grep -v "^messages.po$"); do
160 echo -e "locale/$dir\t\t\t/usr/share/gosa/locale/plugins/$PL_NAME" >> debian/install
161 done
163 # Generate dirs
164 echo "usr/share/gosa" > debian/dirs
166 # If we've a contrib directory include it to the docs
167 if [ -d contrib ]; then
168 echo "contrib /usr/share/doc/gosa-plugin-$PL_NAME" >> debian/install
169 fi
170 if [ -d html ]; then
171 for i in html/*; do
172 echo "$i /usr/share/gosa/html/plugins/$PL_NAME" >> debian/install
173 done
174 fi
176 # Fix copyright
177 sed -i '/^#/d;/^.*likewise for another author.*$/d' debian/copyright
178 year=$(date +%Y)
179 sed -i "s/.Copyright (C) YYYY Name OfAuthor./Copyright (C) $year $PL_AUTHOR/g" debian/copyright
180 sed -i "s/.url:\/\/example.com./http:\/\/www.gosa-project.org/g" debian/copyright
181 sed -i "/.put author's name and email here.\
182 /d" debian/copyright
183 sed -i '/^Upstream/,/^$/d' debian/copyright
185 # Adapt control
186 sed -i 's/^Section: unknown/Section: web/g' debian/control
187 sed -i 's/^Architecture: any/Architecture: all/g' debian/control
188 if [ "$PL_DEPENDS" ]; then
189 sed -i "s/^Depends: .*$/Depends: gosa, $PL_DEPENDS/g" debian/control
190 else
191 sed -i 's/^Depends: .*$/Depends: gosa/g' debian/control
192 fi
193 if [ "$PL_CONFLICTS" ]; then
194 sed "11Conflicts: $PL_CONFLICTS" debian/control
195 fi
196 sed -i 's/^\(Build-Depends: .*\)$/\1, dpatch/g' debian/control
197 sed -i "s/^Description: .*$/Description: $PL_NAME plugin for GOsa/g" debian/control
198 sed -i "s/^ <.*$/ %DESCRIPTION%/g" debian/control
199 dsc=$(tempfile)
200 {
201 echo $PL_DESCRIPTION
202 cat <<EOF
203 .
204 GOsa is a combination of system-administrator and end-user web
205 interface, designed to handle LDAP based setups.
206 EOF
207 }| fmt -suw79 | sed 's/^/ /g' > $dsc
208 sed -i "/%DESCRIPTION%/r $dsc" debian/control
209 sed -i "/%DESCRIPTION%/d" debian/control
210 rm $dsc
212 # Create patch directory
213 [ ! -d debian/patches ] && mkdir debian/patches
215 # Adapt README.debian
216 cat <<EOF > debian/README.Debian
217 README.Debian for GOsa $PL_NAME plugin $PL_VERSION
218 -------------------------------------------
220 Please read the main GOsa README.Debian file for more information.
222 ----
223 $PL_AUTHOR <$PL_MAIL> Fri 02 Jun 2006 16:23:50 +0200
224 EOF
226 # Fix README
227 sed -i "s/Comments regarding the Package/After installing this plugin you may need to reload apache../g" debian/README
229 # Fix rules
230 cat <<EOF > debian/rules
231 #!/usr/bin/make -f
232 # -*- makefile -*-
233 # GOsa default plugin debhelper file.
234 # This file was originally written by Joey Hess and Craig Small.
235 # As a special exception, when this file is copied by dh-make into a
236 # dh-make output file, you may use that output file without restriction.
237 # This special exception was added by Craig Small in version 0.37 of dh-make.
239 # Uncomment this to turn on verbose mode.
240 #export DH_VERBOSE=1
242 configure: configure-stamp
243 configure-stamp:
244 dh_testdir
245 touch configure-stamp
247 patch: patch-stamp
248 patch-stamp:
249 dpatch apply-all
250 dpatch cat-all >patch-stamp
252 build: patch build-stamp
254 build-stamp: configure-stamp
255 dh_testdir
257 touch $@
259 clean: clean-patched unpatch
260 clean-patched:
261 dh_testdir
262 dh_testroot
263 rm -f build-stamp configure-stamp
264 dh_clean
266 unpatch:
267 dpatch deapply-all
268 rm -rf patch-stamp debian/patched
270 install: build
271 dh_testdir
272 dh_testroot
273 dh_clean -k
274 dh_installdirs
276 # Build architecture-independent files here.
277 binary-indep: build install
278 dh_testdir
279 dh_testroot
280 dh_installchangelogs
281 dh_installdocs
282 dh_installexamples
283 dh_install
284 dh_installman
285 dh_strip
286 dh_compress
287 dh_fixperms
288 dh_installdeb
289 dh_gencontrol
290 dh_md5sums
291 dh_builddeb
293 binary: binary-indep
294 .PHONY: build clean binary-indep binary install configure
295 EOF
297 # Adapt postinst/postrm
298 for file in postinst postrm; do
299 sed 's!#DEBHELPER#!#DEBHELPER#\
300 \
301 # Get apache versions running\
302 servers=""\
303 for srv in apache apache-ssl apache2; do\
304 if [ -x /usr/sbin/$srv ]; then\
305 servers="$srv $servers"\
306 fi\
307 done\
308 \
309 # Update gosa\
310 /usr/sbin/update-gosa\
311 \
312 # Finally restart servers\
313 for server in $servers; do\
314 if [ -x /usr/sbin/invoke-rc.d ]; then\
315 invoke-rc.d $server restart\
316 else\
317 /etc/init.d/$server restart\
318 fi\
319 done\
320 \
321 !' debian/$file.ex > debian/$file
322 done
324 # Remove examples
325 rm debian/*ex debian/*EX &> /dev/null
327 popd &> /dev/null
329 echo "Done."