Code

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