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 different location
23 #------------------------------------------------------------------------------
29 #------------------------------------------------------------------------------
30 # Establish Color Scheme
31 #------------------------------------------------------------------------------
32 COLOR=' -xrm *.Command.background:darkgrey
33 -xrm *.Command.foreground:black
34 -xrm *.Text.background:black
35 -xrm *.Text.foreground:green
36 -xrm *.Form.background:grey
37 -xrm *.Form.foreground:green
38 -xrm *.foreground:green
39 -xrm *.background:black'
42 #------------------------------------------------------------------------------
43 # Locate either xmessage or gmessage, if we can.
44 #------------------------------------------------------------------------------
45 type xmessage >/dev/null 2>/dev/null
46 if [ $? -ne 0 ] ; then
49 The Wine launcher is unable to find xmessage.
51 This launcher script relies heavily on finding this tool,
52 and without it, it will behave poorly.
54 Most Linux distributions have one or the other of these
57 We strongly recommend that you use your distribution's
58 software methods to locate xmessage."
61 XMESSAGE="xmessage $COLOR"
65 #------------------------------------------------------------------------------
66 # We're going to do a lot of fancy footwork below.
67 # Before we get started, it would be nice to know the argv0
68 # of the actual script we're running (and lets remove at least
69 # one level of symlinking).
70 #------------------------------------------------------------------------------
72 if [ -z $argv0_path ] ; then
76 real_name=`find $argv0_path -type l -printf "%l\n"`
77 if [ ! $real_name ]; then
79 elif [ ! -x $real_name ]; then
80 real_name=`find $argv0_path -printf "%h\n"`/$real_name
83 argv0_dir=`find $real_name -printf "%h\n"`
85 if [ -z $argv0_dir ] ; then
89 #------------------------------------------------------------------------------
90 # Okay, now all that junk above was established at configure time.
91 # However, if this is an RPM install, they may have chosen
92 # to relocate this installation. If so, that stuff above
93 # is all broken and we should rejigger it.
94 #------------------------------------------------------------------------------
95 WINE_BIN_NAME=wine.bin
96 if [ ! -x $WINEBIN/$WINE_BIN_NAME ] ; then
97 WINEBIN=`find $argv0_dir -maxdepth 1 -perm +0111 -type f -name "$WINE_BIN_NAME" -printf "%h\n" | head -1`
100 if [ ! -x $WINEBIN/$WINE_BIN_NAME ] ; then
101 WINEBIN=`find $argv0_dir/../ -maxdepth 1 -perm +0111 -type f -name "$WINE_BIN_NAME" -printf "%h\n" | head -1`
104 if [ ! -x $WINEBIN/$WINE_BIN_NAME ] ; then
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
111 WINEBIN=`find $argv0_dir/../ -maxdepth 1 -perm +0111 -type f -name "$WINE_BIN_NAME" -printf "%h\n" | head -1`
115 if [ ! -r $WINELIB/libwine.so ] ; then
116 WINELIB=`find $argv0_dir -maxdepth 2 -name 'libwine.so' -printf "%h\n" | head -1`
119 if [ ! -r $WINELIB/libwine.so ] ; then
120 WINELIB=`find $argv0_dir/../ -maxdepth 2 -name 'libwine.so' -printf "%h\n" | head -1`
123 if [ -x $WINEBIN/wineserver ] ; then
124 WINESERVER=$WINEBIN/wineserver
127 #------------------------------------------------------------------------------
128 # Hey, if we built Wine from source, let's add a little extra fun to
130 #------------------------------------------------------------------------------
131 if [ -x $WINEBIN/server/wineserver ] ; then
132 WINESERVER=$WINEBIN/server/wineserver
135 if [ -r $WINELIB/dlls/libntdll.so ] ; then
136 WINELIBDLLS=$WINELIB/dlls
140 #------------------------------------------------------------------------------
141 # Okay, set the paths and move on.
142 #------------------------------------------------------------------------------
143 export LD_LIBRARY_PATH=$WINELIB:$WINELIBDLLS:$LD_LIBRARY_PATH
144 export PATH=$WINEBIN:$PATH
145 export WINEDLLPATH=$WINELIBDLLS
146 export WINELOADER=$WINEBIN/$WINE_BIN_NAME
148 info_flag=~/.wine/.no_prelaunch_window_flag
149 debug_flag=~/.wine/.no_debug_window_flag
150 debug_options="-debugmsg warn+all"
152 if [ -f $info_flag ] ; then
158 if [ -f $debug_flag ] ; then
165 #------------------------------------------------------------------------------
166 # Handle winelib apps going through here
167 #------------------------------------------------------------------------------
169 if [ -f $argv0_path.so ] ; then
171 export WINEPRELOAD=$argv0_path.so
175 #------------------------------------------------------------------------------
176 # No arguments? Help 'em out
177 #------------------------------------------------------------------------------
180 if [ $# -eq 0 ] ; then
184 if [ $# -eq 1 -a "$1" = "" ] ; then
188 if [ $winelib -eq 1 ] ; then
192 if [ $no_args -eq 1 ] ; then
193 echo "Wine called with no arguments."
194 echo "Invoking $WINEBIN/$WINE_BIN_NAME $@ ..."
195 $XMESSAGE -buttons " Okay ":0," See the Wine Usage Statement ":1," Configure Wine ":2 \
196 -title "Welcome to Wine" \
199 You have started Wine without specifying any arguments.
201 Wine requires a least one argument - the name of the Windows
202 application you would like to run.
204 If you have launched this through the KDE menu system,
205 you can use the KDE file browser to select a Windows
206 exectuable and then click on it to launch Wine with
209 You can similarly use the GNOME file manager to
210 select a Windows executable and double click on it.
212 If you would like to see the command line arguments
213 for Wine, select the second option, below.
217 if [ $welcome_rc -eq 0 ] ; then
221 if [ $welcome_rc -eq 2 ] ; then
223 if [ $? -eq 0 ] ; then
226 if [ -x /opt/wine/bin/winesetup ] ; then
227 /opt/wine/bin/winesetup
229 $XMESSAGE -title "Error" "Error: Unable to find winesetup in your PATH or in /opt/wine/bin"
239 #------------------------------------------------------------------------------
240 # No config file? Offer to help 'em out...
241 #------------------------------------------------------------------------------
244 while [ $conf -eq 0 ] ; do
246 if [ -f ~/.winerc ] ; then
249 if [ -f ~/.wine/config ] ; then
252 if [ -f /etc/wine.conf ] ; then
256 if [ $conf -ne 0 ] ; then
260 echo "No configuration file detected."
261 $XMESSAGE -buttons " Cancel ":0," Proceed ":1," Configure Wine ":2 \
262 -title "Welcome to Wine" \
265 You have started Wine but we cannot find a Wine
268 This is normal if you have never run Wine before.
269 If this is the case, select the 'Configure Wine'
270 option, below, to create a configuration file.
274 if [ $init_rc -eq 0 ] ; then
278 if [ $init_rc -eq 1 ] ; then
282 if [ $init_rc -eq 2 ] ; then
284 if [ $? -eq 0 ] ; then
287 if [ -x /opt/wine/bin/winesetup ] ; then
288 /opt/wine/bin/winesetup
290 $XMESSAGE -title "Error" "Error: Unable to find winesetup in your PATH or in /opt/wine/bin"
297 #------------------------------------------------------------------------------
298 # Optionally Warn the user we're going to be launching Wine...
299 #------------------------------------------------------------------------------
300 if [ $use_info_message -ne 0 ] ; then
301 echo "Invoking $WINEBIN/$WINE_BIN_NAME $@ ..."
302 $XMESSAGE -timeout 30 -buttons " Dismiss ":0," Never display this message again ":3 \
303 -title "Wine Launch Window" \
304 "Invoking $WINEBIN/$WINE_BIN_NAME $@ ...
306 This dialog box is a temporary status dialog to let you know
307 that Wine is attempting to launch your application.
309 Since Wine is still very much in a development stage, many
310 applications will fail silently. This dialog box is your indication
311 that we're *trying* to run your application.
313 This dialog box will automatically disappear after 30 seconds,
314 or after your application finishes.
316 You can permanently disable this dialog by selecting the option below.
321 #------------------------------------------------------------------------------
322 # Here's a little function to clean up after that dialog...
323 #------------------------------------------------------------------------------
324 clean_up_info_message ()
326 if [ $use_info_message -ne 0 ] ; then
328 #------------------------------------------------------------------------------
329 # Okay, make sure that the notice window is dead (and kill it if it ain't)
330 #------------------------------------------------------------------------------
331 ps $info_message_pid >/dev/null 2>&1
332 if [ $? -ne 0 ] ; then
333 wait $info_message_pid
337 kill $info_message_pid
340 #------------------------------------------------------------------------------
341 # If they didn't like the warning window, turn it off
342 #------------------------------------------------------------------------------
343 if [ $info_return -eq 3 ] ; then
344 $XMESSAGE -title "Wine Prelaunch Control" \
345 "Wine will now disable the prelaunch Window you just saw.
346 You will no longer be notified when Wine is attempting
347 to start a Windows application.
349 You can reenable this Window by removing the $info_flag file." -buttons " Okay ":0," Cancel ":1
350 if [ $? -eq 0 ] ; then
358 #------------------------------------------------------------------------------
359 # Generate a temporary log file name
360 #------------------------------------------------------------------------------
361 if [ -n "$TMP" ] ; then
367 log_name=`mktemp "$log_dir/wine.log.XXXXXX"`
368 if [ $? -eq 0 ] ; then
372 status_name=`mktemp "$log_dir/wine.status.XXXXXX"`
373 if [ $? -eq 0 ] ; then
377 #------------------------------------------------------------------------------
378 # Okay, really launch Wine...
379 #------------------------------------------------------------------------------
380 if [ $use_log_name -ne 0 -a $use_status_name -ne 0 ] ; then
381 ( $WINEBIN/$WINE_BIN_NAME "$@"; echo $? >$status_name ) 2>&1 | tee "$log_name"
382 wine_return=`cat $status_name`
384 $WINEBIN/$WINE_BIN_NAME "$@"
387 if [ $use_status_name -ne 0 ] ; then
391 #------------------------------------------------------------------------------
392 # Test the return code, and see if it fails
393 #------------------------------------------------------------------------------
394 if [ $always_see_output -eq 0 -a $wine_return -eq 0 ] ; then
395 echo "Wine exited with a successful status"
396 if [ $use_log_name -ne 0 ] ; then
400 if [ $always_see_output -eq 0 ] ; then
401 echo "Wine failed with return code $wine_return"
404 #------------------------------------------------------------------------------
405 # Gracefully display a debug message if they like...
406 #------------------------------------------------------------------------------
407 while [ $use_debug_message -gt 0 ] ; do
409 #------------------------------------------------------------------------------
410 # Build up the menu of choices they can make...
411 #------------------------------------------------------------------------------
413 if [ $use_log_name -ne 0 ] ; then
414 BUTTONS="$BUTTONS"', View Log :1'
417 BUTTONS="$BUTTONS"', Debug :2'
418 BUTTONS="$BUTTONS"', Configure :4'
419 BUTTONS="$BUTTONS"', Disable :3'
421 #------------------------------------------------------------------------------
422 # Build an error message
423 #------------------------------------------------------------------------------
425 Wine has exited with a failure status of $wine_return.
427 Wine is still development software, so there can be many
428 explanations for this problem.
430 You can choose to run Wine again with a higher level
431 of debug messages (the debug option, below).
433 You can attempt to reconfigure Wine to make it work better.
434 Note that one change you can make that will dramatically
435 effect Wine's behaviour is to change whether or not
436 Wine uses a true Windows partition, mounted under Linux,
437 or whether it uses an empty Windows directory.
438 The Wine Configuration program can assist you in making
439 those changes (select Configure, below, for more).
441 You can disable this message entirely by selecting the
442 Disable option below."
444 if [ $always_see_output -ne 0 -a $wine_return -eq 0 ] ; then
446 Wine has exited with a failure status of $wine_return.
448 You can disable this message entirely by selecting the
449 Disable option below."
453 if [ $use_log_name -ne 0 ] ; then
456 Wine has captured a log of the Wine output in the file $log_name.
457 You may view this file by selecting View Log, below."
460 #------------------------------------------------------------------------------
461 # Display the message
462 #------------------------------------------------------------------------------
463 $XMESSAGE -title "Wine Finished With Error" -buttons "$BUTTONS" "$MESSAGE"
466 #------------------------------------------------------------------------------
467 # Dismiss the other window...
468 #------------------------------------------------------------------------------
469 clean_up_info_message
471 #------------------------------------------------------------------------------
472 # Process a configure instruction
473 #------------------------------------------------------------------------------
474 if [ $debug_return -eq 4 ] ; then
476 if [ $? -eq 0 ] ; then
479 if [ -x /opt/wine/bin/winesetup ] ; then
480 /opt/wine/bin/winesetup
482 $XMESSAGE -title "Error" "Error: Unable to find winesetup in your PATH or in /opt/wine/bin"
488 #------------------------------------------------------------------------------
489 # Process a view instruction
490 #------------------------------------------------------------------------------
491 if [ $debug_return -eq 1 ] ; then
492 $XMESSAGE -title "View Wine Log" -file "$log_name" -buttons " Okay ":0,"Delete $log_name":1
493 if [ $? -eq 1 ] ; then
494 echo "Deleting $log_name"
502 #------------------------------------------------------------------------------
503 # If they didn't like the warning window, turn it off
504 #------------------------------------------------------------------------------
505 if [ $debug_return -eq 3 ] ; then
506 $XMESSAGE -title "Wine Debug Log Control" \
507 "Wine will now disable the Wine debug output control window you just saw.
508 You will no longer be notified when Wine fails to start a
511 You can reenable this Window by removing the $debug_flag file." -buttons " Okay ":0," Cancel ":1
513 if [ $? -eq 0 ] ; then
519 #------------------------------------------------------------------------------
520 # If they want to retry with debug, let 'em.
521 #------------------------------------------------------------------------------
522 if [ $debug_return -eq 2 ] ; then
523 echo "Rerunning $0 $debug_options $@"
524 exec $0 $debug_options "$@"
530 clean_up_info_message
533 if [ $wine_return -ge 128 ]; then
534 # try to kill myself with the same signal
535 kill -$[wine_return - 128] $$
536 # if we get here the kill didn't work