Code

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