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