Code

Updated to the gosa package builder
[gosa.git] / gosa-core / dh-make-gosa
1 #!/bin/bash
3 usage() {
4   echo "Usage: ${0##*/} [--download] [--section section name] [-b|--branch branch] [-e|--email mail] [--depends] plugin-dir|plugin.tar.gz" >&2
5   exit 1
6 }
9 load_dsc() {
10   if [ -r "$1" ]; then
11     PL_NAME=$(sed -n 's/"//g;s/^name\s*=\s*\(.*\)$/\1/p' "$1")
12     PL_VERSION=$(sed -n 's/"//g;s/^version\s*=\s*\(.*\)$/\1/p' "$1")
13     TDEPENDS=$(sed -n 's/"//g;s/^depends\s*=\s*\(.*\)$/\1/p' "$1")
14     for dep in $TDEPENDS; do
15       PL_DEPENDS="gosa-plugin-$dep, $PL_DEPENDS"
16     done
17     TCONFLICTS=$(sed -n 's/"//g;s/^conflicts\s*=\s*\(.*\)$/\1/p' "$1")
18     for dep in $TCONFLICTS; do
19       PL_CONFLICTS="gosa-plugin-$dep, $PL_CONFLICTS"
20     done
21     PL_DESCRIPTION=$(sed -n 's/"//g;s/^description\s*=\s*\(.*\)$/\1/p' "$1")
22     PL_AUTHOR=$(sed -n 's/"//g;s/^author\s*=\s*\([^<]*\).*$/\1/p' "$1")
23     PL_MAIL=$(sed -n 's/"//g;s/^author\s*=[^<].*<\([^>]*\).*$/\1/p' "$1")
24   else
25     echo "Error: cannot find description file" >&2
26     exit 1
27   fi
28 }
31 TEMP=`getopt -o e:r: --long download,release:,email:,depends:,section: -n 'dh-make-gosa' -- "$@"`
32 if [ $? != 0 ] ; then
33   echo "Error: cannot get command line information" >&2
34   exit 1
35 fi
37 eval set -- "$TEMP"
39 # Load command  line vars
40 RELEASE=trunk
41 DOWNLOAD=
42 DEPENDS=
43 SECTION=web
44 DEST=
45 while true; do
46   case "$1" in
47     -e|--email) DEBMAIL=$2
48                 shift 2
49                 ;;
50     -r|--release)
51                 if [ "$2" != "trunk" ]; then
52                   RELEASE=tags/$2
53                 fi
54                 shift 2
55                 ;;
56     --depends)  DEPENDS="$2"
57                 shift 2
58                 ;;
59     --section)  SECTION="$2"
60                 shift 2
61                 ;;
62     --dest)     DEST=$2/
63                 shift 2
64                 ;;
65     --download) DOWNLOAD=yes
66                 shift 1
67                 ;;
68     --)         shift
69                 break
70                 ;;
71     *)          usage
72                 ;;
73   esac
74 done
76 [ $# -ne 1 ] && usage
77 file=$*
79 # Three possiblities
80 if [ -d "$file" ]; then
82   # It's a local directory
83   load_dsc $file/plugin.dsc
85   # Setup build environment
86   if [ "$OVERRIDE_VERSION" ]; then
87           BUILD_PATH=${DEST}gosa-plugin-${PL_NAME}-${OVERRIDE_VERSION}
88   else
89           BUILD_PATH=${DEST}gosa-plugin-${PL_NAME}-${PL_VERSION}
90   fi
91   if [ -d "$BUILD_PATH" ]; then
92     echo "Error: build path $BUILD_PATH already exists" >&2
93     exit 2
94   fi
95   cp -a "$PL_NAME" "$BUILD_PATH"
97 elif [ -f "$file" ]; then
99   # It's a compressed user contributed file
100   TMPDIR="/tmp/dh-make-gosa-$PPID"
101   if [ -d "/tmp/dh-make-gosa-$PPID"  ]; then
102     echo "Error: directory $TMPDIR exists" >&2
103     exit 4
104   fi
106   # Untar
107   mkdir -p "$TMPDIR"
108   tar --extract --directory "$TMPDIR" -fz "$file" &> /dev/null
109   if [ $? -ne 0 ]; then
110     echo "Error: cannot extract plugin file - invalid file format" >&2
111     exit 5
112   fi
114   # It's a local directory
115   load_dsc TMPDIR/*/plugin.dsc
117   # Setup build environment
118   BUILD_PATH=${DEST}gosa-plugin-${PL_NAME}-${PL_VERSION}
119   mv "$TMPDIR/*" "$BUILD_PATH"
121 else
123   echo "Error: cannot find plugin $file" >&2
124   exit 5
126 fi
129 PL_DEPENDS=$(echo $PL_DEPENDS$DEPENDS | sed 's/,\s*$//')
130 echo "Debian package summary ========================================"
131 echo "Plugin:       $PL_NAME"
132 echo "Version:      $PL_VERSION"
133 echo "Description:  $PL_DESCRIPTION"
134 echo "Depends:      $PL_DEPENDS"
135 echo "Conflicts:    $PL_CONFLICTS"
136 echo "Author name:  $PL_AUTHOR"
137 echo "Author email: $PL_MAIL"
138 echo
139 read -s -n 1 -p "Do you want to continue? (y/n)" ans; echo
140 [ "$ans" != "y" ] && exit 0
142 pushd . &> /dev/null
144 cd "$BUILD_PATH"
146 # Use gosa-plugin skelleton
147 echo "Calling dh_make..."
148 echo | dh_make -e "$PL_MAIL" -c gpl -s -n -f gosa-plugin-${PL_NAME}-${PL_VERSION}.tar.gz &> /dev/null
149 if [ $? -ne 0 ]; then
150         echo "Failed to call dh_make - aborting!"
151         exit 1
152 fi
154 echo "Apdapting debian descriptive files..."
156 # Generate install file
157 for dir in admin personal addons gofax gofon generic; do
158         [ -d $dir ] && echo -e "$dir\t\t\t/usr/share/gosa/plugins" >> debian/install
159 done
160 for dir in help/*; do
161         echo -e "$dir\t\t\t/usr/share/gosa/doc/plugins/$PL_NAME" >> debian/install
162 done
163 for dir in $(ls -1 locale | grep -v "^en$" | grep -v "^messages.po$"); do
164         echo -e "locale/$dir\t\t\t/usr/share/gosa/locale/plugins/$PL_NAME" >> debian/install
165 done
167 # Generate dirs
168 echo "usr/share/gosa" > debian/dirs
170 # If we've a contrib directory include it to the docs
171 if [ -d contrib ]; then
172         echo "contrib /usr/share/doc/gosa-plugin-$PL_NAME" >> debian/install
173 fi
174 if [ -d html ]; then
175         for i in html/*; do
176                 echo "$i /usr/share/gosa/html/plugins/$PL_NAME" >> debian/install
177         done
178 fi
180 # Fix copyright
181 sed -i '/^#/d;/^.*likewise for another author.*$/d' debian/copyright
182 year=$(date +%Y)
183 sed -i "s/.Copyright (C) YYYY Name OfAuthor./Copyright (C) $year $PL_AUTHOR/g" debian/copyright
184 sed -i "s/.url:\/\/example.com./http:\/\/www.gosa-project.org/g" debian/copyright
185 sed -i "/.put author's name and email here.\
186 /d" debian/copyright
187 sed -i '/^Upstream/,/^$/d' debian/copyright
189 # Adapt control
190 sed -i "s#^Section: unknown#Section: $SECTION#g" debian/control
191 sed -i 's/^Architecture: any/Architecture: all/g' debian/control
192 if [ "$PL_DEPENDS" ]; then
193         sed -i "s/^Depends: .*$/Depends: gosa, $PL_DEPENDS/g" debian/control
194 else
195         sed -i 's/^Depends: .*$/Depends: gosa/g' debian/control
196 fi
197 if [ "$PL_CONFLICTS" ]; then
198         sed "11Conflicts: $PL_CONFLICTS" debian/control
199 fi
200 sed -i 's/^\(Build-Depends: .*\)$/\1, dpatch/g' debian/control
201 sed -i "s/^Description: .*$/Description: $PL_NAME plugin for GOsa/g" debian/control
202 sed -i "s/^ <.*$/ %DESCRIPTION%/g" debian/control
203 dsc=$(tempfile)
205 echo $PL_DESCRIPTION 
206 cat <<EOF
208 GOsa is a combination of system-administrator and end-user web
209 interface, designed to handle LDAP based setups.
210 EOF
211 }| fmt -suw79 | sed 's/^/ /g' > $dsc
212 sed -i "/%DESCRIPTION%/r $dsc" debian/control
213 sed -i "/%DESCRIPTION%/d" debian/control
214 rm $dsc
216 # Create patch directory
217 [ ! -d debian/patches ] && mkdir debian/patches
219 # Adapt README.debian
220 cat <<EOF > debian/README.Debian
221 README.Debian for GOsa $PL_NAME plugin $PL_VERSION
222 -------------------------------------------
224 Please read the main GOsa README.Debian file for more information.
226 ----
227 $PL_AUTHOR <$PL_MAIL>  Fri 02 Jun 2006 16:23:50 +0200
228 EOF
230 # Fix README
231 sed -i "s/Comments regarding the Package/After installing this plugin you may need to reload apache../g" debian/README
233 # Fix rules
234 cat <<EOF > debian/rules
235 #!/usr/bin/make -f
236 # -*- makefile -*-
237 # GOsa default plugin debhelper file.
238 # This file was originally written by Joey Hess and Craig Small.
239 # As a special exception, when this file is copied by dh-make into a
240 # dh-make output file, you may use that output file without restriction.
241 # This special exception was added by Craig Small in version 0.37 of dh-make.
243 # Uncomment this to turn on verbose mode.
244 #export DH_VERBOSE=1
246 configure: configure-stamp
247 configure-stamp:
248         dh_testdir
249         touch configure-stamp
251 patch: patch-stamp
252 patch-stamp:
253         dpatch apply-all
254         dpatch cat-all >patch-stamp
256 build: patch build-stamp
258 build-stamp: configure-stamp 
259         dh_testdir
261         touch $@
263 clean: clean-patched unpatch
264 clean-patched:
265         dh_testdir
266         dh_testroot
267         rm -f build-stamp configure-stamp
268         dh_clean 
270 unpatch:
271         dpatch deapply-all
272         rm -rf patch-stamp debian/patched
274 install: build
275         dh_testdir
276         dh_testroot
277         dh_clean -k 
278         dh_installdirs
280 # Build architecture-independent files here.
281 binary-indep: build install
282         dh_testdir
283         dh_testroot
284         dh_installchangelogs 
285         dh_installdocs
286         dh_installexamples
287         dh_install
288         dh_installman
289         dh_strip
290         dh_compress
291         dh_fixperms
292         dh_installdeb
293         dh_gencontrol
294         dh_md5sums
295         dh_builddeb
297 binary: binary-indep
298 .PHONY: build clean binary-indep binary install configure
299 EOF
301 # Adapt postinst/postrm
302 for file in postinst postrm; do
303 sed 's!#DEBHELPER#!#DEBHELPER#\
305 # Get apache versions running\
306 servers=""\
307 for srv in apache apache-ssl apache2; do\
308         if [ -x /usr/sbin/$srv ]; then\
309                 servers="$srv $servers"\
310         fi\
311 done\
313 # Update gosa\
314 /usr/sbin/update-gosa\
316 # Finally restart servers\
317 for server in $servers; do\
318         if [ -x /usr/sbin/invoke-rc.d ]; then\
319                 invoke-rc.d $server restart\
320         else\
321                 /etc/init.d/$server restart\
322         fi\
323 done\
325 !' debian/$file.ex > debian/$file
326 done
328 # Remove examples
329 rm debian/*ex debian/*EX &> /dev/null
331 popd &> /dev/null
333 echo "Done."