Make sure prefix is actually honoured by configure.
[wine] / tools / wineinstall
1 #!/bin/bash
2 # WINE Installation script
3 # Can do almost everything from compiling to configuring...
4 #
5 # Copyright 1999 Ove Kåven
6 #
7 # This library is free software; you can redistribute it and/or
8 # modify it under the terms of the GNU Lesser General Public
9 # License as published by the Free Software Foundation; either
10 # version 2.1 of the License, or (at your option) any later version.
11 #
12 # This library is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 # Lesser General Public License for more details.
16 #
17 # You should have received a copy of the GNU Lesser General Public
18 # License along with this library; if not, write to the Free Software
19 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20 #
21
22 #--- defaults (change these if you are a packager)
23 CONFARGS=""                   # configure args, e.g. --prefix=/usr --sysconfdir=/etc
24 prefix=/usr/local             # installation prefix
25 sysconfdir=$prefix/etc        # where wine.conf and the global registry are supposed to be
26 bindir=$prefix/bin            # where winelib apps will be (or are) installed
27 libdir=$prefix/lib            # where libwine.so will be (or is) installed
28 exdir=documentation/samples   # where the sample system.ini resides
29 GCONF=$sysconfdir/wine.conf   # default path of the wine.conf global config file
30 LCONF=~/.wine/config          # default path of the local config file
31 BINDIST=no                    # whether called from a binary package config script
32 DOGLOBALCONF=auto             # whether to autogenerate wine.conf
33 DOLOCALCONF=auto              # whether to autogenerate localconf
34 DOWCHK=auto                   # whether to autoconfigure existing-windows installation
35 DOWINE=auto                   # whether to autoconfigure no-windows installation
36 DOREG=auto                    # whether to install default registry
37 DOAPP=auto                    # whether to install applications, distributed with Wine
38 SYSREG=yes                    # whether to make root's registry global (system-default)
39
40 # "make install" still installs the dlls into $libdir, but this may change in the future
41 # (DLLPATH should point to them if/when they are not in standard ld.so paths)
42 DLLPATH=$libdir/wine          # default path of the dll .so files (except libwine.so)
43
44 # this is only for existing-windows installs
45 WINECONF=tools/wineconf       # path to the wineconf perl script
46
47 # this is only for no-windows installs
48 WINEINI=$exdir/config         # path to the default wine config file (also used by wineconf)
49 WININI=/dev/null              # path to the default win.ini
50 SYSTEMINI=$exdir/system.ini   # path to the default system.ini
51 REGEDIT=programs/regedit/regedit       # path to the regedit winelib application
52 DEFREG=winedefault.reg        # path of the registry file to be fed to regedit
53 # CROOT=/var/wine             # path of the fake Drive C (asks user if not set)
54 DEFCAT=cat                    # program to cat $DEFREG with (some packages need zcat)
55 #--- end of defaults
56
57 # temporary files used by the installer
58 TMPCONF=/tmp/wineinstall.conf
59
60 # functions
61
62 function std_sleep {
63   sleep 1
64 }
65
66 function conf_question {
67   # parameters: $1 = importance, $2 = question-id, $3+ = message lines
68   # the first two parameters can be used by e.g. debconf in debian packages
69   # but here we just print the message
70   shift 2
71   echo
72   local LINE="$1"
73   while shift
74   do {
75     echo "$LINE"
76     LINE="$1"
77   }
78   done
79 }
80
81 function conf_reset_question {
82   # parameters: $1 = question-id
83   # this is used to flush any cached answers and "already-displayed" flags
84   shift # dummy command
85 }
86
87 function conf_yesno_answer {
88   unset ANSWER
89   while [ "$ANSWER" != 'yes' ] && [ "$ANSWER" != 'no' ]
90   do {
91     echo -n "$1"
92     read ANSWER
93   }
94   done
95 }
96
97 function conf_string_answer {
98   echo -n "$1"
99   read ANSWER
100 }
101
102 function create_windows_directories {
103   for tdir in "$CROOT/windows" "$CROOT/windows/system" \
104               "$CROOT/windows/command" \
105               "$CROOT/windows/Start Menu" "$CROOT/windows/Start Menu/Programs" \
106               "$CROOT/Program Files" "$CROOT/Program Files/Common Files" \
107               "$CROOT/windows/Profiles" "$CROOT/windows/Profiles/Administrator" \
108               "$CROOT/windows/Fonts" "$CROOT/windows/Start Menu/Programs/Startup"
109   do [ -d "$tdir" ] || mkdir "$tdir"
110   done
111   [ -f "$CROOT/windows/win.ini" ]    || cp "$WININI"    "$CROOT/windows/win.ini"
112   [ -f "$CROOT/windows/system.ini" ] || cp "$SYSTEMINI" "$CROOT/windows/system.ini"
113 }
114
115 #creates symbolic link in windows directory to installed winelib application
116 #parameters:
117 # - name of the installed winelib application
118 # - full path to application in the winelib directory
119 function link_app {
120   if [ "$WINEINSTALLED" = 'no' ]
121   then {
122     ln -sf $PWD/programs/$1/$1.exe.so $2
123   }
124   else {
125     ln -sf $libdir/wine/$1.exe.so $2
126   }
127   fi
128 }
129
130 #puts windows applications replacements to windows directories,
131 #configures them
132 function configure_wine_applications {
133   link_app start        "$CROOT/windows/command/start.exe"
134   link_app notepad      "$CROOT/windows/notepad.exe"
135   link_app regedit      "$CROOT/windows/regedit.exe"
136   link_app rundll32     "$CROOT/windows/rundll32.exe"
137   link_app wcmd         "$CROOT/windows/system/wcmd.exe"
138   link_app control      "$CROOT/windows/system/control.exe"
139   link_app winhelp      "$CROOT/windows/system/help.exe"
140   link_app notepad      "$CROOT/windows/system/notepad.exe"
141   link_app progman      "$CROOT/windows/system/progman.exe"
142   link_app regsvr32     "$CROOT/windows/system/regsvr32.exe"
143   link_app winemine     "$CROOT/windows/system/winmine.exe"
144   link_app winver       "$CROOT/windows/system/winver.exe"
145   link_app uninstaller  "$CROOT/windows/uninstall.exe"
146   link_app winhelp      "$CROOT/windows/winhelp.exe"
147   link_app winhelp      "$CROOT/windows/winhlp32.exe"
148 }
149
150 # startup...
151
152 echo "WINE Installer v0.74"
153 echo
154
155 # check for redhat 9 so we can enable --with-nptl until runtime detection is complete
156 if cat /etc/redhat-release | grep Shrike &>/dev/null; then
157     CONFARGS="$CONFARGS --with-nptl"
158 fi
159
160 if [ "$BINDIST" = 'no' ]
161 then {
162
163   if ! [ -f configure ]
164   then {
165     if [ -f ../configure ]
166     then {
167       pushd ..
168     }
169     else {
170       echo "You're running this from the wrong directory."
171       echo "Change to the Wine source's main directory and try again."
172       exit 1
173     }
174     fi
175   }
176   fi
177
178   if [ `whoami` == 'root' ]
179   then {
180     echo "You are running wineinstall as root, this is not advisable. Please rerun as a user."
181     echo "Aborting."
182     exit 1
183   }
184   fi
185
186   # check whether RPM installed, and if it is, remove any old wine rpm.
187   hash rpm &>/dev/null
188   RET=$?
189   if [ $RET -eq 0 ]; then
190     if [ -n "`rpm -qi wine 2>/dev/null|grep "^Name"`" ]; then
191       echo "Warning: Old Wine RPM install detected. Do you want to remove it first?"
192       conf_yesno_answer "(yes/no) "
193       if [ "$ANSWER" = 'yes' ]; then
194         echo "We need to remove the rpm as root, please enter your root password"
195         echo
196         echo Starting wine rpm removal...
197         su -c "rpm -e wine; RET=$?"
198         if [ $RET -eq 0 ]; then
199           echo Done.
200         else
201           echo "FAILED. Probably you aren't installing as root."
202           echo "Expect problems (library conflicts with existing install etc.)."
203         fi
204       else
205         echo "Sorry, I won't install Wine when an rpm version is still installed."
206         echo "(Wine support suffered from way too many conflicts between RPM"
207         echo "and source installs)"
208         echo "Have a nice day !"
209         exit 1
210       fi
211     fi
212   fi
213
214   # check whether wine binary still available
215   if [ -n "`which wine 2>/dev/null|grep '/wine'`" ]; then
216     echo "Warning !! wine binary (still) found, which may indicate"
217     echo "a (conflicting) previous installation."
218     echo "You might want to abort and uninstall Wine first."
219     std_sleep
220   fi
221
222   # run the configure script, if necessary
223
224   if [ -f config.cache ] && [ -f Makefile ] && [ Makefile -nt configure ]
225   then {
226     echo
227     echo "I see that WINE has already been configured, so I'll skip that."
228     std_sleep
229     # load configure results
230     . ./config.cache
231   }
232   else {
233     echo "Running configure..."
234     echo
235     if ! ./configure -C $CONFARGS --prefix=$prefix
236     then {
237       echo
238       echo "Configure failed, aborting install."
239       rm -f config.cache
240       exit 1
241     }
242     fi
243     # load configure results
244     . ./config.cache
245     # make sure X was found
246     eval "$ac_cv_have_x"
247     if [ "$have_x" != "yes" ]
248     then {
249       echo "Install the X development headers and try again."
250       rm -f config.cache
251       exit 1
252     }
253     fi
254   }
255   fi
256
257   # now do the compilation and install, we need to always do this because we
258   # don't want the 'make install' command we might run to run 'make' as root
259   if [ `whoami` != 'root' ]
260   then {
261     # ask the user if they want to build and install wine
262     echo
263     echo "We need to install wine as root user, do you want us to build wine,"
264     echo "'su root' and install Wine?  Enter 'no' to continue without installing"
265     conf_yesno_answer "(yes/no) "
266     ROOTINSTALL="$ANSWER"
267
268     if [ "$ROOTINSTALL" = "yes" ]
269     then {
270       # start out with the basic command
271       sucommand="make install"
272
273       # if the user doesn't have $libdir in their ld.so.conf add this
274       # to our sucommand string
275       if [ -f /etc/ld.so.conf ]
276       then
277         if ! grep -qs "$libdir" /etc/ld.so.conf
278         then {
279           echo
280           echo "$libdir doesn't exist in your /etc/ld.so.conf, it will be added"
281           echo "when we perform the install..."
282           sucommand="$sucommand;echo $libdir>>/etc/ld.so.conf"
283         }
284         fi
285         # run ldconfig always just in case some updated files dont get linked
286         sucommand="$sucommand;$ac_cv_path_LDCONFIG"
287       fi
288     }
289     fi # [ "$ROOTINSTALL" = "yes" ]
290
291     echo
292
293     echo "Compiling WINE. Grab a lunch or two, rent a video, or whatever,"
294     echo "in the meantime..."
295     echo
296     std_sleep
297
298     # try to just make wine, if this fails 'make depend' and try to remake
299     if ! { make; }
300     then {
301       if ! { make depend && make; }
302       then {
303         echo
304         echo "Compilation failed, aborting install."
305         exit 1
306       }
307       fi
308     }
309     fi
310
311     if [ "$ROOTINSTALL" = "yes" ]
312     then {
313       echo
314
315       echo "Performing 'make install' as root to install binaries, enter root password"
316
317       std_sleep
318
319       if ! su root -c "$sucommand"
320       then {
321         if ! su root -c "$sucommand"
322         then {
323              echo
324              echo "Either you entered an incorrect password or we failed to"
325              echo "run '$sucommand' correctly."
326              echo "If you didn't enter an incorrect password then please"
327              echo "report this error and any steps to possibly reproduce it to"
328              echo "http://bugs.winehq.com/"
329              echo
330              echo "Installation failed, aborting."
331              exit 1
332          }
333          fi
334        }
335       fi
336
337       echo
338
339       # see if wine is installed on the users system, if not prompt them
340       # and then exit
341       if [ ! `which wine` ]
342       then
343         echo "Could not find wine on your system.  Run wineinstall as root to install wine"
344         echo "before re-running wineinstall as a user."
345         echo
346         echo "Exiting wineinstall"
347         exit 1;
348       fi
349
350       WINEINSTALLED=yes
351     }
352     else {
353       # user didn't want to install wine so tell them about running from the
354       # current directory and set some stuff up for them
355
356       # setup to run from current directory
357       DLLPATH="$PWD/dlls"
358       if [ -z "$LD_LIBRARY_PATH" ]
359       then LD_LIBRARY_PATH="$PWD:$DLLPATH"
360       else LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$PWD:$DLLPATH"
361       fi
362       export LD_LIBRARY_PATH
363       echo
364       echo "NOTE! To run Wine without installing, you must set the environment variable"
365       echo "LD_LIBRARY_PATH to $PWD:$DLLPATH"
366       echo "in your logon scripts."
367       echo
368
369       WINEINSTALLED=no
370     }
371     fi # [ "$ROOTINSTALL" = "yes" ]
372   }
373   fi # [ `whoami` != 'root' ]
374
375 }
376 fi # BINDIST
377
378 # now check whether we should generate wine.conf
379 if [ -z "$DOGLOBALCONF" ]
380 then
381   DOGLOBALCONF=auto
382 fi
383
384 if [ "$DOGLOBALCONF" = 'auto' ]
385 then {
386   # see if we already have a system wine.conf
387   if [ ! -f $GCONF ] && [ `whoami` = 'root' ]
388   then
389     DOGLOBALCONF=no
390     echo "Creation of a global config file is not supported in wineinstall at this"
391     echo "time.  When the configuration architecture is cleaned up this functionality"
392     echo "will be restored to wineinstall."
393     echo
394   fi
395 }
396 fi
397
398 if [ "$DOLOCALCONF" = 'auto' ]
399 then {
400   # see if the user is root, if so, explicitly ask them if they want a
401   # local config file
402   if [ `whoami` = 'root' ]
403   then
404     echo "You are running as root.  Do you want a local config file,"
405     echo "file, ~/.wine/config, created?"
406     conf_yesno_answer "(yes/no) "
407     DOLOCALCONF="$ANSWER"
408   else
409     # if the user has an existing config file ask them if they want us to
410     # overwrite it, otherwise just ask them if they want to create one
411     if [ -f "$LCONF" ]
412     then
413       echo "Found existing $LCONF, do you want to overwrite this"
414       echo "existing Wine configuration file?"
415       conf_yesno_answer "(yes/no) "
416       DOLOCALCONF="$ANSWER"
417       echo
418       if [ "$ANSWER" = "yes" ]
419       then
420       {
421         echo "Would you like to make a backup of this old config file?"
422         conf_yesno_answer "(yes/no) "
423         echo
424         if [ "$ANSWER" = "yes" ]
425         then
426         {
427           echo "Renaming $LCONF to $LCONF.old"
428           mv -f "$LCONF" "$LCONF.old"
429           echo
430         }
431         fi
432       }
433       fi
434     else
435     {
436       echo "Create local config file ~/.wine/config?"
437       conf_yesno_answer "(yes/no) "
438       DOLOCALCONF="$ANSWER"
439       echo
440       if [ "$ANSWER" = 'no' ]
441       then
442         conf_question high need_root \
443           "Aborting install. Try again as root to generate a system wine.conf."
444         exit 1
445       fi
446     }
447     fi
448   fi
449 }
450 fi
451
452 # generate $TMPCONF from existing windows install, if any
453 if [ "$DOLOCALCONF" = 'yes' ]
454 then {
455   if [ "$DOWCHK" = 'yes' ] || [ "$DOWCHK" = 'auto' ]
456   then {
457     echo -n "Searching for an existing Windows installation..."
458     if ! $WINECONF -inifile "$WINEINI" > $TMPCONF 2>/dev/null
459     then {
460       rm -f $TMPCONF > /dev/null
461
462       echo " not found. (no matching /etc/fstab mount entry found)"
463       conf_question low do_without_windows \
464        "Windows was not found on your system, so I assume you want" \
465        "a Wine-only installation. Am I correct?"
466       conf_yesno_answer "(yes/no) "
467       if [ "$ANSWER" = 'no' ]
468       then {
469         conf_question high windows_not_found \
470          "Aborting install. Make sure your Windows partition is mounted and try again," \
471          "or create $LCONF manually by copying from $WINEINI and adapting the drive paths."
472         exit 1
473       }
474       fi
475       DOWINE=yes
476     }
477     else {
478       echo " found."
479
480       conf_question low do_without_windows \
481        "Windows was found on your system, and so we can use the Windows" \
482        "Drive as our Wine drive. You may, however, wish to create a clean" \
483        "Wine install anyways."
484       conf_yesno_answer "Should I use the Windows drive for the Wine install? (yes/no) "
485       if [ "$ANSWER" = 'yes' ]
486       then {
487         conf_reset_question windows_found
488         conf_question low windows_found \
489          "Created $LCONF using your existing Windows installation." \
490          "You probably want to review the file, though."
491         DOWINE=no
492       }
493       else {
494         DOWINE=yes
495       }
496       fi
497     }
498     fi
499   }
500   elif [ "$DOWINE" = 'auto' ]
501   then DOWINE=yes
502   fi
503 }
504 elif [ "$DOWINE" = 'auto' ]
505 then
506   DOWINE=no
507 fi
508
509 # setup a no-windows installation, if necessary
510 if [ "$DOWINE" = 'yes' ]
511 then {
512   # set an appropriate DCROOT
513   if [ `whoami` != 'root' ]
514   then DCROOT=~/c
515   else DCROOT=/c
516   fi
517
518   conf_question low drivec_path \
519      "Configuring Wine without Windows." \
520      "Some fake Windows directories must be created, to hold any .ini files, DLLs," \
521      "start menu entries, and other things your applications may need to install." \
522      "Where would you like your fake C drive to be placed?"
523   while [ -z "$CROOT" ]
524   do {
525     conf_string_answer "(default is $DCROOT) "
526     [ -z "$ANSWER" ] && ANSWER="$DCROOT"
527     if ! [ -d "$ANSWER" ]
528     then {
529       if mkdir -p "$ANSWER"
530       then CROOT="$ANSWER"
531       else
532           echo "Directory $ANSWER can't be created !"
533           conf_reset_question drivec_path
534       fi
535     }
536     else CROOT="$ANSWER"
537     fi
538   }
539   done
540   echo "Configuring Wine for a no-windows install in $CROOT..."
541
542     create_windows_directories
543     configure_wine_applications
544
545   # create $LCONF using the default config file $WINEINI
546   if [ "$DOLOCALCONF" = 'yes' ]
547   then {
548     sed "s|\"Path\" = \"/c\"\$|\"Path\" = \"${CROOT}\"|" $WINEINI > $TMPCONF
549     conf_reset_question default_config
550     conf_question low default_config \
551      "Created $LCONF using default Wine configuration." \
552      "You probably want to review the file, though."
553   }
554   fi
555
556   # now we really should install the registry
557   if [ "$DOREG" = 'auto' ]
558   then DOREG=yes
559   fi
560 }
561 fi
562 echo
563
564 #install the local config file $LCONF
565 if [ "$DOLOCALCONF" = 'yes' ]
566 then
567   if [ ! -w ~/.wine ]
568   then
569     mkdir ~/.wine
570   fi
571   cp $TMPCONF $LCONF > /dev/null
572 else
573   DOREG=no
574 fi
575
576 #install the global config file $GCONF
577 if [ "$DOGLOBALCONF" = 'yes' ]
578 then
579   if [ ! -f $sysconfdir ]
580   then
581     mkdir -p $sysconfdir
582   fi
583
584   cp $TMPCONF $GCONF > /dev/null
585 fi
586
587 # check whether we need to install default registry
588 # (not to be done if windows registry exists)
589 if [ "$DOREG" = 'auto' ]
590 then {
591   CROOT=`sed -n '/^\[Drive C\]$/,/^\[.*\]$/ s/^\"Path\" = \"\(.*\)\"/\1/p' $LCONF`
592   echo "Checking for real Windows registry..."
593   if [ -f "$CROOT/windows/system.dat" ]
594   then DOREG=no
595   elif [ -f "$CROOT/windows/system32/config/system" ]
596   then DOREG=no
597   elif [ -f "$CROOT/WINNT/system32/config/system" ]
598   then DOREG=no
599   else DOREG=yes
600   fi
601   if [ "$DOREG" = 'yes' ]
602   then echo "Not found, default Wine registry will be installed."
603   else echo "Windows registry found, will not install default Wine registry."
604   fi
605   echo
606 }
607 fi
608
609 # install default registry entries
610 if [ "$DOREG" = 'yes' ]
611 then {
612   if [ "$BINDIST" = 'no' ]
613   then {
614     echo "Compiling regedit..."
615     (cd programs/regedit; make)
616     echo
617   }
618   fi
619   echo "Preparing to install default Wine registry entries..."
620
621   # Make sure we are on a Windows drive
622   mv $LCONF $LCONF.orig
623   sed "s/\"Path\" = \"\${HOME}\"$/\"Path\" = \"\${PWD}\"/" $LCONF.orig> $LCONF
624
625   echo "Installing default Wine registry entries..."
626   echo
627   if ! $REGEDIT $DEFREG > /dev/null
628   then {
629     echo "Registry install failed."
630     mv $LCONF.orig $LCONF
631     conf_reset_question regedit_error
632     conf_question high regedit_error
633     exit 1
634   }
635   else {
636     echo
637     echo "Registry entries successfully installed."
638     mv $LCONF.orig $LCONF
639   }
640   fi
641   if [ "$SYSREG" = 'auto' ]
642   then SYSREG=yes
643   fi
644 }
645 fi
646
647 # make root's registry global, if desired
648 if [ `whoami` = 'root' ] && [ "$DOREG" = 'yes' ] && [ "$SYSREG" = 'yes' ]
649 then {
650   [ -d ~/.wine ] || mkdir ~/.wine
651   if ! [ -f $sysconfdir/wine.userreg ]
652   then {
653     echo "Linking root's user registry hive to the global registry..."
654     [ -f ~/.wine/wine.userreg ] && cp ~/.wine/wine.userreg $sysconfdir/wine.userreg
655     ln -sf $sysconfdir/wine.userreg ~/.wine/wine.userreg
656   }
657   fi
658   if ! [ -f $sysconfdir/wine.systemreg ]
659   then {
660     echo "Linking root's system registry hive to the global registry..."
661     [ -f ~/.wine/system.reg ] && cp ~/.wine/system.reg $sysconfdir/wine.systemreg
662     ln -sf $sysconfdir/wine.systemreg ~/.wine/system.reg
663   }
664   fi
665 }
666 fi
667
668 # cleanup any temporary files that may remain
669 if [ -f $TMPCONF ]
670 then rm -f $TMPCONF
671 fi
672
673
674 # it's a wrap
675 echo
676 echo "Installation complete for now. Good luck (this is still alpha software)."
677 echo "If you have problems with WINE, please read the documentation first,"
678 echo "as many kinds of potential problems are explained there."
679
680 exit 0