wine-app-packager improvements: lintian tags, sanity checks
[wine-app-packager.git] / wine-app-packager
1 #!/bin/bash
2
3 # TODO:
4 # * LHM-Wine-Pakete beachten
5
6 set -e
7
8 #
9 # © 2009 Joachim Breitner <joachim.breitner@itomig.de>
10 #
11 # Version: @VERSION@
12 #
13 # Licensed under the EUPL, Version 1.0 or – as soon they
14 # will be approved by the European Commission - subsequent
15 # versions of the EUPL (the "Licence");
16 # you may not use this work except in compliance with the
17 # Licence.
18 # You may obtain a copy of the Licence at:
19
20 # http://ec.europa.eu/idabc/7330l5
21
22 # Unless required by applicable law or agreed to in
23 # writing, software distributed under the Licence is
24 # distributed on an "AS IS" BASIS,
25 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
26 # express or implied.
27 # See the Licence for the specific language governing
28 # permissions and limitations under the Licence.
29
30 function common_setup () {
31         if ! [ -d debian ]
32         then
33                 print "Please run command $0 $1 from within the source directory"
34                 exit 1;
35         fi
36
37         APPNAME="$(grep-dctrl -n -F Source -s Source '' < debian/control)"
38         DEBVERSION="$(dpkg-parsechangelog | grep-dctrl -n -s Version '')"
39         WINE_MASTER_DIR=~/".wine-$APPNAME-master"
40 }
41
42 if [ ! "$1" ]
43 then
44         cat <<'__END__'
45 wine-app-packager
46 =================
47
48 Version: @VERSION@
49
50 This script aids you in creation of Debian packages of Windows applications
51 that are meant to run under wine. It offers the following commands:
52
53 wine-app-packager init
54         creates a Debian source package directory. It will ask various pieces
55         of information. All the following commands will need to run within the
56         created directory.
57
58 wine-app-packager prepare
59         Creates a wine config directory in ~/.wine-<application>-master, based on
60         the current content of the package (if any).
61
62 wine-app-packager run <cmd>
63         Runs cmd in a way that WINEPREFIX is set correctly, i.e.
64         wine-app-packager run wine /tmp/install.exe
65         or
66         wine-app-packager run wine C:\\Applications\\DemoApplication\\DemoApplication.exe
67
68 wine-app-packager commit
69         Takes the changes you made in ~/.wine-<application>-master and puts them
70         back into the Debian source package. Ususally, this will be followed by
71         calls to debchange and debuilt to build the package
72         Removes ~/.wine-<application>-master afterwards.
73
74 wine-app-packager abort
75         Just removes ~/.wine-<application>-master, throwing away all changes.
76 __END__
77         exit 1;
78 fi
79
80 if [ "$1" = "init" ]
81 then
82         cat <<__END__
83 Please enter the name of the application (only lower letters, digits, dots and
84 dashes. It will be both the package name and the name of the wrapper executable.
85 Example: wsftp
86 __END__
87
88         read APPNAME
89         if [ -z "$APPNAME" -o -n "$(echo -n "$APPNAME" | tr -d a-z0-9.-)" ]
90         then
91                 echo "Invalid application name \"$APPNAME\"."
92                 exit 1
93         fi
94
95         cat <<__END__
96 Please enter the upstream version of the application, with the same conventions.
97 If there is no meaningful version, leave this field empty.
98 Example: 1.0
99 __END__
100
101         read APPVER
102         if [ -n "$(echo -n "$APPVER" | tr -d a-z0-9.-)" ]
103         then
104                 echo "Invalid application version \"$APPVER\"."
105                 exit 1
106         fi
107
108         if [ -z "$APPVER" ]
109         then
110                 DEBVER="1"
111         else
112                 DEBVER="$APPVER"
113         fi
114         DEBDIR="$APPNAME-$DEBVER"
115
116         if [ -e "$DEBDIR" ]
117         then
118                 cat <<__END__
119 The directory \"$DEBDIR\" does already exist. Please remove it if you want to
120 start from scratch.
121 __END__
122
123                 exit 1
124         fi
125         echo "Creating directory \"$DEBDIR\"."
126         mkdir "$DEBDIR"
127         mkdir "$DEBDIR"/debian
128         echo "Writing \"$DEBDIR/debian/control\""
129
130         if [ -n "$DEBFULLNAME" ]
131         then
132                 MAINT="$DEBFULLNAME <$DEBEMAIL>"
133         else
134                 cat <<__END__
135 WARNING: DEBFULLNAME and DEBEMAIL not set. Please adjust maintainer field
136 in debian/control and debian/changelog afterwards.
137 __END__
138                 MAINT="Someone <please-update@in.here>"
139         fi
140         cat >"$DEBDIR/debian/control" <<__END__
141 Source: $APPNAME
142 Maintainer: $MAINT
143 Build-Depends: debhelper (>= 6.0.7~)
144
145 Package: $APPNAME
146 Architecture: all
147 Depends: wine
148 Description: Application $APPNAME
149  This is a windows application packaged for Debian clients.
150 __END__
151         echo "Writing \"$DEBDIR/debian/compat\""
152         echo 5 > "$DEBDIR/debian/compat"
153         echo "Writing \"$DEBDIR/debian/rules\""
154         cat >"$DEBDIR/debian/rules" <<__END__
155 #!/usr/bin/make -f
156 build:
157         
158
159 clean:
160         dh_testdir
161         dh_testroot
162         dh_clean
163
164 install: build
165         dh_testdir
166         dh_testroot
167         dh_clean -k
168         dh_installdirs
169         
170         if grep -q "^EXE='c:.Programme.Please Adjust.start.exe'" $APPNAME ; \
171         then echo "Please update the EXE variable in the script $APPNAME"; \
172              exit 1; \
173         fi;
174         
175         # Add here commands to install the package into debian/<packagename>
176         #\$(MAKE) prefix=\`pwd\`/debian/\`dh_listpackages\`/usr install
177
178 binary-arch: install
179         # nothing to do here
180
181 binary-indep: install
182         dh_testdir
183         dh_testroot
184         dh_installchangelogs
185         dh_installdocs
186         dh_installexamples
187         dh_install
188         dh_installman
189         dh_lintian
190         dh_link
191         dh_strip
192         dh_compress
193         dh_fixperms
194         dh_installdeb
195         dh_shlibdeps
196         dh_gencontrol
197         dh_md5sums
198         dh_builddeb
199
200 binary: binary-indep binary-arch
201 .PHONY: clean binary-indep binary-arch binary install
202 __END__
203         chmod +x "$DEBDIR/debian/rules"
204         echo "Writing \"$DEBDIR/debian/lintian-overrides"
205         cat > "$DEBDIR/debian/lintian-overrides" <<__END__
206 dir-or-file-in-opt
207 binary-without-manpage
208 no-copyright-file
209 no-section-field
210 no-priority-field
211 extra-license-file
212 __END__
213         echo "Writing \"$DEBDIR/debian/source.lintian-overrides"
214         cat > "$DEBDIR/debian/source.lintian-overrides" <<__END__
215 no-standards-version-field
216 no-section-field-for-source
217 __END__
218         echo "Generating \"$DEBDIR/debian/install\""
219         cat >"$DEBDIR/debian/install" <<__END__
220 drive_c /opt/wineapps/wine-$APPNAME/
221 wine-config.tar.gz /opt/wineapps/wine-$APPNAME/
222 $APPNAME /usr/bin
223 __END__
224         echo "Generating \"$APPNAME\" (start wrapper. Please adjust variables at the top)"
225         cat >"$DEBDIR/$APPNAME" <<__END__
226 #!/bin/bash
227
228 # This variable need to be set:
229 EXE='c:\\Programme\\Please Adjust\\start.exe'
230
231 # These are already filled correctly
232 APPNAME="$APPNAME"
233 WINE_HOME="\$HOME/.wine-\$APPNAME"
234
235 set -e
236 if [ ! -d "\$WINE_HOME" ]
237 then
238         echo "\$APPNAME started for the first time, creating \$WINE_HOME"
239         mkdir -p "\$WINE_HOME"
240         tar --extract --gzip --file /opt/wineapps/wine-\$APPNAME/wine-config.tar.gz -C "\$WINE_HOME"
241         cp -r --symbolic-link /opt/wineapps/wine-\$APPNAME/drive_c/ "\$WINE_HOME"/drive_c
242 fi
243
244
245 export WINEPREFIX="\$WINE_HOME"
246 exec wine "\$EXE"
247 __END__
248         chmod +x "$DEBDIR/$APPNAME" 
249         echo "Generating \"$DEBDIR/debian/changelog\""
250         pushd "$DEBDIR"
251         debchange --create --package "$APPNAME" --newversion "$DEBVER" --distribution UNRELEASED "First release of $APPNAME"
252         popd
253         cat <<__END__
254 Done preparing the source package. You can review the contents of these files
255 now, or go ahead with wine-app-packager prepare, from within the created source
256 directory in $DEBDIR.
257 __END__
258
259 elif [ "$1" = "prepare" ]
260 then
261         common_setup
262
263         if [ -e "$WINE_MASTER_DIR" ]
264         then
265                 cat <<__END__
266 Directory $WINE_MASTER_DIR already exists. If it contains changes
267 that need to be preserved, please use $0 commit, otherwise remove
268 it before running $0 $1.
269 __END__
270                 exit 1
271         fi
272
273         if [ -d drive_c ]
274         then
275                 echo "Creating $WINE_MASTER_DIR"
276                 mkdir "$WINE_MASTER_DIR"
277                 echo "Extracting ./wine-config.tar.gz to $WINE_MASTER_DIR"
278                 tar --extract --gzip --file ./wine-config.tar.gz -C "$WINE_MASTER_DIR"
279                 echo "Copying ./drive_c to $WINE_MASTER_DIR/drive_c"
280                 rsync --recursive ./drive_c/ $WINE_MASTER_DIR/drive_c
281         else
282                 echo "Empty package, creating empty $WINE_MASTER_DIR"
283                 mkdir "$WINE_MASTER_DIR"
284         fi
285 elif [ "$1" = "run" ]
286 then
287         common_setup
288
289         if [ ! -d "$WINE_MASTER_DIR" ]
290         then
291                 cat <<__END__
292 Directory $WINE_MASTER_DIR does not exist. Please run $0 $1 prepare first.
293 __END__
294                 exit 1
295         fi
296
297         if [ -z "$2" ]
298         then
299                 cat <<__END__
300 You need to pass a program to be run, e.g. $0 $1 wine setup.exe
301 __END__
302                 exit 1
303         fi
304
305         export WINEPREFIX=$WINE_MASTER_DIR
306         shift
307         exec "$@"
308 elif [ "$1" = "commit" ]
309 then
310         common_setup
311
312         if [ ! -d "$WINE_MASTER_DIR" ]
313         then
314                 cat <<__END__
315 Directory $WINE_MASTER_DIR does not exist. Please run $0 $1 prepare first.
316 __END__
317                 exit 1
318         fi
319
320         echo "Copying over $WINE_MASTER_DIR in a tarfile, excluding drive_c"
321         tar --create --file ./wine-config.tar.gz --gzip --directory "$WINE_MASTER_DIR" --exclude drive_c .
322         echo "Copying over drive_c, excluding Profiles"
323         rsync --recursive --delete --exclude windows/profiles --exclude windows/temp "$WINE_MASTER_DIR/drive_c/" drive_c
324
325         echo "Removing $WINE_MASTER_DIR"
326         rm -rf "$WINE_MASTER_DIR"
327         cat <<__END__
328 Change are propagated to the Debian source directory. To build the package,
329 increase the version number with "debchange -i" and build it with "dpkg-buildpackage -uc -us".
330 __END__
331
332 elif [ "$1" = "abort" ]
333 then
334         common_setup
335
336         if [ ! -d "$WINE_MASTER_DIR" ]
337         then
338                 cat <<__END__
339 Directory $WINE_MASTER_DIR does not exist, nothing to abort.
340 __END__
341                 exit 1
342         fi
343
344         echo "Removing $WINE_MASTER_DIR"
345         rm -rf "$WINE_MASTER_DIR"
346 else
347         echo "Unknown command $1. Please run $0 without commands for a usage summary."
348         exit 1
349 fi