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
60 # xmessage not found; make sure the user notices this error
61 # (GUI users wouldn't even notice if we printed the text on console !)
62 MSGFILE=/tmp/WINE_CANNOT_FIND_XMESSAGE
65 The Wine launcher is unable to find the xmessage program,
66 which it needs to properly notify you of Wine execution status
69 This launcher script relies heavily on finding this tool,
70 and without it, it will behave very poorly.
72 We strongly recommend that you use your distribution's
73 software methods to locate xmessage, or alternatively
74 use your favourite internet search engine to find out
75 how you are supposed to install xmessage on your system.
78 # try to display message file with tons of different X11 editors
79 # until we find one that's installed and working
80 for EDITPRG in nedit gedit kedit gvim xemacs; do
81 type $EDITPRG >/dev/null 2>/dev/null
82 if [ $? -eq 0 ] ; then
83 # execute editor and exit if successful
84 $EDITPRG $MSGFILE && exit
88 # ok, we really give up now, this system is hosed ;-)
91 XMESSAGE="xmessage $COLOR"
97 if [ $? -eq 0 ] ; then
100 if [ -x /opt/wine/bin/winesetup ] ; then
101 /opt/wine/bin/winesetup
103 $XMESSAGE -title "Error" \
104 "Error: Unable to find winesetup in your PATH or in /opt/wine/bin:
105 I am not able to configure Wine.
107 If winesetup is being distributed in a separate package
108 that is not installed yet on your system, then please install this
110 winesetup can also be downloaded from www.codeweavers.com.
112 If you choose to not use winesetup for configuration, then
113 you can find information on how to prepare a Wine config file manually
114 in the Wine README / README.gz file or in the Wine User Guide."
119 #------------------------------------------------------------------------------
120 # We're going to do a lot of fancy footwork below.
121 # Before we get started, it would be nice to know the argv0
122 # of the actual script we're running (and lets remove at least
123 # one level of symlinking).
124 #------------------------------------------------------------------------------
125 argv0_path=`which $0`
126 if [ -z $argv0_path ] ; then
130 real_name=`find $argv0_path -type l -printf "%l\n"`
131 if [ ! $real_name ]; then
132 real_name=$argv0_path
133 elif [ ! -x $real_name ]; then
134 real_name=`find $argv0_path -printf "%h\n"`/$real_name
137 argv0_dir=`find $real_name -printf "%h\n"`
139 if [ -z $argv0_dir ] ; then
143 #------------------------------------------------------------------------------
144 # Okay, now all that junk above was established at configure time.
145 # However, if this is an RPM install, they may have chosen
146 # to relocate this installation. If so, that stuff above
147 # is all broken and we should rejigger it.
148 #------------------------------------------------------------------------------
149 WINE_BIN_NAME=wine.bin
150 if [ ! -x $WINEBIN/$WINE_BIN_NAME ] ; then
151 WINEBIN=`find $argv0_dir -maxdepth 1 -perm +0111 -type f -name "$WINE_BIN_NAME" -printf "%h\n" | head -n 1`
154 if [ ! -x $WINEBIN/$WINE_BIN_NAME ] ; then
155 WINEBIN=`find $argv0_dir/../ -maxdepth 1 -perm +0111 -type f -name "$WINE_BIN_NAME" -printf "%h\n" | head -n 1`
158 if [ ! -x $WINEBIN/$WINE_BIN_NAME ] ; then
160 if [ ! -x $WINEBIN/$WINE_BIN_NAME ] ; then
161 WINEBIN=`find $argv0_dir -maxdepth 1 -perm +0111 -type f -name "$WINE_BIN_NAME" -printf "%h\n" | head -n 1`
164 if [ ! -x $WINEBIN/$WINE_BIN_NAME ] ; then
165 WINEBIN=`find $argv0_dir/../ -maxdepth 1 -perm +0111 -type f -name "$WINE_BIN_NAME" -printf "%h\n" | head -n 1`
169 if [ ! -r $WINELIB/libwine.so ] ; then
170 WINELIB=`find $argv0_dir -maxdepth 2 -name 'libwine.so' -printf "%h\n" | head -n 1`
173 if [ ! -r $WINELIB/libwine.so ] ; then
174 WINELIB=`find $argv0_dir/../ -maxdepth 2 -name 'libwine.so' -printf "%h\n" | head -n 1`
177 if [ -x $WINEBIN/wineserver ] ; then
178 WINESERVER=$WINEBIN/wineserver
181 #------------------------------------------------------------------------------
182 # Hey, if we built Wine from source, let's add a little extra fun to
184 #------------------------------------------------------------------------------
185 if [ -x $WINEBIN/server/wineserver ] ; then
186 WINESERVER=$WINEBIN/server/wineserver
189 if [ -r $WINELIB/dlls/ntdll.dll.so ] ; then
190 WINEDLLPATH=$WINELIB/dlls
194 #------------------------------------------------------------------------------
195 # Okay, set the paths and move on.
196 #------------------------------------------------------------------------------
197 export LD_LIBRARY_PATH=$WINELIB:$LD_LIBRARY_PATH
198 export PATH=$WINEBIN:$PATH
199 export WINELOADER=$WINEBIN/$WINE_BIN_NAME
203 info_flag=~/.wine/.no_prelaunch_window_flag
204 debug_flag=~/.wine/.no_debug_window_flag
205 debug_options="warn+all"
207 if [ -f $info_flag ] ; then
213 if [ -f $debug_flag ] ; then
220 #------------------------------------------------------------------------------
221 # Handle winelib apps going through here
222 #------------------------------------------------------------------------------
224 if [ -f $argv0_path.so ] ; then
226 export WINEPRELOAD=$argv0_path.so
230 #------------------------------------------------------------------------------
231 # No arguments? Help 'em out
232 #------------------------------------------------------------------------------
235 if [ $# -eq 0 ] ; then
239 if [ $# -eq 1 -a "$1" = "" ] ; then
243 if [ $winelib -eq 1 ] ; then
247 if [ $no_args -eq 1 ] ; then
248 echo "Wine called with no arguments."
249 echo "Invoking $WINEBIN/$WINE_BIN_NAME $@ ..."
250 $XMESSAGE -buttons " Okay ":0," See the Wine Usage Statement ":1," Configure Wine ":2 \
251 -title "Welcome to Wine" \
254 You have started Wine without specifying any arguments.
256 Wine requires at least one argument - the name of the Windows
257 application you would like to run.
259 If you have launched this through the KDE menu system
260 and your KDE installation is specially configured for Wine,
261 then you can use the KDE file browser to select a Windows
262 executable and then click on it to launch Wine with
265 You can similarly use the GNOME file manager to
266 select a Windows executable and double click on it.
268 If you would like to see the command line arguments
269 for Wine, select the second option, below.
273 if [ $welcome_rc -eq 0 ] ; then
277 if [ $welcome_rc -eq 2 ] ; then
286 #------------------------------------------------------------------------------
287 # No config file? Offer to help 'em out...
288 #------------------------------------------------------------------------------
291 while [ $conf -eq 0 ] ; do
293 if [ -f ~/.winerc ] ; then
296 if [ -f ~/.wine/config ] ; then
299 if [ -f /etc/wine.conf ] ; then
303 if [ $conf -ne 0 ] ; then
307 echo "No configuration file detected."
308 $XMESSAGE -buttons " Cancel ":0," Proceed ":1," Configure Wine ":2 \
309 -title "Welcome to Wine" \
312 You have started Wine, but we cannot find a Wine
315 This is normal if you have never run Wine before.
316 If this is the case, select the 'Configure Wine'
317 option, below, to create a configuration file.
321 if [ $init_rc -eq 0 ] ; then
325 if [ $init_rc -eq 1 ] ; then
329 if [ $init_rc -eq 2 ] ; then
333 # 127 == xmessage not available
334 if [ $init_rc -eq 127 ] ; then
340 #------------------------------------------------------------------------------
341 # Optionally Warn the user we're going to be launching Wine...
342 #------------------------------------------------------------------------------
343 if [ $use_info_message -ne 0 ] ; then
344 echo "Invoking $WINEBIN/$WINE_BIN_NAME $@ ..."
345 $XMESSAGE -timeout 30 -buttons " Dismiss ":0," Never display this message again ":3 \
346 -title "Wine Launch Window" \
347 "Invoking $WINEBIN/$WINE_BIN_NAME $@ ...
349 This dialog box is a temporary status dialog to let you know
350 that Wine is attempting to launch your application.
352 Since Wine is still very much in a development stage,
353 many applications will fail silently.
354 This dialog box is your indication
355 that we're *trying* to run your application.
357 This dialog box will automatically disappear after 30 seconds,
358 or after your application finishes.
360 You can permanently disable this dialog by selecting
366 #------------------------------------------------------------------------------
367 # Here's a little function to clean up after that dialog...
368 #------------------------------------------------------------------------------
369 clean_up_info_message ()
371 if [ $use_info_message -ne 0 ] ; then
373 #------------------------------------------------------------------------------
374 # Okay, make sure that the notice window is dead (and kill it if it ain't)
375 #------------------------------------------------------------------------------
376 ps $info_message_pid >/dev/null 2>&1
377 if [ $? -ne 0 ] ; then
378 wait $info_message_pid
382 kill $info_message_pid
385 #------------------------------------------------------------------------------
386 # If they didn't like the warning window, turn it off
387 #------------------------------------------------------------------------------
388 if [ $info_return -eq 3 ] ; then
389 $XMESSAGE -title "Wine Prelaunch Control" \
390 "Wine will now disable the prelaunch window you just saw.
391 You will no longer be notified when Wine is attempting
392 to start a Windows application.
394 Please take note that you can reenable this window
395 by removing the $info_flag file." -buttons " Okay ":0," Cancel ":1
396 if [ $? -eq 0 ] ; then
404 #------------------------------------------------------------------------------
405 # Generate a temporary log file name
406 #------------------------------------------------------------------------------
407 if [ -n "$TMP" ] ; then
413 log_name=`mktemp "$log_dir/wine.log.XXXXXX"`
414 if [ $? -eq 0 ] ; then
418 status_name=`mktemp "$log_dir/wine.status.XXXXXX"`
419 if [ $? -eq 0 ] ; then
423 #------------------------------------------------------------------------------
424 # Okay, really launch Wine...
425 #------------------------------------------------------------------------------
426 if [ $use_log_name -ne 0 -a $use_status_name -ne 0 ] ; then
427 ( $WINEBIN/$WINE_BIN_NAME "$@"; echo $? >$status_name ) 2>&1 | tee "$log_name"
428 wine_return=`cat $status_name`
430 $WINEBIN/$WINE_BIN_NAME "$@"
433 if [ $use_status_name -ne 0 ] ; then
437 #------------------------------------------------------------------------------
438 # Test the return code, and see if it fails
439 #------------------------------------------------------------------------------
440 if [ $always_see_output -eq 0 -a $wine_return -eq 0 ] ; then
441 echo "Wine exited with a successful status"
442 if [ $use_log_name -ne 0 ] ; then
446 if [ $always_see_output -eq 0 ] ; then
447 echo "Wine failed with return code $wine_return"
450 #------------------------------------------------------------------------------
451 # Gracefully display a debug message if they like...
452 #------------------------------------------------------------------------------
453 while [ $use_debug_message -gt 0 ] ; do
455 #------------------------------------------------------------------------------
456 # Build up the menu of choices they can make...
457 #------------------------------------------------------------------------------
459 if [ $use_log_name -ne 0 ] ; then
460 BUTTONS="$BUTTONS"', View Log :1'
463 BUTTONS="$BUTTONS"', Debug :2'
464 BUTTONS="$BUTTONS"', Configure :4'
465 BUTTONS="$BUTTONS"', Disable :3'
467 #------------------------------------------------------------------------------
468 # Build an error message
469 #------------------------------------------------------------------------------
471 Wine has exited with a failure status of $wine_return.
473 Wine is still development software, so there can be many
474 explanations for this problem.
476 You can choose to run Wine again with a higher level
477 of debug messages (the debug option, below).
479 You can attempt to reconfigure Wine to make it work better.
480 Note that one change you can make that will dramatically
481 effect Wine's behaviour is to change whether or not
482 Wine uses a true Windows partition, mounted under Linux,
483 or whether it uses an empty Windows directory.
484 The Wine Configuration program can assist you in making
485 those changes (select Configure, below, for more).
487 You can disable this message entirely by selecting the
488 Disable option below."
490 if [ $always_see_output -ne 0 -a $wine_return -eq 0 ] ; then
492 Wine has exited with a failure status of $wine_return.
494 You can disable this message entirely by selecting the
495 Disable option below."
499 if [ $use_log_name -ne 0 ] ; then
502 Wine has captured a log of the Wine output in the file $log_name.
503 You may view this file by selecting View Log, below."
506 #------------------------------------------------------------------------------
507 # Display the message
508 #------------------------------------------------------------------------------
509 $XMESSAGE -title "Wine Finished With Error" -buttons "$BUTTONS" "$MESSAGE"
512 #------------------------------------------------------------------------------
513 # Dismiss the other window...
514 #------------------------------------------------------------------------------
515 clean_up_info_message
517 #------------------------------------------------------------------------------
518 # Process a configure instruction
519 #------------------------------------------------------------------------------
520 if [ $debug_return -eq 4 ] ; then
525 #------------------------------------------------------------------------------
526 # Process a view instruction
527 #------------------------------------------------------------------------------
528 if [ $debug_return -eq 1 ] ; then
529 $XMESSAGE -title "View Wine Log" -file "$log_name" -buttons " Okay ":0,"Delete $log_name":1
530 if [ $? -eq 1 ] ; then
531 echo "Deleting $log_name"
539 #------------------------------------------------------------------------------
540 # If they didn't like the warning window, turn it off
541 #------------------------------------------------------------------------------
542 if [ $debug_return -eq 3 ] ; then
543 $XMESSAGE -title "Wine Debug Log Control" \
544 "Wine will now disable the Wine debug output control window you just saw.
545 You will no longer be notified when Wine fails to start a
548 Please take note that you can reenable this window
549 by removing the $debug_flag file." -buttons " Okay ":0," Cancel ":1
551 if [ $? -eq 0 ] ; then
557 #------------------------------------------------------------------------------
558 # If they want to retry with debug, let 'em.
559 #------------------------------------------------------------------------------
560 if [ $debug_return -eq 2 ] ; then
561 echo "Rerunning WINEDEBUG=$debug_options $0 $@"
562 WINEDEBUG=$debug_options exec $0 "$@"
568 clean_up_info_message
571 if [ $wine_return -ge 128 ]; then
572 # try to kill myself with the same signal
573 kill -$[wine_return - 128] $$
574 # if we get here the kill didn't work