Reference to manpage
[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 debuild 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
77 A more complete description can be found in the manpage for wine-app-packager.
78 __END__
79         exit 1;
80 fi
81
82 if [ "$1" = "init" ]
83 then
84         cat <<__END__
85 Please enter the name of the application (only lower letters, digits, dots and
86 dashes. It will be both the package name and the name of the wrapper executable.
87 Example: wsftp
88 __END__
89
90         read APPNAME
91         if [ -z "$APPNAME" -o -n "$(echo -n "$APPNAME" | tr -d a-z0-9.-)" ]
92         then
93                 echo "Invalid application name \"$APPNAME\"."
94                 exit 1
95         fi
96
97         cat <<__END__
98 Please enter the upstream version of the application, with the same conventions.
99 If there is no meaningful version, leave this field empty.
100 Example: 1.0
101 __END__
102
103         read APPVER
104         if [ -n "$(echo -n "$APPVER" | tr -d a-z0-9.-)" ]
105         then
106                 echo "Invalid application version \"$APPVER\"."
107                 exit 1
108         fi
109
110         if [ -z "$APPVER" ]
111         then
112                 DEBVER="1"
113         else
114                 DEBVER="$APPVER"
115         fi
116         DEBDIR="$APPNAME-$DEBVER"
117
118         if [ -e "$DEBDIR" ]
119         then
120                 cat <<__END__
121 The directory \"$DEBDIR\" does already exist. Please remove it if you want to
122 start from scratch.
123 __END__
124
125                 exit 1
126         fi
127         echo "Creating directory \"$DEBDIR\"."
128         mkdir "$DEBDIR"
129         mkdir "$DEBDIR"/debian
130         echo "Writing \"$DEBDIR/debian/control\""
131
132         if [ -n "$DEBFULLNAME" ]
133         then
134                 MAINT="$DEBFULLNAME <$DEBEMAIL>"
135                 echo "Using maintainer address \"$MAINT\""
136         else
137                 cat <<__END__
138 WARNING: DEBFULLNAME and DEBEMAIL not set. Please adjust maintainer field
139 in debian/control and debian/changelog afterwards.
140 __END__
141                 MAINT="Someone <please-update@in.here>"
142         fi
143         cat >"$DEBDIR/debian/control" <<__END__
144 Source: $APPNAME
145 Maintainer: $MAINT
146 Build-Depends: debhelper (>= 6.0.7~)
147
148 Package: $APPNAME
149 Architecture: all
150 Depends: \${wine:Depends}
151 Description: Application $APPNAME
152  This is a windows application packaged for Debian clients.
153 __END__
154         echo "Writing \"$DEBDIR/debian/compat\""
155         echo 5 > "$DEBDIR/debian/compat"
156         echo "Writing \"$DEBDIR/debian/rules\""
157         cat >"$DEBDIR/debian/rules" <<__END__
158 #!/usr/bin/make -f
159 build:
160         
161
162 clean:
163         dh_testdir
164         dh_testroot
165         dh_clean
166
167 install: build
168         dh_testdir
169         dh_testroot
170         dh_clean -k
171         dh_installdirs
172         
173         if grep -q "^EXE='c:.Programme.Please Adjust.start.exe'" $APPNAME ; \
174         then echo "Please update the EXE variable in the script $APPNAME"; \
175              exit 1; \
176         fi;
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 -- -Vwine:Depends="\$\$(dpkg-query -S \$\$(readlink -f /usr/bin/wine) | cut -d: -f1)"
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