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##*/} [--download] [--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 else
43 echo "Error: cannot find description file" >&2
44 exit 1
45 fi
46 }
49 TEMP=`getopt -o e:r: --long download,release:,email:,depends:,section: -n 'dh-make-gosa' -- "$@"`
50 if [ $? != 0 ] ; then
51 echo "Error: cannot get command line information" >&2
52 exit 1
53 fi
55 eval set -- "$TEMP"
57 # Load command line vars
58 RELEASE=trunk
59 DOWNLOAD=
60 DEPENDS=
61 SECTION=web
62 DEST=
63 while true; do
64 case "$1" in
65 -e|--email) DEBMAIL=$2
66 shift 2
67 ;;
68 -r|--release)
69 if [ "$2" != "trunk" ]; then
70 RELEASE=tags/$2
71 fi
72 shift 2
73 ;;
74 --depends) DEPENDS="$2"
75 shift 2
76 ;;
77 --section) SECTION="$2"
78 shift 2
79 ;;
80 --dest) DEST=$2/
81 shift 2
82 ;;
83 --download) DOWNLOAD=yes
84 echo "Download is not implemented yet"
85 exit 1
86 ;;
87 --) shift
88 break
89 ;;
90 *) usage
91 ;;
92 esac
93 done
95 [ $# -ne 1 ] && usage
96 file=$*
98 # Three possiblities
99 if [ -d "$file" ]; then
101 # It's a local directory
102 load_dsc $file/plugin.dsc
104 # Setup build environment
105 if [ "$OVERRIDE_VERSION" ]; then
106 BUILD_PATH=${DEST}gosa-plugin-${PL_NAME}-${OVERRIDE_VERSION}
107 else
108 BUILD_PATH=${DEST}gosa-plugin-${PL_NAME}-${PL_VERSION}
109 fi
110 if [ -d "$BUILD_PATH" ]; then
111 echo "Error: build path $BUILD_PATH already exists" >&2
112 exit 2
113 fi
114 cp -a "$PL_NAME" "$BUILD_PATH"
116 elif [ -f "$file" ]; then
118 # It's a compressed user contributed file
119 TMPDIR="/tmp/dh-make-gosa-$PPID"
120 if [ -d "/tmp/dh-make-gosa-$PPID" ]; then
121 echo "Error: directory $TMPDIR exists" >&2
122 exit 4
123 fi
125 # Untar
126 mkdir -p "$TMPDIR"
127 tar --extract --directory "$TMPDIR" -fz "$file" &> /dev/null
128 if [ $? -ne 0 ]; then
129 echo "Error: cannot extract plugin file - invalid file format" >&2
130 exit 5
131 fi
133 # It's a local directory
134 load_dsc TMPDIR/*/plugin.dsc
136 # Setup build environment
137 BUILD_PATH=${DEST}gosa-plugin-${PL_NAME}-${PL_VERSION}
138 mv "$TMPDIR/*" "$BUILD_PATH"
140 else
142 echo "Error: cannot find plugin $file" >&2
143 exit 5
145 fi
148 PL_DEPENDS=$(echo $PL_DEPENDS$DEPENDS | sed 's/,\s*$//')
149 echo "Debian package summary ========================================"
150 echo "Plugin: $PL_NAME"
151 echo "Version: $PL_VERSION"
152 echo "Description: $PL_DESCRIPTION"
153 echo "Depends: $PL_DEPENDS"
154 echo "Conflicts: $PL_CONFLICTS"
155 echo "Author name: $PL_AUTHOR"
156 echo "Author email: $PL_MAIL"
157 echo
158 read -s -n 1 -p "Do you want to continue? (y/n)" ans; echo
159 [ "$ans" != "y" ] && exit 0
161 pushd . &> /dev/null
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
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" >> debian/install
178 done
179 for dir in help/*; do
180 printf "$dir\t\t\t/usr/share/gosa/doc/plugins/$PL_NAME" >> 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" >> 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 if [ "$PL_DEPENDS" ]; then
212 sed -i "s/^Depends: .*$/Depends: gosa, $PL_DEPENDS/g" debian/control
213 else
214 sed -i 's/^Depends: .*$/Depends: gosa/g' debian/control
215 fi
216 if [ "$PL_CONFLICTS" ]; then
217 sed "11Conflicts: $PL_CONFLICTS" debian/control
218 fi
219 sed -i 's/^\(Build-Depends: .*\)$/\1, dpatch/g' debian/control
220 sed -i "s/^Description: .*$/Description: $PL_NAME plugin for GOsa/g" debian/control
221 sed -i "s/^ <.*$/ %DESCRIPTION%/g" debian/control
222 dsc=$(tempfile)
223 {
224 echo $PL_DESCRIPTION
225 cat <<EOF
226 .
227 GOsa is a combination of system-administrator and end-user web
228 interface, designed to handle LDAP based setups.
229 EOF
230 }| fmt -suw79 | sed 's/^/ /g' > $dsc
231 sed -i "/%DESCRIPTION%/r $dsc" debian/control
232 sed -i "/%DESCRIPTION%/d" debian/control
233 rm $dsc
235 # Create patch directory
236 [ ! -d debian/patches ] && mkdir debian/patches
238 # Adapt README.debian
239 cat <<EOF > debian/README.Debian
240 README.Debian for GOsa $PL_NAME plugin $PL_VERSION
241 -------------------------------------------
243 Please read the main GOsa README.Debian file for more information.
245 ----
246 $PL_AUTHOR <$PL_MAIL> Fri 02 Jun 2006 16:23:50 +0200
247 EOF
249 # Fix README
250 sed -i "s/Comments regarding the Package/After installing this plugin you may need to reload apache../g" debian/README
252 # Fix rules
253 cat <<EOF > debian/rules
254 #!/usr/bin/make -f
255 # -*- makefile -*-
256 # GOsa default plugin debhelper file.
257 # This file was originally written by Joey Hess and Craig Small.
258 # As a special exception, when this file is copied by dh-make into a
259 # dh-make output file, you may use that output file without restriction.
260 # This special exception was added by Craig Small in version 0.37 of dh-make.
262 # Uncomment this to turn on verbose mode.
263 #export DH_VERBOSE=1
265 configure: configure-stamp
266 configure-stamp:
267 dh_testdir
268 touch configure-stamp
270 patch: patch-stamp
271 patch-stamp:
272 dpatch apply-all
273 dpatch cat-all >patch-stamp
275 build: patch build-stamp
277 build-stamp: configure-stamp
278 dh_testdir
280 touch $@
282 clean: clean-patched unpatch
283 clean-patched:
284 dh_testdir
285 dh_testroot
286 rm -f build-stamp configure-stamp
287 dh_clean
289 unpatch:
290 dpatch deapply-all
291 rm -rf patch-stamp debian/patched
293 install: build
294 dh_testdir
295 dh_testroot
296 dh_clean -k
297 dh_installdirs
299 # Build architecture-independent files here.
300 binary-indep: build install
301 dh_testdir
302 dh_testroot
303 dh_installchangelogs
304 dh_installdocs
305 dh_installexamples
306 dh_install
307 dh_installman
308 dh_strip
309 dh_compress
310 dh_fixperms
311 dh_installdeb
312 dh_gencontrol
313 dh_md5sums
314 dh_builddeb
316 binary: binary-indep
317 .PHONY: build clean binary-indep binary install configure
318 EOF
320 # Adapt postinst/postrm
321 for file in postinst postrm; do
322 sed 's!#DEBHELPER#!#DEBHELPER#\
323 \
324 # Get apache versions running\
325 servers=""\
326 for srv in apache apache-ssl apache2; do\
327 if [ -x /usr/sbin/$srv ]; then\
328 servers="$srv $servers"\
329 fi\
330 done\
331 \
332 # Update gosa\
333 /usr/sbin/update-gosa\
334 \
335 # Finally restart servers\
336 for server in $servers; do\
337 if [ -x /usr/sbin/invoke-rc.d ]; then\
338 invoke-rc.d $server restart\
339 else\
340 /etc/init.d/$server restart\
341 fi\
342 done\
343 \
344 !' debian/$file.ex > debian/$file
345 done
347 # Remove examples
348 rm debian/*ex debian/*EX &> /dev/null
350 popd &> /dev/null
352 echo "Done."