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