Code

Removed very important empty line to README in order to test svn account.
[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##*/} [--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)
226 echo $PL_DESCRIPTION 
227 cat <<EOF
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 # Create patch directory
238 [ ! -d debian/patches ] && mkdir debian/patches
240 # Adapt README.debian
241 cat <<EOF > debian/README.Debian
242 README.Debian for GOsa $PL_NAME plugin $PL_VERSION
243 -------------------------------------------
245 Please read the main GOsa README.Debian file for more information.
247 ----
248 $PL_AUTHOR <$PL_MAIL>  Fri 02 Jun 2006 16:23:50 +0200
249 EOF
251 # Fix README
252 sed -i "s/Comments regarding the Package/After installing this plugin you may need to reload apache../g" debian/README
254 # Fix rules
255 cat <<EOF > debian/rules
256 #!/usr/bin/make -f
257 # -*- makefile -*-
258 # GOsa default plugin debhelper file.
259 # This file was originally written by Joey Hess and Craig Small.
260 # As a special exception, when this file is copied by dh-make into a
261 # dh-make output file, you may use that output file without restriction.
262 # This special exception was added by Craig Small in version 0.37 of dh-make.
264 # Uncomment this to turn on verbose mode.
265 #export DH_VERBOSE=1
267 configure: configure-stamp
268 configure-stamp:
269         dh_testdir
270         touch configure-stamp
272 patch: patch-stamp
273 patch-stamp:
274         dpatch apply-all
275         dpatch cat-all >patch-stamp
277 build: patch build-stamp
279 build-stamp: configure-stamp 
280         dh_testdir
282         touch $@
284 clean: clean-patched unpatch
285 clean-patched:
286         dh_testdir
287         dh_testroot
288         rm -f build-stamp configure-stamp
289         dh_clean 
291 unpatch:
292         dpatch deapply-all
293         rm -rf patch-stamp debian/patched
295 install: build
296         dh_testdir
297         dh_testroot
298         dh_clean -k 
299         dh_installdirs
301 # Build architecture-independent files here.
302 binary-indep: build install
303         dh_testdir
304         dh_testroot
305         dh_installchangelogs 
306         dh_installdocs
307         dh_installexamples
308         dh_install
309         dh_installman
310         dh_strip
311         dh_compress
312         dh_fixperms
313         dh_installdeb
314         dh_gencontrol
315         dh_md5sums
316         dh_builddeb
318 binary: binary-indep
319 .PHONY: build clean binary-indep binary install configure
320 EOF
322 # Adapt postinst/postrm
323 for file in postinst postrm; do
324 sed 's!#DEBHELPER#!#DEBHELPER#\
326 # Get apache versions running\
327 servers=""\
328 for srv in apache apache-ssl apache2; do\
329         if [ -x /usr/sbin/$srv ]; then\
330                 servers="$srv $servers"\
331         fi\
332 done\
334 # Update gosa\
335 /usr/sbin/update-gosa\
337 # Finally restart servers\
338 for server in $servers; do\
339         if [ -x /usr/sbin/invoke-rc.d ]; then\
340                 invoke-rc.d $server restart\
341         else\
342                 /etc/init.d/$server restart\
343         fi\
344 done\
346 !' debian/$file.ex > debian/$file
347 done
349 # Remove examples
350 rm debian/*ex debian/*EX >/dev/null 2>&1
352 echo "Done."