Code

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