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 #------------------------------------------------------------------------------
77 real_name
=`find $0 -type l -printf "%l\n"`
78 if [ ! $real_name ]; then
81 argv0_dir
=`find $real_name -printf "%h\n"`
83 if [ -z $argv0_dir ] ; then
87 #------------------------------------------------------------------------------
88 # Okay, now all that junk above was established at configure time.
89 # However, if this is an RPM install, they may have chosen
90 # to relocate this installation. If so, that stuff above
91 # is all broken and we should rejigger it.
92 #------------------------------------------------------------------------------
93 WINE_BIN_NAME
=wine.bin
94 if [ ! -x $WINEBIN/$WINE_BIN_NAME ] ; then
95 WINEBIN
=`find $argv0_dir -maxdepth 1 -perm +0111 -type f -name "$WINE_BIN_NAME" -printf "%h\n" | head -1`
98 if [ ! -x $WINEBIN/$WINE_BIN_NAME ] ; then
99 WINEBIN
=`find $argv0_dir/../ -maxdepth 1 -perm +0111 -type f -name "$WINE_BIN_NAME" -printf "%h\n" | head -1`
102 if [ ! -x $WINEBIN/$WINE_BIN_NAME ] ; then
104 if [ ! -x $WINEBIN/$WINE_BIN_NAME ] ; then
105 WINEBIN
=`find $argv0_dir -maxdepth 1 -perm +0111 -type f -name "$WINE_BIN_NAME" -printf "%h\n" | head -1`
108 if [ ! -x $WINEBIN/$WINE_BIN_NAME ] ; then
109 WINEBIN
=`find $argv0_dir/../ -maxdepth 1 -perm +0111 -type f -name "$WINE_BIN_NAME" -printf "%h\n" | head -1`
113 if [ ! -r $WINELIB/libwine.so
] ; then
114 WINELIB
=`find $argv0_dir -maxdepth 2 -name 'libwine.so' -printf "%h\n" | head -1`
117 if [ ! -r $WINELIB/libwine.so
] ; then
118 WINELIB
=`find $argv0_dir/../ -maxdepth 2 -name 'libwine.so' -printf "%h\n" | head -1`
121 if [ -x $WINEBIN/wineserver
] ; then
122 WINESERVER
=$WINEBIN/wineserver
125 #------------------------------------------------------------------------------
126 # Hey, if we built Wine from source, let's add a little extra fun to
128 #------------------------------------------------------------------------------
129 if [ -x $WINEBIN/server
/wineserver
] ; then
130 WINESERVER
=$WINEBIN/server
/wineserver
133 if [ -r $WINELIB/dlls
/libuser.so
] ; then
134 WINELIBDLLS
=$WINELIB/dlls
138 #------------------------------------------------------------------------------
139 # Okay, set the paths and move on.
140 #------------------------------------------------------------------------------
141 export LD_LIBRARY_PATH
=$WINELIB:$WINELIBDLLS:$LD_LIBRARY_PATH
142 export PATH
=$WINEBIN:$PATH
143 export WINEDLLPATH
=$WINELIBDLLS
144 export WINELOADER
=$WINEBIN/$WINE_BIN_NAME
146 info_flag
=~
/.wine
/.no_prelaunch_window_flag
147 debug_flag
=~
/.wine
/.no_debug_window_flag
148 debug_options
="-debugmsg warn+all"
150 if [ -f $info_flag ] ; then
156 if [ -f $debug_flag ] ; then
163 #------------------------------------------------------------------------------
164 # No arguments? Help 'em out
165 #------------------------------------------------------------------------------
168 if [ $# -eq 0 ] ; then
172 if [ $# -eq 1 -a foo
$1 = foo
] ; then
176 if [ $no_args -eq 1 ] ; then
177 echo "Wine called with no arguments."
178 echo "Invoking $WINEBIN/$WINE_BIN_NAME $@ ..."
179 $XMESSAGE -buttons " Okay ":0," See the Wine Usage Statement ":1," Configure Wine ":2 \
180 -title "Welcome to Wine" \
183 You have started Wine without specifying any arguments.
185 Wine requires a least one argument - the name of the Windows
186 application you would like to run.
188 If you have launched this through the KDE menu system,
189 you can use the KDE file browser to select a Windows
190 exectuable and then click on it to launch Wine with
193 You can similarly use the GNOME file manager to
194 select a Windows executable and double click on it.
196 If you would like to see the command line arguments
197 for Wine, select the second option, below.
201 if [ $welcome_rc -eq 0 ] ; then
205 if [ $welcome_rc -eq 2 ] ; then
207 if [ $?
-eq 0 ] ; then
210 if [ -x /opt
/wine
/bin
/winesetup
] ; then
211 /opt
/wine
/bin
/winesetup
213 $XMESSAGE -title "Error" "Error: Unable to find winesetup in your PATH or in /opt/wine/bin"
223 #------------------------------------------------------------------------------
224 # No config file? Offer to help 'em out...
225 #------------------------------------------------------------------------------
228 while [ $conf -eq 0 ] ; do
230 if [ -f ~
/.winerc
] ; then
233 if [ -f ~
/.wine
/config
] ; then
236 if [ -f /etc
/wine.conf
] ; then
240 if [ $conf -ne 0 ] ; then
244 echo "No configuration file detected."
245 $XMESSAGE -buttons " Cancel ":0," Proceed ":1," Configure Wine ":2 \
246 -title "Welcome to Wine" \
249 You have started Wine but we cannot find a Wine
252 This is normal if you have never run Wine before.
253 If this is the case, select the 'Configure Wine'
254 option, below, to create a configuration file.
258 if [ $init_rc -eq 0 ] ; then
262 if [ $init_rc -eq 1 ] ; then
266 if [ $init_rc -eq 2 ] ; then
268 if [ $?
-eq 0 ] ; then
271 if [ -x /opt
/wine
/bin
/winesetup
] ; then
272 /opt
/wine
/bin
/winesetup
274 $XMESSAGE -title "Error" "Error: Unable to find winesetup in your PATH or in /opt/wine/bin"
281 #------------------------------------------------------------------------------
282 # Optionally Warn the user we're going to be launching Wine...
283 #------------------------------------------------------------------------------
284 if [ $use_info_message -ne 0 ] ; then
285 echo "Invoking $WINEBIN/$WINE_BIN_NAME $@ ..."
286 $XMESSAGE -timeout 30 -buttons " Dismiss ":0," Never display this message again ":3 \
287 -title "Wine Launch Window" \
288 "Invoking $WINEBIN/$WINE_BIN_NAME $@ ...
290 This dialog box is a temporary status dialog to let you know
291 that Wine is attempting to launch your application.
293 Since Wine is still very much in a development stage, many
294 applications will fail silently. This dialog box is your indication
295 that we're *trying* to run your application.
297 This dialog box will automatically disappear after 30 seconds,
298 or after your application finishes.
300 You can permanently disable this dialog by selecting the option below.
305 #------------------------------------------------------------------------------
306 # Here's a little function to clean up after that dialog...
307 #------------------------------------------------------------------------------
308 clean_up_info_message
()
310 if [ $use_info_message -ne 0 ] ; then
312 #------------------------------------------------------------------------------
313 # Okay, make sure that the notice window is dead (and kill it if it ain't)
314 #------------------------------------------------------------------------------
315 ps
$info_message_pid >/dev
/null
2>&1
316 if [ $?
-ne 0 ] ; then
317 wait $info_message_pid
321 kill $info_message_pid
324 #------------------------------------------------------------------------------
325 # If they didn't like the warning window, turn it off
326 #------------------------------------------------------------------------------
327 if [ $info_return -eq 3 ] ; then
328 $XMESSAGE -title "Wine Prelaunch Control" \
329 "Wine will now disable the prelaunch Window you just saw.
330 You will no longer be notified when Wine is attempting
331 to start a Windows application.
333 You can reenable this Window by removing the $info_flag file." -buttons " Okay ":0," Cancel ":1
334 if [ $?
-eq 0 ] ; then
342 #------------------------------------------------------------------------------
343 # Generate a temporary log file name
344 #------------------------------------------------------------------------------
346 log_name
=`mktemp /tmp/wine.log.XXXXXX`
347 if [ $?
-eq 0 ] ; then
348 which tail >/dev
/null
2>&1
349 if [ $?
-eq 0 ]; then
354 #------------------------------------------------------------------------------
355 # Okay, really launch Wine...
356 #------------------------------------------------------------------------------
357 if [ $use_log_name -ne 0 ] ; then
358 #------------------------------------------------------------------------------
359 # Okay, we bend over backwards to run Wine, get that status,
360 # but still display its output to the screen.
361 # The obvious thing to do is to run wine and pipe output to tee,
362 # but then I can't find a way to get the return code of wine;
363 # I only get the return code of tee.
364 #------------------------------------------------------------------------------
365 $WINEBIN/$WINE_BIN_NAME "$@" >$log_name 2>&1 &
376 $WINEBIN/$WINE_BIN_NAME "$@"
380 #------------------------------------------------------------------------------
381 # Test the return code, and see if it fails
382 #------------------------------------------------------------------------------
383 if [ $always_see_output -eq 0 -a $wine_return -eq 0 ] ; then
384 echo "Wine exited with a successful status"
385 if [ $use_log_name -ne 0 ] ; then
389 if [ $always_see_output -eq 0 ] ; then
390 echo "Wine failed with return code $wine_return"
393 #------------------------------------------------------------------------------
394 # Gracefully display a debug message if they like...
395 #------------------------------------------------------------------------------
396 while [ $use_debug_message -gt 0 ] ; do
398 #------------------------------------------------------------------------------
399 # Build up the menu of choices they can make...
400 #------------------------------------------------------------------------------
402 if [ $use_log_name -ne 0 ] ; then
403 BUTTONS
="$BUTTONS"', View Log :1'
406 BUTTONS
="$BUTTONS"', Debug :2'
407 BUTTONS
="$BUTTONS"', Configure :4'
408 BUTTONS
="$BUTTONS"', Disable :3'
410 #------------------------------------------------------------------------------
411 # Build an error message
412 #------------------------------------------------------------------------------
414 Wine has exited with a failure status of $wine_return.
416 Wine is still development software, so there can be many
417 explanations for this problem.
419 You can choose to run Wine again with a higher level
420 of debug messages (the debug option, below).
422 You can attempt to reconfigure Wine to make it work better.
423 Note that one change you can make that will dramatically
424 effect Wine's behaviour is to change whether or not
425 Wine uses a true Windows partition, mounted under Linux,
426 or whether it uses an empty Windows directory.
427 The Wine Configuration program can assist you in making
428 those changes (select Configure, below, for more).
430 You can disable this message entirely by selecting the
431 Disable option below."
433 if [ $always_see_output -ne 0 -a $wine_return -eq 0 ] ; then
435 Wine has exited with a failure status of $wine_return.
437 You can disable this message entirely by selecting the
438 Disable option below."
442 if [ $use_log_name -ne 0 ] ; then
445 Wine has captured a log of the Wine output in the file $log_name.
446 You may view this file by selecting View Log, below."
449 #------------------------------------------------------------------------------
450 # Display the message
451 #------------------------------------------------------------------------------
452 $XMESSAGE -title "Wine Finished With Error" -buttons "$BUTTONS" "$MESSAGE"
455 #------------------------------------------------------------------------------
456 # Dismiss the other window...
457 #------------------------------------------------------------------------------
458 clean_up_info_message
460 #------------------------------------------------------------------------------
461 # Process a configure instruction
462 #------------------------------------------------------------------------------
463 if [ $debug_return -eq 4 ] ; then
465 if [ $?
-eq 0 ] ; then
468 if [ -x /opt
/wine
/bin
/winesetup
] ; then
469 /opt
/wine
/bin
/winesetup
471 $XMESSAGE -title "Error" "Error: Unable to find winesetup in your PATH or in /opt/wine/bin"
477 #------------------------------------------------------------------------------
478 # Process a view instruction
479 #------------------------------------------------------------------------------
480 if [ $debug_return -eq 1 ] ; then
481 $XMESSAGE -title "View Wine Log" -file $log_name -buttons " Okay ":0,"Delete $log_name":1
482 if [ $?
-eq 1 ] ; then
483 echo "Deleting $log_name"
491 #------------------------------------------------------------------------------
492 # If they didn't like the warning window, turn it off
493 #------------------------------------------------------------------------------
494 if [ $debug_return -eq 3 ] ; then
495 $XMESSAGE -title "Wine Debug Log Control" \
496 "Wine will now disable the Wine debug output control window you just saw.
497 You will no longer be notified when Wine fails to start a
500 You can reenable this Window by removing the $debug_flag file." -buttons " Okay ":0," Cancel ":1
502 if [ $?
-eq 0 ] ; then
508 #------------------------------------------------------------------------------
509 # If they want to retry with debug, let 'em.
510 #------------------------------------------------------------------------------
511 if [ $debug_return -eq 2 ] ; then
512 echo "Rerunning $0 $debug_options $@"
513 exec $0 $debug_options $@
519 clean_up_info_message