2 #------------------------------------------------------------------------------
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.
9 # winelauncher [options] "<windows program> [program arguments]"
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.
16 # Copyright (c) 2000 by Jeremy White for CodeWeavers
18 #------------------------------------------------------------------------------
20 #------------------------------------------------------------------------------
21 # Primary configuration area - change this if you installed Wine to
22 # a location other than @prefix@
23 #------------------------------------------------------------------------------
26 #------------------------------------------------------------------------------
27 # Secondary configuration area; change these at your own risk.
28 #------------------------------------------------------------------------------
29 exec_prefix=@exec_prefix@
35 #------------------------------------------------------------------------------
36 # Establish Color Scheme
37 #------------------------------------------------------------------------------
38 COLOR=' -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'
48 #------------------------------------------------------------------------------
49 # Locate either xmessage or gmessage, if we can.
50 #------------------------------------------------------------------------------
51 type xmessage >/dev/null 2>/dev/null
52 if [ $? -ne 0 ] ; then
55 The Wine launcher is unable to find xmessage.
57 This launcher script relies heavily on finding this tool,
58 and without it, it will behave poorly.
60 Most Linux distributions have one or the other of these
63 We strongly recommend that you use your distribution's
64 software methods to locate xmessage."
67 XMESSAGE="xmessage $COLOR"
71 #------------------------------------------------------------------------------
72 # We're going to do a lot of fancy footwork below.
73 # Before we get started, it would be nice to know the argv0
74 # of the actual script we're running (and lets remove at least
75 # one level of symlinking).
76 #------------------------------------------------------------------------------
78 if [ -z $argv0_path ] ; then
82 real_name=`find $argv0_path -type l -printf "%l\n"`
83 if [ ! $real_name ]; then
85 elif [ ! -x $real_name ]; then
86 real_name=`find $argv0_path -printf "%h\n"`/$real_name
89 argv0_dir=`find $real_name -printf "%h\n"`
91 if [ -z $argv0_dir ] ; then
95 #------------------------------------------------------------------------------
96 # Okay, now all that junk above was established at configure time.
97 # However, if this is an RPM install, they may have chosen
98 # to relocate this installation. If so, that stuff above
99 # is all broken and we should rejigger it.
100 #------------------------------------------------------------------------------
101 WINE_BIN_NAME=wine.bin
102 if [ ! -x $WINEBIN/$WINE_BIN_NAME ] ; then
103 WINEBIN=`find $argv0_dir -maxdepth 1 -perm +0111 -type f -name "$WINE_BIN_NAME" -printf "%h\n" | head -1`
106 if [ ! -x $WINEBIN/$WINE_BIN_NAME ] ; then
107 WINEBIN=`find $argv0_dir/../ -maxdepth 1 -perm +0111 -type f -name "$WINE_BIN_NAME" -printf "%h\n" | head -1`
110 if [ ! -x $WINEBIN/$WINE_BIN_NAME ] ; then
112 if [ ! -x $WINEBIN/$WINE_BIN_NAME ] ; then
113 WINEBIN=`find $argv0_dir -maxdepth 1 -perm +0111 -type f -name "$WINE_BIN_NAME" -printf "%h\n" | head -1`
116 if [ ! -x $WINEBIN/$WINE_BIN_NAME ] ; then
117 WINEBIN=`find $argv0_dir/../ -maxdepth 1 -perm +0111 -type f -name "$WINE_BIN_NAME" -printf "%h\n" | head -1`
121 if [ ! -r $WINELIB/libwine.so ] ; then
122 WINELIB=`find $argv0_dir -maxdepth 2 -name 'libwine.so' -printf "%h\n" | head -1`
125 if [ ! -r $WINELIB/libwine.so ] ; then
126 WINELIB=`find $argv0_dir/../ -maxdepth 2 -name 'libwine.so' -printf "%h\n" | head -1`
129 if [ -x $WINEBIN/wineserver ] ; then
130 WINESERVER=$WINEBIN/wineserver
133 #------------------------------------------------------------------------------
134 # Hey, if we built Wine from source, let's add a little extra fun to
136 #------------------------------------------------------------------------------
137 if [ -x $WINEBIN/server/wineserver ] ; then
138 WINESERVER=$WINEBIN/server/wineserver
141 if [ -r $WINELIB/dlls/libntdll.so ] ; then
142 WINELIBDLLS=$WINELIB/dlls
146 #------------------------------------------------------------------------------
147 # Okay, set the paths and move on.
148 #------------------------------------------------------------------------------
149 export LD_LIBRARY_PATH=$WINELIB:$WINELIBDLLS:$LD_LIBRARY_PATH
150 export PATH=$WINEBIN:$PATH
151 export WINEDLLPATH=$WINELIBDLLS
152 export WINELOADER=$WINEBIN/$WINE_BIN_NAME
154 info_flag=~/.wine/.no_prelaunch_window_flag
155 debug_flag=~/.wine/.no_debug_window_flag
156 debug_options="-debugmsg warn+all"
158 if [ -f $info_flag ] ; then
164 if [ -f $debug_flag ] ; then
171 #------------------------------------------------------------------------------
172 # Handle winelib apps going through here
173 #------------------------------------------------------------------------------
175 if [ -f $argv0_path.so ] ; then
177 export WINEPRELOAD=$argv0_path.so
181 #------------------------------------------------------------------------------
182 # No arguments? Help 'em out
183 #------------------------------------------------------------------------------
186 if [ $# -eq 0 ] ; then
190 if [ $# -eq 1 -a "$1" = "" ] ; then
194 if [ $winelib -eq 1 ] ; then
198 if [ $no_args -eq 1 ] ; then
199 echo "Wine called with no arguments."
200 echo "Invoking $WINEBIN/$WINE_BIN_NAME $@ ..."
201 $XMESSAGE -buttons " Okay ":0," See the Wine Usage Statement ":1," Configure Wine ":2 \
202 -title "Welcome to Wine" \
205 You have started Wine without specifying any arguments.
207 Wine requires a least one argument - the name of the Windows
208 application you would like to run.
210 If you have launched this through the KDE menu system,
211 you can use the KDE file browser to select a Windows
212 exectuable and then click on it to launch Wine with
215 You can similarly use the GNOME file manager to
216 select a Windows executable and double click on it.
218 If you would like to see the command line arguments
219 for Wine, select the second option, below.
223 if [ $welcome_rc -eq 0 ] ; then
227 if [ $welcome_rc -eq 2 ] ; then
229 if [ $? -eq 0 ] ; then
232 if [ -x /opt/wine/bin/winesetup ] ; then
233 /opt/wine/bin/winesetup
235 $XMESSAGE -title "Error" "Error: Unable to find winesetup in your PATH or in /opt/wine/bin"
245 #------------------------------------------------------------------------------
246 # No config file? Offer to help 'em out...
247 #------------------------------------------------------------------------------
250 while [ $conf -eq 0 ] ; do
252 if [ -f ~/.winerc ] ; then
255 if [ -f ~/.wine/config ] ; then
258 if [ -f /etc/wine.conf ] ; then
262 if [ $conf -ne 0 ] ; then
266 echo "No configuration file detected."
267 $XMESSAGE -buttons " Cancel ":0," Proceed ":1," Configure Wine ":2 \
268 -title "Welcome to Wine" \
271 You have started Wine but we cannot find a Wine
274 This is normal if you have never run Wine before.
275 If this is the case, select the 'Configure Wine'
276 option, below, to create a configuration file.
280 if [ $init_rc -eq 0 ] ; then
284 if [ $init_rc -eq 1 ] ; then
288 if [ $init_rc -eq 2 ] ; then
290 if [ $? -eq 0 ] ; then
293 if [ -x /opt/wine/bin/winesetup ] ; then
294 /opt/wine/bin/winesetup
296 $XMESSAGE -title "Error" "Error: Unable to find winesetup in your PATH or in /opt/wine/bin"
303 #------------------------------------------------------------------------------
304 # Optionally Warn the user we're going to be launching Wine...
305 #------------------------------------------------------------------------------
306 if [ $use_info_message -ne 0 ] ; then
307 echo "Invoking $WINEBIN/$WINE_BIN_NAME $@ ..."
308 $XMESSAGE -timeout 30 -buttons " Dismiss ":0," Never display this message again ":3 \
309 -title "Wine Launch Window" \
310 "Invoking $WINEBIN/$WINE_BIN_NAME $@ ...
312 This dialog box is a temporary status dialog to let you know
313 that Wine is attempting to launch your application.
315 Since Wine is still very much in a development stage, many
316 applications will fail silently. This dialog box is your indication
317 that we're *trying* to run your application.
319 This dialog box will automatically disappear after 30 seconds,
320 or after your application finishes.
322 You can permanently disable this dialog by selecting the option below.
327 #------------------------------------------------------------------------------
328 # Here's a little function to clean up after that dialog...
329 #------------------------------------------------------------------------------
330 clean_up_info_message ()
332 if [ $use_info_message -ne 0 ] ; then
334 #------------------------------------------------------------------------------
335 # Okay, make sure that the notice window is dead (and kill it if it ain't)
336 #------------------------------------------------------------------------------
337 ps $info_message_pid >/dev/null 2>&1
338 if [ $? -ne 0 ] ; then
339 wait $info_message_pid
343 kill $info_message_pid
346 #------------------------------------------------------------------------------
347 # If they didn't like the warning window, turn it off
348 #------------------------------------------------------------------------------
349 if [ $info_return -eq 3 ] ; then
350 $XMESSAGE -title "Wine Prelaunch Control" \
351 "Wine will now disable the prelaunch Window you just saw.
352 You will no longer be notified when Wine is attempting
353 to start a Windows application.
355 You can reenable this Window by removing the $info_flag file." -buttons " Okay ":0," Cancel ":1
356 if [ $? -eq 0 ] ; then
364 #------------------------------------------------------------------------------
365 # Generate a temporary log file name
366 #------------------------------------------------------------------------------
367 if [ -n "$TMP" ] ; then
373 log_name=`mktemp "$log_dir/wine.log.XXXXXX"`
374 if [ $? -eq 0 ] ; then
378 status_name=`mktemp "$log_dir/wine.status.XXXXXX"`
379 if [ $? -eq 0 ] ; then
383 #------------------------------------------------------------------------------
384 # Okay, really launch Wine...
385 #------------------------------------------------------------------------------
386 if [ $use_log_name -ne 0 -a $use_status_name -ne 0 ] ; then
387 ( $WINEBIN/$WINE_BIN_NAME "$@"; echo $? >$status_name ) 2>&1 | tee "$log_name"
388 wine_return=`cat $status_name`
390 $WINEBIN/$WINE_BIN_NAME "$@"
393 if [ $use_status_name -ne 0 ] ; then
397 #------------------------------------------------------------------------------
398 # Test the return code, and see if it fails
399 #------------------------------------------------------------------------------
400 if [ $always_see_output -eq 0 -a $wine_return -eq 0 ] ; then
401 echo "Wine exited with a successful status"
402 if [ $use_log_name -ne 0 ] ; then
406 if [ $always_see_output -eq 0 ] ; then
407 echo "Wine failed with return code $wine_return"
410 #------------------------------------------------------------------------------
411 # Gracefully display a debug message if they like...
412 #------------------------------------------------------------------------------
413 while [ $use_debug_message -gt 0 ] ; do
415 #------------------------------------------------------------------------------
416 # Build up the menu of choices they can make...
417 #------------------------------------------------------------------------------
419 if [ $use_log_name -ne 0 ] ; then
420 BUTTONS="$BUTTONS"', View Log :1'
423 BUTTONS="$BUTTONS"', Debug :2'
424 BUTTONS="$BUTTONS"', Configure :4'
425 BUTTONS="$BUTTONS"', Disable :3'
427 #------------------------------------------------------------------------------
428 # Build an error message
429 #------------------------------------------------------------------------------
431 Wine has exited with a failure status of $wine_return.
433 Wine is still development software, so there can be many
434 explanations for this problem.
436 You can choose to run Wine again with a higher level
437 of debug messages (the debug option, below).
439 You can attempt to reconfigure Wine to make it work better.
440 Note that one change you can make that will dramatically
441 effect Wine's behaviour is to change whether or not
442 Wine uses a true Windows partition, mounted under Linux,
443 or whether it uses an empty Windows directory.
444 The Wine Configuration program can assist you in making
445 those changes (select Configure, below, for more).
447 You can disable this message entirely by selecting the
448 Disable option below."
450 if [ $always_see_output -ne 0 -a $wine_return -eq 0 ] ; then
452 Wine has exited with a failure status of $wine_return.
454 You can disable this message entirely by selecting the
455 Disable option below."
459 if [ $use_log_name -ne 0 ] ; then
462 Wine has captured a log of the Wine output in the file $log_name.
463 You may view this file by selecting View Log, below."
466 #------------------------------------------------------------------------------
467 # Display the message
468 #------------------------------------------------------------------------------
469 $XMESSAGE -title "Wine Finished With Error" -buttons "$BUTTONS" "$MESSAGE"
472 #------------------------------------------------------------------------------
473 # Dismiss the other window...
474 #------------------------------------------------------------------------------
475 clean_up_info_message
477 #------------------------------------------------------------------------------
478 # Process a configure instruction
479 #------------------------------------------------------------------------------
480 if [ $debug_return -eq 4 ] ; then
482 if [ $? -eq 0 ] ; then
485 if [ -x /opt/wine/bin/winesetup ] ; then
486 /opt/wine/bin/winesetup
488 $XMESSAGE -title "Error" "Error: Unable to find winesetup in your PATH or in /opt/wine/bin"
494 #------------------------------------------------------------------------------
495 # Process a view instruction
496 #------------------------------------------------------------------------------
497 if [ $debug_return -eq 1 ] ; then
498 $XMESSAGE -title "View Wine Log" -file "$log_name" -buttons " Okay ":0,"Delete $log_name":1
499 if [ $? -eq 1 ] ; then
500 echo "Deleting $log_name"
508 #------------------------------------------------------------------------------
509 # If they didn't like the warning window, turn it off
510 #------------------------------------------------------------------------------
511 if [ $debug_return -eq 3 ] ; then
512 $XMESSAGE -title "Wine Debug Log Control" \
513 "Wine will now disable the Wine debug output control window you just saw.
514 You will no longer be notified when Wine fails to start a
517 You can reenable this Window by removing the $debug_flag file." -buttons " Okay ":0," Cancel ":1
519 if [ $? -eq 0 ] ; then
525 #------------------------------------------------------------------------------
526 # If they want to retry with debug, let 'em.
527 #------------------------------------------------------------------------------
528 if [ $debug_return -eq 2 ] ; then
529 echo "Rerunning $0 $debug_options $@"
530 exec $0 $debug_options "$@"
536 clean_up_info_message
539 if [ $wine_return -ge 128 ]; then
540 # try to kill myself with the same signal
541 kill -$[wine_return - 128] $$
542 # if we get here the kill didn't work