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 # This library is free software; you can redistribute it and/or
19 # modify it under the terms of the GNU Lesser General Public
20 # License as published by the Free Software Foundation; either
21 # version 2.1 of the License, or (at your option) any later version.
23 # This library is distributed in the hope that it will be useful,
24 # but WITHOUT ANY WARRANTY; without even the implied warranty of
25 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
26 # Lesser General Public License for more details.
28 # You should have received a copy of the GNU Lesser General Public
29 # License along with this library; if not, write to the Free Software
30 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
31 #------------------------------------------------------------------------------
33 #------------------------------------------------------------------------------
34 # Primary configuration area - change this if you installed Wine to
35 # a different location
36 #------------------------------------------------------------------------------
42 #------------------------------------------------------------------------------
43 # Establish Color Scheme
44 #------------------------------------------------------------------------------
45 COLOR=' -xrm *.Command.background:darkgrey
46 -xrm *.Command.foreground:black
47 -xrm *.Text.background:black
48 -xrm *.Text.foreground:green
49 -xrm *.Form.background:grey
50 -xrm *.Form.foreground:green
51 -xrm *.foreground:green
52 -xrm *.background:black'
55 #------------------------------------------------------------------------------
56 # Locate either xmessage or gmessage, if we can.
57 #------------------------------------------------------------------------------
58 type xmessage >/dev/null 2>/dev/null
59 if [ $? -ne 0 ] ; then
62 The Wine launcher is unable to find xmessage.
64 This launcher script relies heavily on finding this tool,
65 and without it, it will behave poorly.
67 Most Linux distributions have one or the other of these
70 We strongly recommend that you use your distribution's
71 software methods to locate xmessage."
74 XMESSAGE="xmessage $COLOR"
78 #------------------------------------------------------------------------------
79 # We're going to do a lot of fancy footwork below.
80 # Before we get started, it would be nice to know the argv0
81 # of the actual script we're running (and lets remove at least
82 # one level of symlinking).
83 #------------------------------------------------------------------------------
85 if [ -z $argv0_path ] ; then
89 real_name=`find $argv0_path -type l -printf "%l\n"`
90 if [ ! $real_name ]; then
92 elif [ ! -x $real_name ]; then
93 real_name=`find $argv0_path -printf "%h\n"`/$real_name
96 argv0_dir=`find $real_name -printf "%h\n"`
98 if [ -z $argv0_dir ] ; then
102 #------------------------------------------------------------------------------
103 # Okay, now all that junk above was established at configure time.
104 # However, if this is an RPM install, they may have chosen
105 # to relocate this installation. If so, that stuff above
106 # is all broken and we should rejigger it.
107 #------------------------------------------------------------------------------
108 WINE_BIN_NAME=wine.bin
109 if [ ! -x $WINEBIN/$WINE_BIN_NAME ] ; then
110 WINEBIN=`find $argv0_dir -maxdepth 1 -perm +0111 -type f -name "$WINE_BIN_NAME" -printf "%h\n" | head -1`
113 if [ ! -x $WINEBIN/$WINE_BIN_NAME ] ; then
114 WINEBIN=`find $argv0_dir/../ -maxdepth 1 -perm +0111 -type f -name "$WINE_BIN_NAME" -printf "%h\n" | head -1`
117 if [ ! -x $WINEBIN/$WINE_BIN_NAME ] ; then
119 if [ ! -x $WINEBIN/$WINE_BIN_NAME ] ; then
120 WINEBIN=`find $argv0_dir -maxdepth 1 -perm +0111 -type f -name "$WINE_BIN_NAME" -printf "%h\n" | head -1`
123 if [ ! -x $WINEBIN/$WINE_BIN_NAME ] ; then
124 WINEBIN=`find $argv0_dir/../ -maxdepth 1 -perm +0111 -type f -name "$WINE_BIN_NAME" -printf "%h\n" | head -1`
128 if [ ! -r $WINELIB/libwine.so ] ; then
129 WINELIB=`find $argv0_dir -maxdepth 2 -name 'libwine.so' -printf "%h\n" | head -1`
132 if [ ! -r $WINELIB/libwine.so ] ; then
133 WINELIB=`find $argv0_dir/../ -maxdepth 2 -name 'libwine.so' -printf "%h\n" | head -1`
136 if [ -x $WINEBIN/wineserver ] ; then
137 WINESERVER=$WINEBIN/wineserver
140 #------------------------------------------------------------------------------
141 # Hey, if we built Wine from source, let's add a little extra fun to
143 #------------------------------------------------------------------------------
144 if [ -x $WINEBIN/server/wineserver ] ; then
145 WINESERVER=$WINEBIN/server/wineserver
148 if [ -r $WINELIB/dlls/ntdll.dll.so ] ; then
149 WINEDLLPATH=$WINELIB/dlls
153 #------------------------------------------------------------------------------
154 # Okay, set the paths and move on.
155 #------------------------------------------------------------------------------
156 export LD_LIBRARY_PATH=$WINELIB:$LD_LIBRARY_PATH
157 export PATH=$WINEBIN:$PATH
158 export WINELOADER=$WINEBIN/$WINE_BIN_NAME
162 info_flag=~/.wine/.no_prelaunch_window_flag
163 debug_flag=~/.wine/.no_debug_window_flag
164 debug_options="-debugmsg warn+all"
166 if [ -f $info_flag ] ; then
172 if [ -f $debug_flag ] ; then
179 #------------------------------------------------------------------------------
180 # Handle winelib apps going through here
181 #------------------------------------------------------------------------------
183 if [ -f $argv0_path.so ] ; then
185 export WINEPRELOAD=$argv0_path.so
189 #------------------------------------------------------------------------------
190 # No arguments? Help 'em out
191 #------------------------------------------------------------------------------
194 if [ $# -eq 0 ] ; then
198 if [ $# -eq 1 -a "$1" = "" ] ; then
202 if [ $winelib -eq 1 ] ; then
206 if [ $no_args -eq 1 ] ; then
207 echo "Wine called with no arguments."
208 echo "Invoking $WINEBIN/$WINE_BIN_NAME $@ ..."
209 $XMESSAGE -buttons " Okay ":0," See the Wine Usage Statement ":1," Configure Wine ":2 \
210 -title "Welcome to Wine" \
213 You have started Wine without specifying any arguments.
215 Wine requires a least one argument - the name of the Windows
216 application you would like to run.
218 If you have launched this through the KDE menu system,
219 you can use the KDE file browser to select a Windows
220 exectuable and then click on it to launch Wine with
223 You can similarly use the GNOME file manager to
224 select a Windows executable and double click on it.
226 If you would like to see the command line arguments
227 for Wine, select the second option, below.
231 if [ $welcome_rc -eq 0 ] ; then
235 if [ $welcome_rc -eq 2 ] ; then
237 if [ $? -eq 0 ] ; then
240 if [ -x /opt/wine/bin/winesetup ] ; then
241 /opt/wine/bin/winesetup
243 $XMESSAGE -title "Error" "Error: Unable to find winesetup in your PATH or in /opt/wine/bin"
253 #------------------------------------------------------------------------------
254 # No config file? Offer to help 'em out...
255 #------------------------------------------------------------------------------
258 while [ $conf -eq 0 ] ; do
260 if [ -f ~/.winerc ] ; then
263 if [ -f ~/.wine/config ] ; then
266 if [ -f /etc/wine.conf ] ; then
270 if [ $conf -ne 0 ] ; then
274 echo "No configuration file detected."
275 $XMESSAGE -buttons " Cancel ":0," Proceed ":1," Configure Wine ":2 \
276 -title "Welcome to Wine" \
279 You have started Wine but we cannot find a Wine
282 This is normal if you have never run Wine before.
283 If this is the case, select the 'Configure Wine'
284 option, below, to create a configuration file.
288 if [ $init_rc -eq 0 ] ; then
292 if [ $init_rc -eq 1 ] ; then
296 if [ $init_rc -eq 2 ] ; then
298 if [ $? -eq 0 ] ; then
301 if [ -x /opt/wine/bin/winesetup ] ; then
302 /opt/wine/bin/winesetup
304 $XMESSAGE -title "Error" "Error: Unable to find winesetup in your PATH or in /opt/wine/bin"
311 #------------------------------------------------------------------------------
312 # Optionally Warn the user we're going to be launching Wine...
313 #------------------------------------------------------------------------------
314 if [ $use_info_message -ne 0 ] ; then
315 echo "Invoking $WINEBIN/$WINE_BIN_NAME $@ ..."
316 $XMESSAGE -timeout 30 -buttons " Dismiss ":0," Never display this message again ":3 \
317 -title "Wine Launch Window" \
318 "Invoking $WINEBIN/$WINE_BIN_NAME $@ ...
320 This dialog box is a temporary status dialog to let you know
321 that Wine is attempting to launch your application.
323 Since Wine is still very much in a development stage, many
324 applications will fail silently. This dialog box is your indication
325 that we're *trying* to run your application.
327 This dialog box will automatically disappear after 30 seconds,
328 or after your application finishes.
330 You can permanently disable this dialog by selecting the option below.
335 #------------------------------------------------------------------------------
336 # Here's a little function to clean up after that dialog...
337 #------------------------------------------------------------------------------
338 clean_up_info_message ()
340 if [ $use_info_message -ne 0 ] ; then
342 #------------------------------------------------------------------------------
343 # Okay, make sure that the notice window is dead (and kill it if it ain't)
344 #------------------------------------------------------------------------------
345 ps $info_message_pid >/dev/null 2>&1
346 if [ $? -ne 0 ] ; then
347 wait $info_message_pid
351 kill $info_message_pid
354 #------------------------------------------------------------------------------
355 # If they didn't like the warning window, turn it off
356 #------------------------------------------------------------------------------
357 if [ $info_return -eq 3 ] ; then
358 $XMESSAGE -title "Wine Prelaunch Control" \
359 "Wine will now disable the prelaunch Window you just saw.
360 You will no longer be notified when Wine is attempting
361 to start a Windows application.
363 You can reenable this Window by removing the $info_flag file." -buttons " Okay ":0," Cancel ":1
364 if [ $? -eq 0 ] ; then
372 #------------------------------------------------------------------------------
373 # Generate a temporary log file name
374 #------------------------------------------------------------------------------
375 if [ -n "$TMP" ] ; then
381 log_name=`mktemp "$log_dir/wine.log.XXXXXX"`
382 if [ $? -eq 0 ] ; then
386 status_name=`mktemp "$log_dir/wine.status.XXXXXX"`
387 if [ $? -eq 0 ] ; then
391 #------------------------------------------------------------------------------
392 # Okay, really launch Wine...
393 #------------------------------------------------------------------------------
394 if [ $use_log_name -ne 0 -a $use_status_name -ne 0 ] ; then
395 ( $WINEBIN/$WINE_BIN_NAME "$@"; echo $? >$status_name ) 2>&1 | tee "$log_name"
396 wine_return=`cat $status_name`
398 $WINEBIN/$WINE_BIN_NAME "$@"
401 if [ $use_status_name -ne 0 ] ; then
405 #------------------------------------------------------------------------------
406 # Test the return code, and see if it fails
407 #------------------------------------------------------------------------------
408 if [ $always_see_output -eq 0 -a $wine_return -eq 0 ] ; then
409 echo "Wine exited with a successful status"
410 if [ $use_log_name -ne 0 ] ; then
414 if [ $always_see_output -eq 0 ] ; then
415 echo "Wine failed with return code $wine_return"
418 #------------------------------------------------------------------------------
419 # Gracefully display a debug message if they like...
420 #------------------------------------------------------------------------------
421 while [ $use_debug_message -gt 0 ] ; do
423 #------------------------------------------------------------------------------
424 # Build up the menu of choices they can make...
425 #------------------------------------------------------------------------------
427 if [ $use_log_name -ne 0 ] ; then
428 BUTTONS="$BUTTONS"', View Log :1'
431 BUTTONS="$BUTTONS"', Debug :2'
432 BUTTONS="$BUTTONS"', Configure :4'
433 BUTTONS="$BUTTONS"', Disable :3'
435 #------------------------------------------------------------------------------
436 # Build an error message
437 #------------------------------------------------------------------------------
439 Wine has exited with a failure status of $wine_return.
441 Wine is still development software, so there can be many
442 explanations for this problem.
444 You can choose to run Wine again with a higher level
445 of debug messages (the debug option, below).
447 You can attempt to reconfigure Wine to make it work better.
448 Note that one change you can make that will dramatically
449 effect Wine's behaviour is to change whether or not
450 Wine uses a true Windows partition, mounted under Linux,
451 or whether it uses an empty Windows directory.
452 The Wine Configuration program can assist you in making
453 those changes (select Configure, below, for more).
455 You can disable this message entirely by selecting the
456 Disable option below."
458 if [ $always_see_output -ne 0 -a $wine_return -eq 0 ] ; then
460 Wine has exited with a failure status of $wine_return.
462 You can disable this message entirely by selecting the
463 Disable option below."
467 if [ $use_log_name -ne 0 ] ; then
470 Wine has captured a log of the Wine output in the file $log_name.
471 You may view this file by selecting View Log, below."
474 #------------------------------------------------------------------------------
475 # Display the message
476 #------------------------------------------------------------------------------
477 $XMESSAGE -title "Wine Finished With Error" -buttons "$BUTTONS" "$MESSAGE"
480 #------------------------------------------------------------------------------
481 # Dismiss the other window...
482 #------------------------------------------------------------------------------
483 clean_up_info_message
485 #------------------------------------------------------------------------------
486 # Process a configure instruction
487 #------------------------------------------------------------------------------
488 if [ $debug_return -eq 4 ] ; then
490 if [ $? -eq 0 ] ; then
493 if [ -x /opt/wine/bin/winesetup ] ; then
494 /opt/wine/bin/winesetup
496 $XMESSAGE -title "Error" "Error: Unable to find winesetup in your PATH or in /opt/wine/bin"
502 #------------------------------------------------------------------------------
503 # Process a view instruction
504 #------------------------------------------------------------------------------
505 if [ $debug_return -eq 1 ] ; then
506 $XMESSAGE -title "View Wine Log" -file "$log_name" -buttons " Okay ":0,"Delete $log_name":1
507 if [ $? -eq 1 ] ; then
508 echo "Deleting $log_name"
516 #------------------------------------------------------------------------------
517 # If they didn't like the warning window, turn it off
518 #------------------------------------------------------------------------------
519 if [ $debug_return -eq 3 ] ; then
520 $XMESSAGE -title "Wine Debug Log Control" \
521 "Wine will now disable the Wine debug output control window you just saw.
522 You will no longer be notified when Wine fails to start a
525 You can reenable this Window by removing the $debug_flag file." -buttons " Okay ":0," Cancel ":1
527 if [ $? -eq 0 ] ; then
533 #------------------------------------------------------------------------------
534 # If they want to retry with debug, let 'em.
535 #------------------------------------------------------------------------------
536 if [ $debug_return -eq 2 ] ; then
537 echo "Rerunning $0 $debug_options $@"
538 exec $0 $debug_options "$@"
544 clean_up_info_message
547 if [ $wine_return -ge 128 ]; then
548 # try to kill myself with the same signal
549 kill -$[wine_return - 128] $$
550 # if we get here the kill didn't work