Code

Updated sudo
[gosa.git] / gosa-core / dh-make-gosa
1 #!/bin/sh
3 usage() {
4 #       file plugin.tgz
5 #       dir plugin
6 #       --download
7 #       --branch | -b
8 #       --email | -e EMAIL
9 #       --depends DEPENDS
11   echo "Usage: ${0##*/}" >&2
12   exit 1
13 }
16 load_dsc() {
17   if [[ -r "$1" ]]; then
18     PL_NAME=$(sed -n 's/"//g;s/^name\s*=\s*\(.*\)$/\1/p' "$1")
19     PL_VERSION=$(sed -n 's/"//g;s/^version\s*=\s*\(.*\)$/\1/p' "$1")
20     TDEPENDS=$(sed -n 's/"//g;s/^depends\s*=\s*\(.*\)$/\1/p' "$1")
21     for dep in $TDEPENDS; do
22       PL_DEPENDS="gosa-plugin-$dep, $PL_DEPENDS"
23     done
24     PL_DESCRIPTION=$(sed -n 's/"//g;s/^description\s*=\s*\(.*\)$/\1/p' "$1")
25     PL_AUTHOR=$(sed -n 's/"//g;s/^author\s*=\s*\([^<]*\).*$/\1/p' "$1")
26     PL_MAIL=$(sed -n 's/"//g;s/^author\s*=[^<].*<\([^>]*\).*$/\1/p' "$1")
27   else
28     echo "Error: cannot find description file" >&2
29     exit 1
30   fi
31 }
34 TEMP=`getopt -o e:r: --long download,release:,email:,depends: -n 'dh-make-gosa' -- "$@"`
35 if [[ $? != 0 ]] ; then
36   echo "Error: cannot get command line information" >&2
37   exit 1
38 fi
40 eval set -- "$TEMP"
42 # Load command  line vars
43 RELEASE=trunk
44 DOWNLOAD=
45 DEPENDS=
46 DEST=
47 while true; do
48   case "$1" in
49     -e|--email) DEBMAIL=$2
50                 shift 2
51                 ;;
52     -r|--release)
53                 if [[ "$2" != "trunk" ]]; then
54                   RELEASE=tags/$2
55                 fi
56                 shift 2
57                 ;;
58     --depends)  DEPENDS="$2"
59                 shift 2
60                 ;;
61     --dest)     DEST=$2/
62                 shift 2
63                 ;;
64     --download) DOWNLOAD=yes
65                 shift 1
66                 ;;
67     --)         shift
68                 break
69                 ;;
70     *)          usage
71                 ;;
72   esac
73 done
75 [[ $# -ne 1 ]] && usage
76 file=$*
78 # Three possiblities
79 if [[ -d "$file" ]]; then
81   # It's a local directory
82   load_dsc $file/plugin.dsc
84   # Setup build environment
85   BUILD_PATH=${DEST}gosa-plugin-${PL_NAME}-${PL_VERSION}
86   if [[ -d "$BUILD_PATH" ]]; then
87     echo "Error: build path $BUILD_PATH already exists" >&2
88     exit 2
89   fi
90   cp -a "$PL_NAME" "$BUILD_PATH"
92 elif [[ -f "$file" ]]; then
94   # It's a compressed user contributed file
95   TMPDIR="/tmp/dh-make-gosa-$PPID"
96   if [[ -d "/tmp/dh-make-gosa-$PPID"  ]]; then
97     echo "Error: directory $TMPDIR exists" >&2
98     exit 4
99   fi
101   # Untar
102   mkdir -p "$TMPDIR"
103   tar --extract --directory "$TMPDIR" -fz "$file" &> /dev/null
104   if [[ $? -ne 0 ]]; then
105     echo "Error: cannot extract plugin file - invalid file format" >&2
106     exit 5
107   fi
109   # It's a local directory
110   load_dsc TMPDIR/*/plugin.dsc
112   # Setup build environment
113   BUILD_PATH=${DEST}gosa-plugin-${PL_NAME}-${PL_VERSION}
114   mv "$TMPDIR/*" "$BUILD_PATH"
116 else
118   echo "Error: cannot find plugin $file" >&2
119   exit 5
121 fi
124 PL_DEPENDS=$(echo $PL_DEPENDS$DEPENDS | sed 's/,\s*$//')
125 echo "Debian package summary ========================================"
126 echo "Plugin:       $PL_NAME"
127 echo "Version:      $PL_VERSION"
128 echo "Description:  $PL_DESCRIPTION"
129 echo "Depends:      $PL_DEPENDS"
130 echo "Author name:  $PL_AUTHOR"
131 echo "Author email: $PL_MAIL"
132 echo
133 read -s -n 1 -p "Do you want to continue? (y/n)" ans; echo
134 [[ "$ans" != "y" ]] && exit 0
136 pushd . &> /dev/null
138 cd "$BUILD_PATH"
140 # Use gosa-plugin skelleton
141 echo "Calling dh_make..."
142 echo | dh_make -e "$PL_MAIL" -c gpl -s -n -f gosa-plugin-${PL_NAME}-${PL_VERSION}.tar.gz &> /dev/null
143 if [[ $? -ne 0 ]]; then
144         echo "Failed to call dh_make - aborting!"
145         exit 1
146 fi
148 echo "Apdapting debian descriptive files..."
149 # Generate install file
150 for dir in admin personal addons; do
151         [[ -d $dir ]] && echo -e "$dir\t\t\t/usr/share/gosa/plugins" > debian/install
152 done
153 for dir in help/*; do
154         echo -e "$dir\t\t\t/usr/share/gosa/plugins/$PL_NAME" >> debian/install
155 done
156 for dir in $(ls -1 locale | grep -v "^en$" | grep -v "^messages.po$"); do
157         echo -e "locale/$dir\t\t\t/usr/share/gosa/locale/plugins/$PL_NAME" >> debian/install
158 done
160 # Generate dirs
161 echo "usr/share/gosa" > debian/dirs
163 # Adapt control
164 sed -i 's/^Section: unknown/Section: web/g' debian/control
165 sed -i 's/^Depends: .*$/Depends: gosa/g' debian/control
166 sed -i "s/^Description: .*$/Description: $PL_NAME plugin for GOsa/g" debian/control
167 sed -i "s/^ <.*$/ $PL_DESCRIPTION\
168  .\
169  GOsa is a combination of system-administrator and end-user web\
170  interface, designed to handle LDAP based setups.\
171 /g" debian/control
173 # Adapt README.debian
174 cat <<EOF > debian/README.Debian
175 README.Debian for GOsa $PL_NAME plugin $PL_VERSION
176 -------------------------------------------
178 Please read the main GOsa README.Debian file for more information.
180 ----
181 $PL_AUTHOR <$PL_MAIL>  Fri 02 Jun 2006 16:23:50 +0200
182 EOF
184 # Fix rules
185 sed -i "/MAKE/d" debian/rules
186 sed -i "s/#.*dh_install$/\tdh_install/" debian/rules
188 # Adapt postinst/postrm
189 for file in postinst postrm; do
190 sed 's!#DEBHELPER#!#DEBHELPER#\
192 # Get apache versions running\
193 servers=""\
194 for srv in apache apache-ssl apache2; do\
195         if [[ -x /usr/sbin/$srv ]]; then\
196                 servers="$srv $servers"\
197         fi\
198 done\
200 # Update gosa\
201 /usr/sbin/update-gosa\
203 # Finally restart servers\
204 for server in $servers; do\
205         if [[ -x /usr/sbin/invoke-rc.d ]]; then\
206                 invoke-rc.d $server restart\
207         else\
208                 /etc/init.d/$server restart\
209         fi\
210 done\
212 !' debian/$file.ex > debian/$file
213 done
215 # Remove examples
216 rm debian/*ex debian/*EX &> /dev/null
218 popd &> /dev/null
220 echo "Done."