blob: c73e0d2637bf9093a9fc6fa3dbd3a190f4877b39 [file] [log] [blame]
Jeremy Whitef9f030b2000-11-05 20:06:56 +00001#!/bin/sh
2#------------------------------------------------------------------------------
3# Winelauncher
4# This shell script attempts to intelligently manage the process
5# of launching a program with Wine. It adds some level of
6# visual feedback to an end user.
7#
8# Usage:
9# winelauncher [options] "<windows program> [program arguments]"
10#
11# This script is meant to be installed to /usr/bin/wine, and
12# to be used to invoke a Windows executable.
13# The options are passed through directly to Wine, and are
14# documented in the Wine man page.
15#
16# Copyright (c) 2000 by Jeremy White for CodeWeavers
17#
18#------------------------------------------------------------------------------
19
Jeremy Whitef9f030b2000-11-05 20:06:56 +000020#------------------------------------------------------------------------------
21# Primary configuration area - change this if you installed Wine to
22# a location other than @prefix@
23#------------------------------------------------------------------------------
24prefix=@prefix@
25
26#------------------------------------------------------------------------------
27# Secondary configuration area; change these at your own risk.
28#------------------------------------------------------------------------------
29exec_prefix=@exec_prefix@
30WINEBIN=@bindir@
31WINELIB=@libdir@
Jeremy White28fd5582000-11-10 22:35:06 +000032WINESERVERBIN=
33WINELIBDLLS=
Jeremy Whitef9f030b2000-11-05 20:06:56 +000034
Jeremy White28fd5582000-11-10 22:35:06 +000035#------------------------------------------------------------------------------
36# Establish Color Scheme
37#------------------------------------------------------------------------------
38COLOR=' -xrm *.Command.background:darkgrey
39-xrm *.Command.foreground:black
40-xrm *.Text.background:black
41-xrm *.Text.foreground:green
42-xrm *.Form.background:grey
43-xrm *.Form.foreground:green
44-xrm *.foreground:green
45-xrm *.background:black'
46
47
48XMESSAGE="xmessage $COLOR"
49
50
51#------------------------------------------------------------------------------
52# We're going to do a lot of fancy footwork below.
53# Before we get started, it would be nice to know the argv0,
54# of the actual script we're running (and lets remove at least
55# one level of symlinking).
56#------------------------------------------------------------------------------
57real_name=`find $0 -type l -printf "%l\n"`
58if [ ! $real_name ]; then
59 real_name=$0;
60fi
61argv0_dir=`find $real_name -printf "%h\n"`
62
63if [ -z $argv0_dir ] ; then
64 argv0_dir=.
65fi
66
67#------------------------------------------------------------------------------
68# Okay, now all that junk above was established at configure time.
69# However, if this is an RPM install, they may have chosen
70# to relocate this installation. If so, that stuff above
71# is all broken and we should rejigger it.
72#------------------------------------------------------------------------------
Jeremy White3a2b9002000-12-01 20:43:51 +000073WINE_BIN_NAME=wine.bin
74if [ ! -x $WINEBIN/$WINE_BIN_NAME ] ; then
75 WINEBIN=`find $argv0_dir -maxdepth 1 -perm +0111 -type f -name "$WINE_BIN_NAME" -printf "%h\n" | head -1`
Jeremy White28fd5582000-11-10 22:35:06 +000076fi
77
Jeremy White3a2b9002000-12-01 20:43:51 +000078if [ ! -x $WINEBIN/$WINE_BIN_NAME ] ; then
79 WINEBIN=`find $argv0_dir/../ -maxdepth 1 -perm +0111 -type f -name "$WINE_BIN_NAME" -printf "%h\n" | head -1`
80fi
81
82if [ ! -x $WINEBIN/$WINE_BIN_NAME ] ; then
83 WINE_BIN_NAME=wine
84 if [ ! -x $WINEBIN/$WINE_BIN_NAME ] ; then
85 WINEBIN=`find $argv0_dir -maxdepth 1 -perm +0111 -type f -name "$WINE_BIN_NAME" -printf "%h\n" | head -1`
86 fi
87
88 if [ ! -x $WINEBIN/$WINE_BIN_NAME ] ; then
89 WINEBIN=`find $argv0_dir/../ -maxdepth 1 -perm +0111 -type f -name "$WINE_BIN_NAME" -printf "%h\n" | head -1`
90 fi
Jeremy White28fd5582000-11-10 22:35:06 +000091fi
92
93if [ ! -r $WINELIB/libwine.so ] ; then
94 WINELIB=`find $argv0_dir -maxdepth 2 -name 'libwine.so' -printf "%h\n" | head -1`
95fi
96
97if [ ! -r $WINELIB/libwine.so ] ; then
98 WINELIB=`find $argv0_dir/../ -maxdepth 2 -name 'libwine.so' -printf "%h\n" | head -1`
99fi
100
Jeremy White3a2b9002000-12-01 20:43:51 +0000101if [ -x $WINEBIN/wineserver ] ; then
102 WINESERVER=$WINEBIN/wineserver
103fi
104
Jeremy White28fd5582000-11-10 22:35:06 +0000105#------------------------------------------------------------------------------
106# Hey, if we built Wine from source, let's add a little extra fun to
107# mix it up a bit
108#------------------------------------------------------------------------------
109if [ -x $WINEBIN/server/wineserver ] ; then
Jeremy White3a2b9002000-12-01 20:43:51 +0000110 WINESERVER=$WINEBIN/server/wineserver
Jeremy White28fd5582000-11-10 22:35:06 +0000111fi
112
113if [ -r $WINELIB/dlls/libuser.so ] ; then
114 WINELIBDLLS=$WINELIB/dlls
115fi
116
117
118#------------------------------------------------------------------------------
119# Okay, set the paths and move on.
120#------------------------------------------------------------------------------
121export LD_LIBRARY_PATH=$WINELIB:$WINELIBDLLS:$LD_LIBRARY_PATH
Jeremy White3a2b9002000-12-01 20:43:51 +0000122export PATH=$WINEBIN:$PATH
123export WINEDLLPATH=$WINELIBDLLS
124export WINELOADER=$WINEBIN/$WINE_BIN_NAME
Jeremy Whitef9f030b2000-11-05 20:06:56 +0000125
126info_flag=~/.wine/.no_prelaunch_window_flag
127debug_flag=~/.wine/.no_debug_window_flag
128debug_options="-debugmsg warn+all"
129
130if [ -f $info_flag ] ; then
131 use_info_message=0
132else
133 use_info_message=1
134fi
135
136if [ -f $debug_flag ] ; then
137 use_debug_message=0
138else
139 use_debug_message=1
140fi
141
142
143#------------------------------------------------------------------------------
Jeremy White28fd5582000-11-10 22:35:06 +0000144# No arguments? Help 'em out
145#------------------------------------------------------------------------------
146always_see_output=0
147no_args=0
148if [ $# -eq 0 ] ; then
149 no_args=1
150fi
151
152if [ $# -eq 1 -a foo$1 = foo ] ; then
153 no_args=1
154fi
155
156if [ $no_args -eq 1 ] ; then
157 echo "Wine called with no arguments."
Jeremy White3a2b9002000-12-01 20:43:51 +0000158 echo "Invoking $WINEBIN/$WINE_BIN_NAME $@ ..."
Jeremy White28fd5582000-11-10 22:35:06 +0000159 $XMESSAGE -buttons " Okay ":0," See the Wine Usage Statement ":1," Configure Wine ":2 \
160 -title "Welcome to Wine" \
161 "
162
163 You have started Wine without specifying any arguments.
164
165 Wine requires a least one argument - the name of the Windows
166 application you would like to run.
167
168 If you have launched this through the KDE menu system,
169 you can use the KDE file browser to select a Windows
170 exectuable and then click on it to launch Wine with
171 that application.
172
173 You can similarly use the GNOME file manager to
174 select a Windows executable and double click on it.
175
176 If you would like to see the command line arguments
177 for Wine, select the second option, below.
178
179 "
180 welcome_rc=$?
181 if [ $welcome_rc -eq 0 ] ; then
182 exit
183 fi
184
185 if [ $welcome_rc -eq 2 ] ; then
186 which winesetup
187 if [ $? -eq 0 ] ; then
188 winesetup
189 else
190 if [ -x /opt/wine/bin/winesetup ] ; then
191 /opt/wine/bin/winesetup
192 else
193 $XMESSAGE -title "Error" "Error: Unable to find winesetup in your PATH or in /opt/wine/bin"
194 fi
195 fi
196 exit
197 fi
198
199 use_info_message=0
200 always_see_output=1
201fi
202
203#------------------------------------------------------------------------------
Jeremy White3a2b9002000-12-01 20:43:51 +0000204# No config file? Offer to help 'em out...
205#------------------------------------------------------------------------------
206conf=0
207
208while [ $conf -eq 0 ] ; do
209
210 if [ -f ~/.winerc ] ; then
211 conf=1
212 fi
213 if [ -f ~/.wine/config ] ; then
214 conf=2
215 fi
216 if [ -f /etc/wine.conf ] ; then
217 conf=3
218 fi
219
220 if [ $conf -ne 0 ] ; then
221 break;
222 fi
223
224 echo "No configuration file detected."
225 $XMESSAGE -buttons " Cancel ":0," Proceed ":1," Configure Wine ":2 \
226 -title "Welcome to Wine" \
227 "
228
229 You have started Wine but we cannot find a Wine
230 configuration file.
231
232 This is normal if you have never run Wine before.
233 If this is the case, select the 'Configure Wine'
234 option, below, to create a configuration file.
235
236 "
237 init_rc=$?
238 if [ $init_rc -eq 0 ] ; then
239 exit
240 fi
241
242 if [ $init_rc -eq 1 ] ; then
243 break
244 fi
245
246 if [ $init_rc -eq 2 ] ; then
247 which winesetup
248 if [ $? -eq 0 ] ; then
249 winesetup
250 else
251 if [ -x /opt/wine/bin/winesetup ] ; then
252 /opt/wine/bin/winesetup
253 else
254 $XMESSAGE -title "Error" "Error: Unable to find winesetup in your PATH or in /opt/wine/bin"
255 fi
256 fi
257 fi
258
259done
260
261#------------------------------------------------------------------------------
Jeremy Whitef9f030b2000-11-05 20:06:56 +0000262# Optionally Warn the user we're going to be launching Wine...
263#------------------------------------------------------------------------------
264if [ $use_info_message -ne 0 ] ; then
Jeremy White3a2b9002000-12-01 20:43:51 +0000265 echo "Invoking $WINEBIN/$WINE_BIN_NAME $@ ..."
Jeremy White28fd5582000-11-10 22:35:06 +0000266 $XMESSAGE -timeout 30 -buttons " Dismiss ":0," Never display this message again ":3 \
267 -title "Wine Launch Window" \
Jeremy White3a2b9002000-12-01 20:43:51 +0000268 "Invoking $WINEBIN/$WINE_BIN_NAME $@ ...
Jeremy White28fd5582000-11-10 22:35:06 +0000269
270 This dialog box is a temporary status dialog to let you know
271 that Wine is attempting to launch your application.
272
273 Since Wine is still very much in a development stage, many
274 applications will fail silently. This dialog box is your indication
275 that we're *trying* to run your application.
276
277 This dialog box will automatically disappear after 30 seconds,
278 or after your application finishes.
279
280 You can permanently disable this dialog by selecting the option below.
281 " &
Jeremy Whitef9f030b2000-11-05 20:06:56 +0000282 info_message_pid=$!
283fi
284
285#------------------------------------------------------------------------------
Jeremy White28fd5582000-11-10 22:35:06 +0000286# Here's a little function to clean up after that dialog...
287#------------------------------------------------------------------------------
288function clean_up_info_message ()
289{
290 if [ $use_info_message -ne 0 ] ; then
291
292 #------------------------------------------------------------------------------
293 # Okay, make sure that the notice window is dead (and kill it if it ain't)
294 #------------------------------------------------------------------------------
295 ps $info_message_pid >/dev/null 2>&1
296 if [ $? -ne 0 ] ; then
297 wait $info_message_pid
298 info_return=$?
299 else
300 info_return=0
301 kill $info_message_pid
302 fi
303
304 #------------------------------------------------------------------------------
305 # If they didn't like the warning window, turn it off
306 #------------------------------------------------------------------------------
307 if [ $info_return -eq 3 ] ; then
308 $XMESSAGE -title "Wine Prelaunch Control" \
309 "Wine will now disable the prelaunch Window you just saw.
310 You will no longer be notified when Wine is attempting
311 to start a Windows application.
312
313 You can reenable this Window by removing the $info_flag file." -buttons " Okay ":0," Cancel ":1
314 if [ $? -eq 0 ] ; then
315 touch $info_flag
316 fi
317 fi
318 fi
319
320 use_info_message=0
321}
322#------------------------------------------------------------------------------
Jeremy Whitef9f030b2000-11-05 20:06:56 +0000323# Generate a temporary log file name
324#------------------------------------------------------------------------------
325use_log_name=0
326log_name=`mktemp /tmp/wine.log.XXXXXX`
327if [ $? -eq 0 ] ; then
328 which tail >/dev/null 2>&1
329 if [ $? -eq 0 ]; then
330 use_log_name=1
331 fi
332fi
333
334#------------------------------------------------------------------------------
335# Okay, really launch Wine...
336#------------------------------------------------------------------------------
337if [ $use_log_name -ne 0 ] ; then
338 #------------------------------------------------------------------------------
339 # Okay, we bend over backwards to run Wine, get that status,
340 # but still display its output to the screen.
341 # The obvious thing to do is to run wine and pipe output to tee,
342 # but then I can't find a way to get the return code of wine;
Jeremy White28fd5582000-11-10 22:35:06 +0000343 # I only get the return code of tee.
Jeremy Whitef9f030b2000-11-05 20:06:56 +0000344 #------------------------------------------------------------------------------
Jeremy White3a2b9002000-12-01 20:43:51 +0000345 $WINEBIN/$WINE_BIN_NAME "$@" >$log_name 2>&1 &
Jeremy Whitef9f030b2000-11-05 20:06:56 +0000346 wine_pid=$!
347
348 tail -f $log_name &
349 tail_pid=$!
350
351 wait $wine_pid
352 wine_return=$?
353
354 kill $tail_pid
355else
Jeremy White3a2b9002000-12-01 20:43:51 +0000356 $WINEBIN/$WINE_BIN_NAME "$@"
Jeremy Whitef9f030b2000-11-05 20:06:56 +0000357 wine_return=$?
358fi
359
360#------------------------------------------------------------------------------
Jeremy Whitef9f030b2000-11-05 20:06:56 +0000361# Test the return code, and see if it fails
362#------------------------------------------------------------------------------
Jeremy White28fd5582000-11-10 22:35:06 +0000363if [ $always_see_output -eq 0 -a $wine_return -eq 0 ] ; then
Jeremy Whitef9f030b2000-11-05 20:06:56 +0000364 echo "Wine exited with a successful status"
365 if [ $use_log_name -ne 0 ] ; then
366 rm -f $log_name
367 fi
368else
Jeremy White28fd5582000-11-10 22:35:06 +0000369 if [ $always_see_output -eq 0 ] ; then
370 echo "Wine failed with return code $wine_return"
371 fi
Jeremy Whitef9f030b2000-11-05 20:06:56 +0000372
373 #------------------------------------------------------------------------------
374 # Gracefully display a debug message if they like...
375 #------------------------------------------------------------------------------
376 while [ $use_debug_message -gt 0 ] ; do
377
378 #------------------------------------------------------------------------------
Jeremy White28fd5582000-11-10 22:35:06 +0000379 # Build up the menu of choices they can make...
Jeremy Whitef9f030b2000-11-05 20:06:56 +0000380 #------------------------------------------------------------------------------
Jeremy White28fd5582000-11-10 22:35:06 +0000381 BUTTONS=' Okay :0'
Jeremy Whitef9f030b2000-11-05 20:06:56 +0000382 if [ $use_log_name -ne 0 ] ; then
Jeremy White28fd5582000-11-10 22:35:06 +0000383 BUTTONS="$BUTTONS"', View Log :1'
Jeremy Whitef9f030b2000-11-05 20:06:56 +0000384 fi
Jeremy Whitef9f030b2000-11-05 20:06:56 +0000385
Jeremy White28fd5582000-11-10 22:35:06 +0000386 BUTTONS="$BUTTONS"', Debug :2'
387 BUTTONS="$BUTTONS"', Configure :4'
388 BUTTONS="$BUTTONS"', Disable :3'
389
390 #------------------------------------------------------------------------------
391 # Build an error message
392 #------------------------------------------------------------------------------
393 MESSAGE="
394Wine has exited with a failure status of $wine_return.
395
396Wine is still development software, so there can be many
397explanations for this problem.
398
399You can choose to run Wine again with a higher level
400of debug messages (the debug option, below).
401
402You can attempt to reconfigure Wine to make it work better.
403Note that one change you can make that will dramatically
404effect Wine's behaviour is to change whether or not
405Wine uses a true Windows partition, mounted under Linux,
406or whether it uses an empty Windows directory.
407The Wine Configuration program can assist you in making
408those changes (select Configure, below, for more).
409
410You can disable this message entirely by selecting the
411Disable option below."
412
413 if [ $always_see_output -ne 0 -a $wine_return -eq 0 ] ; then
414 MESSAGE="
415Wine has exited with a failure status of $wine_return.
416
417You can disable this message entirely by selecting the
418Disable option below."
419
420 fi
421
422 if [ $use_log_name -ne 0 ] ; then
423 MESSAGE="$MESSAGE
424
425Wine has captured a log of the Wine output in the file $log_name.
426You may view this file by selecting View Log, below."
427 fi
428
429 #------------------------------------------------------------------------------
430 # Display the message
431 #------------------------------------------------------------------------------
432 $XMESSAGE -title "Wine Finished With Error" -buttons "$BUTTONS" "$MESSAGE"
433 debug_return=$?
434
435 #------------------------------------------------------------------------------
436 # Dismiss the other window...
437 #------------------------------------------------------------------------------
438 clean_up_info_message
439
440 #------------------------------------------------------------------------------
441 # Process a configure instruction
442 #------------------------------------------------------------------------------
443 if [ $debug_return -eq 4 ] ; then
444 which winesetup
445 if [ $? -eq 0 ] ; then
446 winesetup
447 else
448 if [ -x /opt/wine/bin/winesetup ] ; then
449 /opt/wine/bin/winesetup
450 else
451 $XMESSAGE -title "Error" "Error: Unable to find winesetup in your PATH or in /opt/wine/bin"
452 fi
453 fi
454 continue;
455 fi
456
457 #------------------------------------------------------------------------------
458 # Process a view instruction
459 #------------------------------------------------------------------------------
460 if [ $debug_return -eq 1 ] ; then
461 $XMESSAGE -title "View Wine Log" -file $log_name -buttons " Okay ":0,"Delete $log_name":1
Jeremy Whitef9f030b2000-11-05 20:06:56 +0000462 if [ $? -eq 1 ] ; then
463 echo "Deleting $log_name"
464 rm -f $log_name
465 use_log_name=0
466 fi
467 else
468 use_debug_message=0
469 fi
470
471 #------------------------------------------------------------------------------
472 # If they didn't like the warning window, turn it off
473 #------------------------------------------------------------------------------
Jeremy White28fd5582000-11-10 22:35:06 +0000474 if [ $debug_return -eq 3 ] ; then
475 $XMESSAGE -title "Wine Debug Log Control" \
476 "Wine will now disable the Wine debug output control window you just saw.
477 You will no longer be notified when Wine fails to start a
478 Windows application.
479
480 You can reenable this Window by removing the $debug_flag file." -buttons " Okay ":0," Cancel ":1
481
482 if [ $? -eq 0 ] ; then
483 touch $debug_flag
484 fi
485
Jeremy Whitef9f030b2000-11-05 20:06:56 +0000486 fi
487
488 #------------------------------------------------------------------------------
489 # If they want to retry with debug, let 'em.
490 #------------------------------------------------------------------------------
Jeremy White28fd5582000-11-10 22:35:06 +0000491 if [ $debug_return -eq 2 ] ; then
492 echo "Rerunning $0 $debug_options $@"
493 exec $0 $debug_options $@
Jeremy Whitef9f030b2000-11-05 20:06:56 +0000494 fi
495 done
496fi
497
Jeremy White28fd5582000-11-10 22:35:06 +0000498
499clean_up_info_message
500