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 usage() {
22 echo "Usage: ${0##*/} [--section section name] [-b|--branch branch] [-e|--email mail] [--depends] plugin-dir|plugin.tar.gz" >&2
23 exit 1
24 }
27 remove_empty_docs() {
28 for dir in $(find help); do
29 len=$(echo $dir | wc -c)
30 echo $len $dir
31 done | sort -rn | while read dummy dir; do
33 if [ -d $dir ]; then
34 cnt=$(ls -1A $dir | wc -l)
35 if [ $cnt -eq 0 ]; then
36 echo "Removing empty $dir"
37 rm -rf "$dir"
38 sed -i "/$(echo -n $dir | sed 's/\//\\\//g')/d" debian/install
39 fi
40 fi
42 done
43 }
46 load_dsc() {
47 if [ -r "$1" ]; then
48 PL_NAME=$(sed -n 's/"//g;s/^name\s*=\s*\(.*\)$/\1/p' "$1")
49 PL_VERSION=$(sed -n 's/"//g;s/^version\s*=\s*\(.*\)$/\1/p' "$1")
50 TDEPENDS=$(sed -n 's/"//g;s/^depends\s*=\s*\(.*\)$/\1/p' "$1")
51 for dep in $TDEPENDS; do
52 PL_DEPENDS="gosa-plugin-$dep, $PL_DEPENDS"
53 done
54 TCONFLICTS=$(sed -n 's/"//g;s/^conflicts\s*=\s*\(.*\)$/\1/p' "$1")
55 for dep in $TCONFLICTS; do
56 PL_CONFLICTS="gosa-plugin-$dep, $PL_CONFLICTS"
57 done
58 PL_DESCRIPTION=$(sed -n 's/"//g;s/^description\s*=\s*\(.*\)$/\1/p' "$1")
59 PL_AUTHOR=$(sed -n 's/"//g;s/^author\s*=\s*\([^<]*\).*$/\1/p' "$1")
60 PL_MAIL=$(sed -n 's/"//g;s/^author\s*=[^<].*<\([^>]*\).*$/\1/p' "$1")
61 PL_HOMEPAGE=$(sed -n 's/"//g;s/^homepage\s*=\s*\(.*\)$/\1/p' "$1")
62 else
63 echo "Error: cannot find description file" >&2
64 exit 1
65 fi
66 }
69 TEMP=`getopt -o e:r: --long download,release:,email:,depends:,section: -n 'dh-make-gosa' -- "$@"`
70 if [ $? != 0 ] ; then
71 echo "Error: cannot get command line information" >&2
72 exit 1
73 fi
75 eval set -- "$TEMP"
77 # Load command line vars
78 RELEASE=trunk
79 DOWNLOAD=
80 DEPENDS=
81 SECTION=web
82 DEST=
83 while true; do
84 case "$1" in
85 -e|--email) DEBMAIL=$2
86 shift 2
87 ;;
88 -r|--release)
89 if [ "$2" != "trunk" ]; then
90 RELEASE=tags/$2
91 fi
92 shift 2
93 ;;
94 --depends) DEPENDS="$2"
95 shift 2
96 ;;
97 --section) SECTION="$2"
98 shift 2
99 ;;
100 --dest) DEST=$2/
101 shift 2
102 ;;
103 --download) DOWNLOAD=yes
104 echo "Download is not implemented yet"
105 exit 1
106 ;;
107 --) shift
108 break
109 ;;
110 *) usage
111 ;;
112 esac
113 done
115 [ $# -ne 1 ] && usage
116 file=$*
118 # Three possiblities
119 if [ -d "$file" ]; then
121 # It's a local directory
122 load_dsc $file/plugin.dsc
124 # Setup build environment
125 if [ "$OVERRIDE_VERSION" ]; then
126 BUILD_PATH=${DEST}gosa-plugin-${PL_NAME}-${OVERRIDE_VERSION}
127 else
128 BUILD_PATH=${DEST}gosa-plugin-${PL_NAME}-${PL_VERSION}
129 fi
130 if [ -d "$BUILD_PATH" ]; then
131 echo "Error: build path $BUILD_PATH already exists" >&2
132 exit 2
133 fi
134 cp -a "$PL_NAME" "$BUILD_PATH"
136 elif [ -f "$file" ]; then
138 # It's a compressed user contributed file
139 TMPDIR="/tmp/dh-make-gosa-$PPID"
140 if [ -d "/tmp/dh-make-gosa-$PPID" ]; then
141 echo "Error: directory $TMPDIR exists" >&2
142 exit 4
143 fi
145 # Untar
146 mkdir -p "$TMPDIR"
147 tar --extract --directory "$TMPDIR" -fz "$file" >/dev/null 2>&1
148 if [ $? -ne 0 ]; then
149 echo "Error: cannot extract plugin file - invalid file format" >&2
150 exit 5
151 fi
153 # It's a local directory
154 load_dsc TMPDIR/*/plugin.dsc
156 # Setup build environment
157 BUILD_PATH=${DEST}gosa-plugin-${PL_NAME}-${PL_VERSION}
158 mv "$TMPDIR/*" "$BUILD_PATH"
160 else
162 echo "Error: cannot find plugin $file" >&2
163 exit 5
165 fi
168 PL_DEPENDS=$(echo $PL_DEPENDS$DEPENDS | sed 's/,\s*$//')
169 echo "Debian package summary ========================================"
170 echo "Plugin: $PL_NAME"
171 echo "Version: $PL_VERSION"
172 echo "Description: $PL_DESCRIPTION"
173 echo "Depends: $PL_DEPENDS"
174 echo "Conflicts: $PL_CONFLICTS"
175 echo "Author name: $PL_AUTHOR"
176 echo "Author email: $PL_MAIL"
177 echo "Homepage: $PL_HOMEPAGE"
178 echo
179 read -s -n 1 -p "Do you want to continue? (y/n)" ans; echo
180 [ "$ans" != "y" ] && exit 0
182 cd "$BUILD_PATH"
184 # Use gosa-plugin skelleton
185 echo "Calling dh_make..."
186 echo | dh_make -e "$PL_MAIL" -c gpl -s -n -f gosa-plugin-${PL_NAME}-${PL_VERSION}.tar.gz >/dev/null 2>&1
187 if [ $? -ne 0 ]; then
188 echo "Failed to call dh_make - aborting!"
189 exit 1
190 fi
192 echo "Apdapting debian descriptive files..."
194 # Generate install file
195 for dir in admin personal addons gofax gofon generic; do
196 [ -d $dir ] && printf "$dir\t\t\t/usr/share/gosa/plugins\n" >> debian/install
197 done
198 for dir in help/*; do
199 printf "$dir\t\t\t/usr/share/gosa/doc/plugins/$PL_NAME\n" >> debian/install
200 done
201 for dir in $(ls -1 locale | grep -v "^en$" | grep -v "^messages.po$"); do
202 printf "locale/$dir\t\t\t/usr/share/gosa/locale/plugins/$PL_NAME\n" >> debian/install
203 done
205 # Generate dirs
206 echo "usr/share/gosa" > debian/dirs
208 # If we've a contrib directory include it to the docs
209 if [ -d contrib ]; then
210 echo "contrib /usr/share/doc/gosa-plugin-$PL_NAME" >> debian/install
211 fi
212 if [ -d html ]; then
213 for i in html/*; do
214 echo "$i /usr/share/gosa/html/plugins/$PL_NAME" >> debian/install
215 done
216 fi
218 # Fix copyright
219 sed -i '/^### OR ###/,/^########/d' debian/copyright
220 sed -i '/^#/d;/^.*likewise for another author.*$/d' debian/copyright
221 year=$(date +%Y)
222 sed -i "s/.Copyright (C) YYYY Name OfAuthor./Copyright \(C) $year $PL_AUTHOR/g" debian/copyright
223 sed -i "s/<Copyright (C) YYYY Firtname Lastname>/Copyright \(C) $year $PL_AUTHOR/g" debian/copyright
224 sed -i "s/.url:\/\/example.com./http:\/\/www.gosa-project.org/g" debian/copyright
225 sed -i "/.put author's name and email here.\
226 /d" debian/copyright
227 sed -i '/^Upstream/,/^$/d' debian/copyright
228 sed -i 's/ C)/ (C)/g' debian/copyright
230 # Adapt control
231 sed -i "s#^Section: unknown#Section: $SECTION#g" debian/control
232 sed -i 's/^Architecture: any/Architecture: all/g' debian/control
233 sed -i "s#^Homepage: <insert the upstream URL, if relevant>#Homepage: $PL_HOMEPAGE#g" debian/control
235 if [ "$PL_DEPENDS" ]; then
236 sed -i "s/^Depends: .*$/Depends: gosa, $PL_DEPENDS/g" debian/control
237 else
238 sed -i 's/^Depends: .*$/Depends: gosa/g' debian/control
239 fi
240 if [ "$PL_CONFLICTS" ]; then
241 sed "11Conflicts: $PL_CONFLICTS" debian/control
242 fi
243 sed -i 's/^\(Build-Depends: .*\)$/\1, dpatch/g' debian/control
244 sed -i "s/^Description: .*$/Description: $PL_NAME plugin for GOsa/g" debian/control
245 sed -i "s/^ <.*$/ %DESCRIPTION%/g" debian/control
246 dsc=$(tempfile)
247 {
248 echo $PL_DESCRIPTION
249 cat <<EOF
250 .
251 GOsa is a combination of system-administrator and end-user web
252 interface, designed to handle LDAP based setups.
253 EOF
254 }| fmt -suw79 | sed 's/^/ /g' > $dsc
255 sed -i "/%DESCRIPTION%/r $dsc" debian/control
256 sed -i "/%DESCRIPTION%/d" debian/control
257 rm $dsc
259 # Do we need to generate another package for schema files?
260 if ls contrib/*schema &> /dev/null; then
261 echo etc/ldap/schema/gosa > debian/gosa-plugin-${PL_NAME}-schema.dirs
262 ls -1 contrib/*schema | sed 's%$% /etc/ldap/schema/gosa%g' > debian/gosa-plugin-${PL_NAME}-schema.install
264 cat <<-EOF >> debian/control
266 Package: gosa-plugin-${PL_NAME}-schema
267 Architecture: all
268 Recommends: slapd
269 Description: LDAP schema for GOsa plugin ${PL_NAME}
270 This package includes the LDAP schema needed by the GOsa
271 ${PL_NAME} plugin.
272 .
273 GOsa is a combination of system-administrator and end-user web
274 interface, designed to handle LDAP based setups.
275 EOF
276 fi
278 # Create patch directory
279 [ ! -d debian/patches ] && mkdir debian/patches
281 # Adapt README.debian
282 cat <<EOF > debian/README.Debian
283 README.Debian for GOsa $PL_NAME plugin $PL_VERSION
284 -------------------------------------------
286 Please read the main GOsa README.Debian file for more information.
288 ----
289 $PL_AUTHOR <$PL_MAIL> Fri 02 Jun 2006 16:23:50 +0200
290 EOF
292 # Fix README
293 sed -i "s/Comments regarding the Package/After installing this plugin you may need to reload apache../g" debian/README
295 # Fix rules
296 cat <<EOF > debian/rules
297 #!/usr/bin/make -f
298 # -*- makefile -*-
299 # GOsa default plugin debhelper file.
300 # This file was originally written by Joey Hess and Craig Small.
301 # As a special exception, when this file is copied by dh-make into a
302 # dh-make output file, you may use that output file without restriction.
303 # This special exception was added by Craig Small in version 0.37 of dh-make.
305 # Uncomment this to turn on verbose mode.
306 #export DH_VERBOSE=1
308 configure: configure-stamp
309 configure-stamp:
310 dh_testdir
311 touch configure-stamp
313 patch: patch-stamp
314 patch-stamp:
315 dpatch apply-all
316 dpatch cat-all >patch-stamp
318 build: patch build-stamp
320 build-stamp: configure-stamp
321 dh_testdir
323 touch $@
325 clean: clean-patched unpatch
326 clean-patched:
327 dh_testdir
328 dh_testroot
329 rm -f build-stamp configure-stamp
330 dh_clean
332 unpatch:
333 dpatch deapply-all
334 rm -rf patch-stamp debian/patched
336 install: build
337 dh_testdir
338 dh_testroot
339 dh_clean -k
340 dh_installdirs
342 # Build architecture-independent files here.
343 binary-indep: build install
344 dh_testdir
345 dh_testroot
346 dh_installchangelogs
347 dh_installdocs
348 dh_installexamples
349 dh_install
350 dh_installman
351 dh_strip
352 dh_compress
353 dh_fixperms
354 dh_installdeb
355 dh_gencontrol
356 dh_md5sums
357 dh_builddeb
359 binary: binary-indep
361 binary-arch:
362 .PHONY: build clean binary-indep binary install configure
363 EOF
365 # Adapt postinst/postrm
366 for file in postinst postrm; do
367 sed 's!#DEBHELPER#!#DEBHELPER#\
368 \
369 # Get apache versions running\
370 servers=""\
371 for srv in apache apache-ssl apache2; do\
372 if [ -x /usr/sbin/$srv ]; then\
373 servers="$srv $servers"\
374 fi\
375 done\
376 \
377 # Update gosa\
378 update-gosa\
379 \
380 # Finally restart servers\
381 for server in $servers; do\
382 if [ -x /usr/sbin/invoke-rc.d ]; then\
383 invoke-rc.d $server restart\
384 else\
385 /etc/init.d/$server restart\
386 fi\
387 done\
388 \
389 !' debian/$file.ex > debian/$file
390 done
392 # Remove examples
393 rm debian/*ex debian/*EX >/dev/null 2>&1
395 # Remove empty docs
396 remove_empty_docs
398 echo "Done."