- TRACE opened registry handles
[wine] / tools / wineinstall
1 #!/bin/bash
2 # WINE Installation script
3 # Can do almost everything from compiling to configuring...
4
5 # Mar 31 1999 - Ove Kåven
6 #  First version
7 # Dec 9 1999 - Ove Kåven
8 #  require Xpm
9 # Feb 25 2000 - Ove Kåven
10 #  auto-add /usr/local/lib to /etc/ld.so.conf
11 # Mar 2 2000 - Ove Kåven
12 #  source rather than grep config.cache
13 #  use sourced config.cache to start ldconfig
14 #  reconfigure if config.cache doesn't exist
15 # Mar 30 2000 - Ove Kåven
16 #  autoconfigure no-windows installs
17 #  do not install registry on real-windows installs
18 #  some support for binary package installs
19 #  set and tell user about LD_LIBRARY_PATH if necessary
20 #  set EXTRA_LD_LIBRARY_PATH in wine.conf
21 # Apr 9 2000 - Ove Kåven
22 #  make root's registry global (system-default)
23 # May 9 2000 - Ove Kåven
24 #  use ttydrv when running regapi, so we don't have to run from X
25 #  change debugger path in registry
26 # Oct 29 2000 - Ove Kåven
27 #  added --enable-opengl to default confargs
28 #  added conf_question, conf_yesno_answer, and conf_string_answer functions
29 #  added DEFCAT variable
30 # (later that day...)
31 #  added conf_reset_question function
32 #  added file existence checks to the registry copying
33 #  fixed problem with no-windows directory creation
34 #  some text reformatting from Eric Maryniak
35 # Jan 5 2000 - Chris Morgan
36 #  use default config file in /documentation/samples/config
37 #  replace .winerc with ~/.wine/config in printed text
38 #  added user question to convert .winerc file(if exists) or use the default
39 #    config file
40 #  add conf_question to allow root to install a local config file and
41 #    registry
42 # Jan 12 2000 - Chris Morgan
43 #  distinguish between creating local and global config files
44 #  display a message about the status of global config files
45 #  misc cleanups and reordering of questions
46 #  added check to see if wine is installed when we are running as a normal
47 #    user and print a message if wine cannot be found
48
49 #--- defaults (change these if you are a packager)
50 CONFARGS="--enable-opengl"    # configure args, e.g. --prefix=/usr --sysconfdir=/etc
51 prefix=/usr/local             # installation prefix
52 sysconfdir=$prefix/etc        # where wine.conf and global registry is supposed to be
53 bindir=$prefix/bin            # where winelib apps will be (or is) installed
54 libdir=$prefix/lib            # where libwine.so will be (or is) installed
55 exdir=documentation/samples   # where the example system.ini resides
56 GCONF=$sysconfdir/wine.conf   # default path of the wine.conf global config file
57 LCONF=~/.wine/config          # default path of the local config file
58 BINDIST=no                    # whether called from a binary package config script
59 DOGLOBALCONF=auto             # whether to autogenerate wine.conf
60 DOLOCALCONF=auto              # whether to autogenerate localconf
61 DOWCHK=auto                   # whether to autoconfigure existing-windows installation
62 DOWINE=auto                   # whether to autoconfigure no-windows installation
63 DOREG=auto                    # whether to install default registry
64 SYSREG=yes                    # whether to make root's registry global (system-default)
65 CONVCONF=no                   # whether we are converting an existing .winerc or not
66
67 # "make install" still installs the dlls into $libdir, but this may change in the future
68 # (DLLPATH should point to them if/when they are not in standard ld.so paths)
69 DLLPATH=$libdir/wine          # default path of the dll .so files (except libwine.so)
70
71 # having the Wine debugger launched automatically will be a plus for us
72 DEBUGGER=$bindir/winedbg      # the (installed) path of winedbg
73 HDEBUGGER=debugger/winedbg    # the (non-installed) path of winedbg
74
75 # this is only for existing-windows installs
76 WINECONF=tools/wineconf       # the path of wineconf perl script
77
78 # this is only for no-windows installs
79 WINEINI=$exdir/config         # the path of default wine config file (also used by wineconf)
80 WININI=/dev/null              # the path of default win.ini
81 SYSTEMINI=$exdir/system.ini   # the path of default system.ini
82 REGAPI=programs/regapi/regapi # the path of regapi winelib application
83 DEFREG=winedefault.reg        # the path of the registry file to be fed to regapi
84 # CROOT=/var/wine             # the path of the fake Drive C (asks user if not set)
85 DEFCAT=cat                    # program to cat $DEFREG with (some packages need zcat)
86 #--- end of defaults
87
88 # temporary files used by the installer
89 TMPCONF=/tmp/wineinstall.conf
90 TMPREG=/tmp/wineinstall.reg
91
92 # functions
93
94 function std_sleep {
95   sleep 1
96 }
97
98 function conf_question {
99   # parameters: $1 = importance, $2 = question-id, $3+ = message lines
100   # the first two parameters can be used by e.g. debconf in debian packages
101   # but here we just print the message
102   shift 2
103   echo
104   local LINE="$1"
105   while shift
106   do {
107     echo "$LINE"
108     LINE="$1"
109   }
110   done
111 }
112
113 function conf_reset_question {
114   # parameters: $1 = question-id
115   # this is used to flush any cached answers and "already-displayed" flags
116   shift # dummy command
117 }
118
119 function conf_yesno_answer {
120   unset ANSWER
121   while [ "$ANSWER" != 'yes' ] && [ "$ANSWER" != 'no' ]
122   do {
123     echo -n "$1"
124     read ANSWER
125   }
126   done
127 }
128
129 function conf_string_answer {
130   echo -n "$1"
131   read ANSWER
132 }
133
134 function create_windows_directories {
135   for tdir in "$CROOT/windows" "$CROOT/windows/system" \
136               "$CROOT/windows/Start Menu" "$CROOT/windows/Start Menu/Programs" \
137               "$CROOT/Common Files" "$CROOT/Program Files" \
138               "$CROOT/windows/Profiles" "$CROOT/windows/Profiles/Administrator"
139   do [ -d "$tdir" ] || mkdir "$tdir"
140   done
141   [ -f "$CROOT/windows/win.ini" ]    || cp "$WININI"    "$CROOT/windows/win.ini"
142   [ -f "$CROOT/windows/system.ini" ] || cp "$SYSTEMINI" "$CROOT/windows/system.ini"
143 }
144
145 # startup...
146
147 echo "WINE Installer v0.7"
148 echo
149
150 if [ "$BINDIST" = 'no' ]
151 then {
152
153 if ! [ -f configure ]
154 then {
155   echo "You're running this from the wrong directory."
156   echo "Change to the Wine source's main directory and try again."
157   exit 1
158 }
159 fi
160
161 # check whether RPM installed, and if it is, remove any old wine rpm.
162 hash rpm &>/dev/null
163 RET=$?
164 if [ $RET -eq 0 ]; then
165   if [ -n "`rpm -qi wine 2>/dev/null|grep "^Name"`" ]; then
166     echo "Warning: Old Wine RPM install detected. Do you want to remove it first?"
167     conf_yesno_answer "(yes/no) "
168     if [ "$ANSWER" = 'yes' ]; then
169       echo Starting wine rpm removal...
170       rpm -e wine; RET=$?
171       if [ $RET -eq 0 ]; then
172         echo Done.
173       else
174         echo "FAILED. Probably you aren't installing as root."
175         echo "Expect problems (library conflicts with existing install etc.)."
176       fi
177     else
178       echo "Sorry, I won't install Wine when an rpm version is still installed."
179       echo "(Wine support suffered from way too many conflicts)"
180       echo "Have a nice day !"
181       exit 1
182     fi 
183   fi
184 fi
185
186 # run the configure script, if necessary
187
188 if [ -f config.cache ] && [ -f Makefile ] && [ Makefile -nt configure ]
189 then {
190   echo "I see that WINE has already been configured, so I'll skip that."
191   std_sleep
192   # load configure results
193   . ./config.cache
194 }
195 else {
196   echo "Running configure..."
197   echo
198   if ! ./configure $CONFARGS
199   then {
200     echo
201     echo "Configure failed, aborting install."
202     rm -f config.cache
203     exit 1
204   }
205   fi
206   # load configure results
207   . ./config.cache
208   # make sure X was found
209   eval "$ac_cv_have_x"
210   if [ "$have_x" != "yes" ]
211   then {
212     echo "Install the X development headers and try again."
213     rm -f config.cache
214     exit 1
215   }
216   elif [ "$ac_cv_header_X11_xpm_h" != "yes" ]
217   then {
218     echo "Install the Xpm development headers and try again."
219     rm -f config.cache
220     exit 1
221   }
222   fi
223 }
224 fi
225
226 # now do the compilation
227
228 if [ -f wine ] && [ wine -nt Makefile ]
229 then {
230   echo "Hmm, looks like WINE is already compiled. I'll skip that too, I guess."
231   std_sleep
232 }
233 else {
234   echo "Compiling WINE. Grab a lunch or two, rent a video, or whatever,"
235   echo "in the meantime..."
236   echo
237   std_sleep
238   if ! { make depend && make; }
239   then {
240     echo
241     echo "Compilation failed, aborting install."
242     exit 1
243   }
244   fi
245   echo
246 }
247 fi
248
249 # and installation, if root
250
251 if [ `whoami` != 'root' ]
252 then {
253   echo "You aren't root, so I'll skip the make install."
254
255   # setup to run from current directory
256   DLLPATH="$PWD/dlls"
257   if [ -z "$LD_LIBRARY_PATH" ]
258   then LD_LIBRARY_PATH="$PWD:$DLLPATH"
259   else LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$PWD:$DLLPATH"
260   fi
261   export LD_LIBRARY_PATH
262   DEBUGGER="$PWD/$HDEBUGGER"
263   echo
264   echo "NOTE! To run Wine without installing, you must set the environment variable"
265   echo "LD_LIBRARY_PATH to $PWD:$DLLPATH"
266   echo "in your logon scripts."
267   echo
268
269   # see if wine is installed on the users system, if not prompt them
270   # and then exit
271   if [ ! `which wine` ]
272   then
273     echo "Could not find wine on your system.  Run wineinstall as root to install wine"
274     echo "before re-running wineinstall as a user."
275     echo
276     echo "Exiting wineinstall"
277     exit 1;
278   fi
279 }
280 else {
281   echo "Now installing binaries onto the system..."
282   echo
283   std_sleep
284   if ! make install
285   then {
286     echo
287     echo "Installation failed, aborting."
288     exit 1
289   }
290   fi
291   if [ -f /etc/ld.so.conf ] && ! grep -qs "$libdir" /etc/ld.so.conf
292   then {
293     echo
294     echo "$libdir didn't exist in your /etc/ld.so.conf, adding it now..."
295     echo "$libdir" >>/etc/ld.so.conf
296     echo "Re-running ldconfig..."
297     eval "$ac_cv_path_LDCONFIG"
298   }
299   fi
300 }
301 fi
302
303 }
304 fi # BINDIST
305
306 # now check whether we should generate wine.conf
307 if [ -z "$DOGLOBALCONF" ]
308 then DOGLOBALCONF=auto
309 fi
310
311 if [ "$DOGLOBALCONF" = 'auto' ]
312 then {
313   # see if we already have a system wine.conf
314   if [ ! -f $GCONF ] && [ `whoami` = 'root' ]
315   then
316     DOGLOBALCONF=no
317     echo "Creation of a global config file is not supported in wineinstall at this"
318     echo "time.  When the configuration architecture is cleaned up this functionality"
319     echo "will be restored to wineinstall."
320     echo
321   fi
322 }
323 fi
324
325 if [ "$DOLOCALCONF" = 'auto' ]
326 then {
327   # see if the user is root, if so, explicitly ask them if they want a
328   # local config file
329   if [ `whoami` = 'root' ]
330   then
331     echo "You are running as root.  Do you want a local config file,"
332     echo "file, ~/.wine/config, created?"
333     conf_yesno_answer "(yes/no) "
334     DOLOCALCONF="$ANSWER"
335   else
336     echo "Create local config file ~/.wine/config?"
337     conf_yesno_answer "(yes/no) "
338     echo
339     DOLOCALCONF="$ANSWER"
340     if [ "$ANSWER" = 'no' ]
341     then
342       conf_question high need_root \
343         "Aborting install. Try again as root to generate a system wine.conf."
344       exit 1
345     fi
346   fi
347
348   if [ -f "$LCONF" ]
349   then
350     echo "Found existing $LCONF, if you continue this file will be"
351     echo "overwritten.  Continue running wineinstall?"
352     conf_yesno_answer "(yes/no) "
353     echo
354     if [ "$ANSWER" = 'no' ]
355     then
356       echo "Exiting wineinstall"
357       exit 1
358     fi
359   fi
360 }
361 fi
362
363 # generate $TMPCONF from existing windows install, if any
364 if [ "$DOLOCALCONF" = 'yes' ]
365 then {
366   if [ "$DOWCHK" = 'yes' ] || [ "$DOWCHK" = 'auto' ]
367   then {
368     echo -n "Searching for an existing Windows installation..."
369     if ! $WINECONF -inifile "$WINEINI" > $TMPCONF 2>/dev/null
370     then {
371       rm -f $TMPCONF $TMPREG > /dev/null
372
373       echo " not found."
374       conf_question low do_without_windows \
375        "Windows was not found on your system, so I assume you want" \
376        "a Wine-only installation. Am I correct?"
377       conf_yesno_answer "(yes/no) "
378       if [ "$ANSWER" = 'no' ]
379       then {
380         conf_question high windows_not_found \
381          "Aborting install. Make sure your Windows partition is mounted and try again," \
382          "or create $LCONF manually by copying from $WINEINI and adapting the drive paths."
383         exit 1
384       }
385       fi
386       DOWINE=yes
387     }
388     else {
389       echo " found."
390
391       conf_reset_question windows_found
392       conf_question low windows_found \
393        "Created $LCONF using your existing Windows installation." \
394        "You probably want to review the file, though."
395       DOWINE=no
396     }
397     fi
398   }
399   elif [ "$DOWINE" = 'auto' ]
400   then DOWINE=yes
401   fi
402 }
403 elif [ "$DOWINE" = 'auto' ]
404 then 
405   DOWINE=no
406 fi
407
408 # setup a no-windows installation, if necessary
409 if [ "$DOWINE" = 'yes' ]
410 then {
411   # set an appropriate DCROOT
412   if [ `whoami` != 'root' ]
413   then DCROOT=~/c
414   else DCROOT=/c
415   fi
416
417   if [ -f ~/.winerc ]
418   then {
419     conf_question medium convert_config \
420      "I found the old version Wine config file, .winerc, in your " \
421      "home directory.  I can convert this to the new format or use the" \
422      "new default Wine config file. Convert?"
423     conf_yesno_answer "(yes/no) "
424     if [ "$ANSWER" = 'yes' ]
425     then {
426       WINEINI=~/.winerc
427       CONVCONF=yes
428     }
429     fi
430   }
431   else {
432
433     conf_question low drivec_path \
434      "Configuring Wine without Windows." \
435      "Some fake Windows directories must be created, to hold any .ini files, DLLs," \
436      "start menu entries, and other things your applications may need to install." \
437      "Where would you like your fake C drive to be placed?"
438     while [ -z "$CROOT" ]
439     do {
440       conf_string_answer "(default is $DCROOT) "
441       [ -z "$ANSWER" ] && ANSWER="$DCROOT"
442       if ! [ -d "$ANSWER" ]
443       then {
444         if mkdir -p "$ANSWER"
445         then CROOT="$ANSWER"
446         else
447           echo "Directory $ANSWER can't be created !"
448           conf_reset_question drivec_path
449         fi
450       }
451       else CROOT="$ANSWER"
452       fi
453     }
454     done
455     echo "Configuring Wine for a no-windows install in $CROOT..."
456   
457     create_windows_directories
458   }
459   fi
460
461   # create $LCONF using the default config file $WINEINI  
462   if [ "$DOLOCALCONF" = 'yes' ] && [ "$CONVCONF" = 'no' ]
463   then {
464     sed "s|\"Path\" = \"/c\"\$|\"Path\" = \"${CROOT}\"|" $WINEINI > $TMPCONF
465     conf_reset_question default_config
466     conf_question low default_config \
467      "Created $LCONF using default Wine configuration." \
468      "You probably want to review the file, though."
469   }
470   fi
471
472   # now we really should install the registry
473   if [ "$DOREG" = 'auto' ]
474   then DOREG=yes
475   fi
476 }
477 fi
478 echo
479
480 #install the local config file $LCONF
481 if [ "$DOLOCALCONF" = 'yes' ]
482 then
483   if [ ! -w ~/.wine ]
484   then
485     mkdir ~/.wine
486   fi
487
488   if [ "$CONVCONF" = 'no' ]
489   then
490     cp $TMPCONF $LCONF > /dev/null
491   fi
492 else
493   DOREG=no
494 fi      
495
496 #install the global config file $GCONF
497 if [ "$DOGLOBALCONF" = 'yes' ]
498 then
499   if [ ! -f $sysconfdir ]
500   then
501     mkdir -p $sysconfdir
502   fi
503
504   cp $TMPCONF $GCONF > /dev/null
505 fi
506
507 # check whether we need to install default registry
508 # (not to be done if windows registry exists)
509 if [ "$DOREG" = 'auto' ]
510 then {
511   echo "Checking for real Windows registry..."
512   if [ -f "$CROOT/windows/system.dat" ]
513   then DOREG=no
514   elif [ -f "$CROOT/windows/system32/config/system" ]
515   then DOREG=no
516   else DOREG=yes
517   fi
518   if [ "$DOREG" = 'yes' ]
519   then echo "Not found, default Wine registry will be installed."
520   else echo "Windows registry found, will not install default Wine registry."
521   fi
522   echo
523 }
524 fi
525
526 # install default registry entries
527 if [ "$DOREG" = 'yes' ]
528 then {
529   if [ "$BINDIST" = 'no' ]
530   then {
531     echo "Compiling regapi..."
532     (cd programs/regapi; make)
533     echo
534   }
535   fi
536   echo "Preparing to install default Wine registry entries..."
537
538   # edit config files so we don't have to run regapi under X
539   if [ "$CONVCONF" = 'yes' ]
540   then
541     mv $WINEINI $WINEINI.new
542     sed "s/GraphicsDriver=.*/GraphicsDriver=ttydrv/" $WINEINI.new > $WINEINI
543   else
544     mv $LCONF $LCONF.new
545     sed "s/\"GraphicsDriver\" = .*/\"GraphicsDriver\" = \"ttydrv\"/" $LCONF.new > $LCONF
546   fi
547
548   # create a temporary wineinstall.reg with fixed debugger path
549   $DEFCAT $DEFREG | sed "s|debugger/winedbg|${DEBUGGER}|" > $TMPREG
550
551   echo "Installing default Wine registry entries..."
552   echo
553   if ! $REGAPI setValue < $TMPREG > /dev/null
554   then {
555     rm -f $TMPREG
556     echo "Registry install failed."
557     conf_reset_question regapi_error
558     conf_question high regapi_error
559     exit 1
560   }
561   else {
562     # if we are converting from a .winerc file, running regapi once
563     # will ONLY convert .winerc -> ~/.wine/config, it will not import the
564     # registry data.  so if we are converting we need to run regapi twice
565     if [ "$CONVCONF" = 'yes' ]
566     then
567       if ! $REGAPI setValue < $TMPREG > /dev/null
568       then
569         rm -f $TMPREG
570         echo "Registry install failed."
571         conf_reset_question regapi_error
572         conf_question high regapi_error
573         exit 1
574       else
575         echo
576         echo "Registry entries successfully installed."
577       fi
578     else
579       echo
580       echo "Registry entries successfully installed."
581     fi
582   }
583   fi
584   rm -f $TMPREG
585   if [ "$SYSREG" = 'auto' ]
586   then SYSREG=yes
587   fi
588
589   # if we converted we need to change the graphics driver back and
590   # restore the original .winerc file
591   if [ "$CONVCONF" = 'yes' ]
592   then
593      mv $WINEINI.new $WINEINI
594   fi
595
596   sed "s/\"GraphicsDriver\" = .*/\"GraphicsDriver\" = \"x11drv\"/" $LCONF > $LCONF.new
597   mv $LCONF.new $LCONF
598 }
599 fi
600
601 # make root's registry global, if desired
602 if [ `whoami` = 'root' ] && [ "$DOREG" = 'yes' ] && [ "$SYSREG" = 'yes' ]
603 then {
604   [ -d ~/.wine ] || mkdir ~/.wine
605   if ! [ -f $sysconfdir/wine.userreg ]
606   then {
607     echo "Linking root's user registry hive to the global registry..."
608     [ -f ~/.wine/wine.userreg ] && cp ~/.wine/wine.userreg $sysconfdir/wine.userreg
609     ln -sf $sysconfdir/wine.userreg ~/.wine/wine.userreg
610   }
611   fi
612   if ! [ -f $sysconfdir/wine.systemreg ]
613   then {
614     echo "Linking root's system registry hive to the global registry..."
615     [ -f ~/.wine/system.reg ] && cp ~/.wine/system.reg $sysconfdir/wine.systemreg
616     ln -sf $sysconfdir/wine.systemreg ~/.wine/system.reg
617   }
618   fi
619 }
620 fi
621
622 # cleanup any temporary files that may remain
623 if [ -f $TMPCONF ]
624 then rm -f $TMPCONF
625 fi
626 if [ -f $TMPREG ]
627 then rm -f $TMPREG
628 fi
629
630
631 # it's a wrap
632 echo
633 echo "Installation complete for now. Good luck (this is still alpha software)."
634 echo "If you have problems with WINE, please read the documentation first,"
635 echo "as many kinds of potential problems are explained there."
636
637 exit 0