Code

Updated error messages before exit() statements
[gosa.git] / gosa-core / dh-make-gosa
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 2>&1
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 cd "$BUILD_PATH"
163 # Use gosa-plugin skelleton
164 echo "Calling dh_make..."
165 echo | dh_make -e "$PL_MAIL" -c gpl -s -n -f gosa-plugin-${PL_NAME}-${PL_VERSION}.tar.gz >/dev/null 2>&1
166 if [ $? -ne 0 ]; then
167         echo "Failed to call dh_make - aborting!"
168         exit 1
169 fi
171 echo "Apdapting debian descriptive files..."
173 # Generate install file
174 for dir in admin personal addons gofax gofon generic; do
175         [ -d $dir ] && printf "$dir\t\t\t/usr/share/gosa/plugins\n" >> debian/install
176 done
177 for dir in help/*; do
178         printf "$dir\t\t\t/usr/share/gosa/doc/plugins/$PL_NAME\n" >> debian/install
179 done
180 for dir in $(ls -1 locale | grep -v "^en$" | grep -v "^messages.po$"); do
181         printf "locale/$dir\t\t\t/usr/share/gosa/locale/plugins/$PL_NAME\n" >> debian/install
182 done
184 # Generate dirs
185 echo "usr/share/gosa" > debian/dirs
187 # If we've a contrib directory include it to the docs
188 if [ -d contrib ]; then
189         echo "contrib /usr/share/doc/gosa-plugin-$PL_NAME" >> debian/install
190 fi
191 if [ -d html ]; then
192         for i in html/*; do
193                 echo "$i /usr/share/gosa/html/plugins/$PL_NAME" >> debian/install
194         done
195 fi
197 # Fix copyright
198 sed -i '/^#/d;/^.*likewise for another author.*$/d' debian/copyright
199 year=$(date +%Y)
200 sed -i "s/.Copyright (C) YYYY Name OfAuthor./Copyright (C) $year $PL_AUTHOR/g" debian/copyright
201 sed -i "s/.url:\/\/example.com./http:\/\/www.gosa-project.org/g" debian/copyright
202 sed -i "/.put author's name and email here.\
203 /d" debian/copyright
204 sed -i '/^Upstream/,/^$/d' debian/copyright
206 # Adapt control
207 sed -i "s#^Section: unknown#Section: $SECTION#g" debian/control
208 sed -i 's/^Architecture: any/Architecture: all/g' debian/control
209 if [ "$PL_DEPENDS" ]; then
210         sed -i "s/^Depends: .*$/Depends: gosa, $PL_DEPENDS/g" debian/control
211 else
212         sed -i 's/^Depends: .*$/Depends: gosa/g' debian/control
213 fi
214 if [ "$PL_CONFLICTS" ]; then
215         sed "11Conflicts: $PL_CONFLICTS" debian/control
216 fi
217 sed -i 's/^\(Build-Depends: .*\)$/\1, dpatch/g' debian/control
218 sed -i "s/^Description: .*$/Description: $PL_NAME plugin for GOsa/g" debian/control
219 sed -i "s/^ <.*$/ %DESCRIPTION%/g" debian/control
220 dsc=$(tempfile)
222 echo $PL_DESCRIPTION 
223 cat <<EOF
225 GOsa is a combination of system-administrator and end-user web
226 interface, designed to handle LDAP based setups.
227 EOF
228 }| fmt -suw79 | sed 's/^/ /g' > $dsc
229 sed -i "/%DESCRIPTION%/r $dsc" debian/control
230 sed -i "/%DESCRIPTION%/d" debian/control
231 rm $dsc
233 # Create patch directory
234 [ ! -d debian/patches ] && mkdir debian/patches
236 # Adapt README.debian
237 cat <<EOF > debian/README.Debian
238 README.Debian for GOsa $PL_NAME plugin $PL_VERSION
239 -------------------------------------------
241 Please read the main GOsa README.Debian file for more information.
243 ----
244 $PL_AUTHOR <$PL_MAIL>  Fri 02 Jun 2006 16:23:50 +0200
245 EOF
247 # Fix README
248 sed -i "s/Comments regarding the Package/After installing this plugin you may need to reload apache../g" debian/README
250 # Fix rules
251 cat <<EOF > debian/rules
252 #!/usr/bin/make -f
253 # -*- makefile -*-
254 # GOsa default plugin debhelper file.
255 # This file was originally written by Joey Hess and Craig Small.
256 # As a special exception, when this file is copied by dh-make into a
257 # dh-make output file, you may use that output file without restriction.
258 # This special exception was added by Craig Small in version 0.37 of dh-make.
260 # Uncomment this to turn on verbose mode.
261 #export DH_VERBOSE=1
263 configure: configure-stamp
264 configure-stamp:
265         dh_testdir
266         touch configure-stamp
268 patch: patch-stamp
269 patch-stamp:
270         dpatch apply-all
271         dpatch cat-all >patch-stamp
273 build: patch build-stamp
275 build-stamp: configure-stamp 
276         dh_testdir
278         touch $@
280 clean: clean-patched unpatch
281 clean-patched:
282         dh_testdir
283         dh_testroot
284         rm -f build-stamp configure-stamp
285         dh_clean 
287 unpatch:
288         dpatch deapply-all
289         rm -rf patch-stamp debian/patched
291 install: build
292         dh_testdir
293         dh_testroot
294         dh_clean -k 
295         dh_installdirs
297 # Build architecture-independent files here.
298 binary-indep: build install
299         dh_testdir
300         dh_testroot
301         dh_installchangelogs 
302         dh_installdocs
303         dh_installexamples
304         dh_install
305         dh_installman
306         dh_strip
307         dh_compress
308         dh_fixperms
309         dh_installdeb
310         dh_gencontrol
311         dh_md5sums
312         dh_builddeb
314 binary: binary-indep
315 .PHONY: build clean binary-indep binary install configure
316 EOF
318 # Adapt postinst/postrm
319 for file in postinst postrm; do
320 sed 's!#DEBHELPER#!#DEBHELPER#\
322 # Get apache versions running\
323 servers=""\
324 for srv in apache apache-ssl apache2; do\
325         if [ -x /usr/sbin/$srv ]; then\
326                 servers="$srv $servers"\
327         fi\
328 done\
330 # Update gosa\
331 /usr/sbin/update-gosa\
333 # Finally restart servers\
334 for server in $servers; do\
335         if [ -x /usr/sbin/invoke-rc.d ]; then\
336                 invoke-rc.d $server restart\
337         else\
338                 /etc/init.d/$server restart\
339         fi\
340 done\
342 !' debian/$file.ex > debian/$file
343 done
345 # Remove examples
346 rm debian/*ex debian/*EX >/dev/null 2>&1
348 echo "Done."