Code

Updated department listing in class_listing.inc
[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)/ (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 "11Conflicts: $PL_CONFLICTS" debian/control
246 fi
247 sed -i 's/^\(Build-Depends: .*\)$/\1, dpatch/g' debian/control
248 sed -i "s/^Description: .*$/Description: $PL_NAME plugin for GOsa/g" debian/control
249 sed -i "s/^ <.*$/ %DESCRIPTION%/g" debian/control
250 dsc=$(tempfile)
252 echo $PL_DESCRIPTION 
253 cat <<EOF
255 GOsa is a combination of system-administrator and end-user web
256 interface, designed to handle LDAP based setups.
257 EOF
258 }| fmt -suw79 | sed 's/^/ /g' > $dsc
259 sed -i "/%DESCRIPTION%/r $dsc" debian/control
260 sed -i "/%DESCRIPTION%/d" debian/control
261 rm $dsc
263 # Do we need to generate another package for schema files?
264 if ls contrib/*schema &> /dev/null; then
265         echo etc/ldap/schema/gosa > debian/gosa-plugin-${PL_NAME}-schema.dirs
266         ls -1 contrib/*schema | sed 's%$% /etc/ldap/schema/gosa%g' > debian/gosa-plugin-${PL_NAME}-schema.install
268         cat <<-EOF >> debian/control
269         
270         Package: gosa-plugin-${PL_NAME}-schema
271         Architecture: all
272         Recommends: slapd
273         Description: LDAP schema for GOsa plugin ${PL_NAME}
274          This package includes the LDAP schema needed by the GOsa
275          ${PL_NAME} plugin.
276          .
277          GOsa is a combination of system-administrator and end-user web
278          interface, designed to handle LDAP based setups.
279         EOF
280 fi
282 # Create patch directory
283 [ ! -d debian/patches ] && mkdir debian/patches
285 # Adapt README.debian
286 cat <<EOF > debian/README.Debian
287 README.Debian for GOsa $PL_NAME plugin $PL_VERSION
288 -------------------------------------------
290 Please read the main GOsa README.Debian file for more information.
292 ----
293 $PL_AUTHOR <$PL_MAIL>  Fri 02 Jun 2006 16:23:50 +0200
294 EOF
296 # Fix README
297 sed -i "s/Comments regarding the Package/After installing this plugin you may need to reload apache../g" debian/README
299 # Fix rules
300 cat <<EOF > debian/rules
301 #!/usr/bin/make -f
302 # -*- makefile -*-
303 # GOsa default plugin debhelper file.
304 # This file was originally written by Joey Hess and Craig Small.
305 # As a special exception, when this file is copied by dh-make into a
306 # dh-make output file, you may use that output file without restriction.
307 # This special exception was added by Craig Small in version 0.37 of dh-make.
309 # Uncomment this to turn on verbose mode.
310 #export DH_VERBOSE=1
312 configure: configure-stamp
313 configure-stamp:
314         dh_testdir
315         touch configure-stamp
317 patch: patch-stamp
318 patch-stamp:
319         dpatch apply-all
320         dpatch cat-all >patch-stamp
322 build: patch build-stamp
324 build-stamp: configure-stamp 
325         dh_testdir
327         touch $@
329 clean: clean-patched unpatch
330 clean-patched:
331         dh_testdir
332         dh_testroot
333         rm -f build-stamp configure-stamp
334         dh_clean 
336 unpatch:
337         dpatch deapply-all
338         rm -rf patch-stamp debian/patched
340 install: build
341         dh_testdir
342         dh_testroot
343         dh_clean -k 
344         dh_installdirs
346 # Build architecture-independent files here.
347 binary-indep: build install
348         dh_testdir
349         dh_testroot
350         dh_installchangelogs 
351         dh_installdocs
352         dh_installexamples
353         dh_install
354         dh_installman
355         dh_strip
356         dh_compress
357         dh_fixperms
358         dh_installdeb
359         dh_gencontrol
360         dh_md5sums
361         dh_builddeb
363 binary: binary-indep
365 binary-arch:
366 .PHONY: build clean binary-indep binary install configure
367 EOF
369 # Adapt postinst/postrm
370 for file in postinst postrm; do
371 sed 's!#DEBHELPER#!#DEBHELPER#\
373 # Get apache versions running\
374 servers=""\
375 for srv in apache apache-ssl apache2; do\
376         if [ -x /usr/sbin/$srv ]; then\
377                 servers="$srv $servers"\
378         fi\
379 done\
381 # Update gosa\
382 update-gosa\
384 # Finally restart servers\
385 for server in $servers; do\
386         if [ -x /usr/sbin/invoke-rc.d ]; then\
387                 invoke-rc.d $server restart\
388         else\
389                 /etc/init.d/$server restart\
390         fi\
391 done\
393 !' debian/$file.ex > debian/$file
394 done
396 # Remove examples
397 rm debian/*ex debian/*EX >/dev/null 2>&1
399 # Remove empty docs
400 remove_empty_docs
402 echo "Done."