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 BUILD_PATH=${DEST}gosa-plugin-${PL_NAME}-${PL_VERSION}
79 if [ -d "$BUILD_PATH" ]; then
80 echo "Error: build path $BUILD_PATH already exists" >&2
81 exit 2
82 fi
83 cp -a "$PL_NAME" "$BUILD_PATH"
85 elif [ -f "$file" ]; then
87 # It's a compressed user contributed file
88 TMPDIR="/tmp/dh-make-gosa-$PPID"
89 if [ -d "/tmp/dh-make-gosa-$PPID" ]; then
90 echo "Error: directory $TMPDIR exists" >&2
91 exit 4
92 fi
94 # Untar
95 mkdir -p "$TMPDIR"
96 tar --extract --directory "$TMPDIR" -fz "$file" &> /dev/null
97 if [ $? -ne 0 ]; then
98 echo "Error: cannot extract plugin file - invalid file format" >&2
99 exit 5
100 fi
102 # It's a local directory
103 load_dsc TMPDIR/*/plugin.dsc
105 # Setup build environment
106 BUILD_PATH=${DEST}gosa-plugin-${PL_NAME}-${PL_VERSION}
107 mv "$TMPDIR/*" "$BUILD_PATH"
109 else
111 echo "Error: cannot find plugin $file" >&2
112 exit 5
114 fi
117 PL_DEPENDS=$(echo $PL_DEPENDS$DEPENDS | sed 's/,\s*$//')
118 echo "Debian package summary ========================================"
119 echo "Plugin: $PL_NAME"
120 echo "Version: $PL_VERSION"
121 echo "Description: $PL_DESCRIPTION"
122 echo "Depends: $PL_DEPENDS"
123 echo "Author name: $PL_AUTHOR"
124 echo "Author email: $PL_MAIL"
125 echo
126 read -s -n 1 -p "Do you want to continue? (y/n)" ans; echo
127 [ "$ans" != "y" ] && exit 0
129 pushd . &> /dev/null
131 cd "$BUILD_PATH"
133 # Use gosa-plugin skelleton
134 echo "Calling dh_make..."
135 echo | dh_make -e "$PL_MAIL" -c gpl -s -n -f gosa-plugin-${PL_NAME}-${PL_VERSION}.tar.gz &> /dev/null
136 if [ $? -ne 0 ]; then
137 echo "Failed to call dh_make - aborting!"
138 exit 1
139 fi
141 echo "Apdapting debian descriptive files..."
143 # Generate install file
144 for dir in admin personal addons; do
145 [ -d $dir ] && echo -e "$dir\t\t\t/usr/share/gosa/plugins" > debian/install
146 done
147 for dir in help/*; do
148 echo -e "$dir\t\t\t/usr/share/gosa/plugins/$PL_NAME" >> debian/install
149 done
150 for dir in $(ls -1 locale | grep -v "^en$" | grep -v "^messages.po$"); do
151 echo -e "locale/$dir\t\t\t/usr/share/gosa/locale/plugins/$PL_NAME" >> debian/install
152 done
154 # Generate dirs
155 echo "usr/share/gosa" > debian/dirs
157 # If we've a contrib directory include it to the docs
158 if [ -d contrib ]; then
159 echo "contrib /usr/share/doc/gosa-plugin-$PL_NAME" >> debian/install
160 fi
161 if [ -d html ]; then
162 for i in html/*; do
163 echo "$i /usr/share/gosa/html/plugins/$PL_NAME" >> debian/install
164 done
165 fi
167 # Adapt control
168 sed -i 's/^Section: unknown/Section: web/g' debian/control
169 sed -i 's/^Architecture: any/Architecture: all/g' debian/control
170 sed -i 's/^Depends: .*$/Depends: gosa/g' debian/control
171 sed -i "s/^Description: .*$/Description: $PL_NAME plugin for GOsa/g" debian/control
172 sed -i "s/^ <.*$/ $PL_DESCRIPTION\
173 .\
174 GOsa is a combination of system-administrator and end-user web\
175 interface, designed to handle LDAP based setups.\
176 /g" debian/control
178 # Adapt README.debian
179 cat <<EOF > debian/README.Debian
180 README.Debian for GOsa $PL_NAME plugin $PL_VERSION
181 -------------------------------------------
183 Please read the main GOsa README.Debian file for more information.
185 ----
186 $PL_AUTHOR <$PL_MAIL> Fri 02 Jun 2006 16:23:50 +0200
187 EOF
189 # Fix rules
190 cat <<EOF > debian/rules
191 #!/usr/bin/make -f
192 # -*- makefile -*-
193 # GOsa default plugin debhelper file.
194 # This file was originally written by Joey Hess and Craig Small.
195 # As a special exception, when this file is copied by dh-make into a
196 # dh-make output file, you may use that output file without restriction.
197 # This special exception was added by Craig Small in version 0.37 of dh-make.
199 # Uncomment this to turn on verbose mode.
200 #export DH_VERBOSE=1
202 configure: configure-stamp
203 configure-stamp:
204 dh_testdir
205 touch configure-stamp
208 build: build-stamp
210 build-stamp: configure-stamp
211 dh_testdir
213 touch $@
215 clean:
216 dh_testdir
217 dh_testroot
218 rm -f build-stamp configure-stamp
219 dh_clean
221 install: build
222 dh_testdir
223 dh_testroot
224 dh_clean -k
225 dh_installdirs
227 # Build architecture-independent files here.
228 binary-indep: build install
229 dh_testdir
230 dh_testroot
231 dh_installchangelogs
232 dh_installdocs
233 dh_installexamples
234 dh_install
235 dh_installman
236 dh_link
237 dh_strip
238 dh_compress
239 dh_fixperms
240 dh_installdeb
241 dh_shlibdeps
242 dh_gencontrol
243 dh_md5sums
244 dh_builddeb
246 binary: binary-indep
247 .PHONY: build clean binary-indep binary install configure
248 EOF
250 # Adapt postinst/postrm
251 for file in postinst postrm; do
252 sed 's!#DEBHELPER#!#DEBHELPER#\
253 \
254 # Get apache versions running\
255 servers=""\
256 for srv in apache apache-ssl apache2; do\
257 if [ -x /usr/sbin/$srv ]; then\
258 servers="$srv $servers"\
259 fi\
260 done\
261 \
262 # Update gosa\
263 /usr/sbin/update-gosa\
264 \
265 # Finally restart servers\
266 for server in $servers; do\
267 if [ -x /usr/sbin/invoke-rc.d ]; then\
268 invoke-rc.d $server restart\
269 else\
270 /etc/init.d/$server restart\
271 fi\
272 done\
273 \
274 !' debian/$file.ex > debian/$file
275 done
277 # Remove examples
278 rm debian/*ex debian/*EX &> /dev/null
280 popd &> /dev/null
282 echo "Done."