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