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 distributions
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 #------------------------------------------------------------------------------
368 log_name=`mktemp /tmp/wine.log.XXXXXX`
369 if [ $? -eq 0 ] ; then
373 status_name=`mktemp /tmp/wine.status.XXXXXX`
374 if [ $? -eq 0 ] ; then
378 #------------------------------------------------------------------------------
379 # Okay, really launch Wine...
380 #------------------------------------------------------------------------------
381 if [ $use_log_name -ne 0 -a $use_status_name -ne 0 ] ; then
382 ( $WINEBIN/$WINE_BIN_NAME "$@"; echo $? >$status_name ) 2>&1 | tee $log_name
383 wine_return=`cat $status_name`
385 $WINEBIN/$WINE_BIN_NAME "$@"
388 if [ $use_status_name -ne 0 ] ; then
392 #------------------------------------------------------------------------------
393 # Test the return code, and see if it fails
394 #------------------------------------------------------------------------------
395 if [ $always_see_output -eq 0 -a $wine_return -eq 0 ] ; then
396 echo "Wine exited with a successful status"
397 if [ $use_log_name -ne 0 ] ; then
401 if [ $always_see_output -eq 0 ] ; then
402 echo "Wine failed with return code $wine_return"
405 #------------------------------------------------------------------------------
406 # Gracefully display a debug message if they like...
407 #------------------------------------------------------------------------------
408 while [ $use_debug_message -gt 0 ] ; do
410 #------------------------------------------------------------------------------
411 # Build up the menu of choices they can make...
412 #------------------------------------------------------------------------------
414 if [ $use_log_name -ne 0 ] ; then
415 BUTTONS="$BUTTONS"', View Log :1'
418 BUTTONS="$BUTTONS"', Debug :2'
419 BUTTONS="$BUTTONS"', Configure :4'
420 BUTTONS="$BUTTONS"', Disable :3'
422 #------------------------------------------------------------------------------
423 # Build an error message
424 #------------------------------------------------------------------------------
426 Wine has exited with a failure status of $wine_return.
428 Wine is still development software, so there can be many
429 explanations for this problem.
431 You can choose to run Wine again with a higher level
432 of debug messages (the debug option, below).
434 You can attempt to reconfigure Wine to make it work better.
435 Note that one change you can make that will dramatically
436 effect Wine's behaviour is to change whether or not
437 Wine uses a true Windows partition, mounted under Linux,
438 or whether it uses an empty Windows directory.
439 The Wine Configuration program can assist you in making
440 those changes (select Configure, below, for more).
442 You can disable this message entirely by selecting the
443 Disable option below."
445 if [ $always_see_output -ne 0 -a $wine_return -eq 0 ] ; then
447 Wine has exited with a failure status of $wine_return.
449 You can disable this message entirely by selecting the
450 Disable option below."
454 if [ $use_log_name -ne 0 ] ; then
457 Wine has captured a log of the Wine output in the file $log_name.
458 You may view this file by selecting View Log, below."
461 #------------------------------------------------------------------------------
462 # Display the message
463 #------------------------------------------------------------------------------
464 $XMESSAGE -title "Wine Finished With Error" -buttons "$BUTTONS" "$MESSAGE"
467 #------------------------------------------------------------------------------
468 # Dismiss the other window...
469 #------------------------------------------------------------------------------
470 clean_up_info_message
472 #------------------------------------------------------------------------------
473 # Process a configure instruction
474 #------------------------------------------------------------------------------
475 if [ $debug_return -eq 4 ] ; then
477 if [ $? -eq 0 ] ; then
480 if [ -x /opt/wine/bin/winesetup ] ; then
481 /opt/wine/bin/winesetup
483 $XMESSAGE -title "Error" "Error: Unable to find winesetup in your PATH or in /opt/wine/bin"
489 #------------------------------------------------------------------------------
490 # Process a view instruction
491 #------------------------------------------------------------------------------
492 if [ $debug_return -eq 1 ] ; then
493 $XMESSAGE -title "View Wine Log" -file $log_name -buttons " Okay ":0,"Delete $log_name":1
494 if [ $? -eq 1 ] ; then
495 echo "Deleting $log_name"
503 #------------------------------------------------------------------------------
504 # If they didn't like the warning window, turn it off
505 #------------------------------------------------------------------------------
506 if [ $debug_return -eq 3 ] ; then
507 $XMESSAGE -title "Wine Debug Log Control" \
508 "Wine will now disable the Wine debug output control window you just saw.
509 You will no longer be notified when Wine fails to start a
512 You can reenable this Window by removing the $debug_flag file." -buttons " Okay ":0," Cancel ":1
514 if [ $? -eq 0 ] ; then
520 #------------------------------------------------------------------------------
521 # If they want to retry with debug, let 'em.
522 #------------------------------------------------------------------------------
523 if [ $debug_return -eq 2 ] ; then
524 echo "Rerunning $0 $debug_options $@"
525 exec $0 $debug_options "$@"
531 clean_up_info_message
534 if [ $wine_return -ge 128 ]; then
535 # try to kill myself with the same signal
536 kill -$[wine_return - 128] $$
537 # if we get here the kill didn't work