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