Don't change to ttydrv to install registry, regedit doesn't use X.
[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 if [ "$BINDIST" = 'no' ]
156 then {
157
158   if ! [ -f configure ]
159   then {
160     if [ -f ../configure ]
161     then {
162       pushd ..
163     }
164     else {
165       echo "You're running this from the wrong directory."
166       echo "Change to the Wine source's main directory and try again."
167       exit 1
168     }
169     fi
170   }
171   fi
172
173   if [ `whoami` == 'root' ]
174   then {
175     echo "You are running wineinstall as root, this is not advisable. Please rerun as a user."
176     echo "Aborting."
177     exit 1
178   }
179   fi
180
181   # check whether RPM installed, and if it is, remove any old wine rpm.
182   hash rpm &>/dev/null
183   RET=$?
184   if [ $RET -eq 0 ]; then
185     if [ -n "`rpm -qi wine 2>/dev/null|grep "^Name"`" ]; then
186       echo "Warning: Old Wine RPM install detected. Do you want to remove it first?"
187       conf_yesno_answer "(yes/no) "
188       if [ "$ANSWER" = 'yes' ]; then
189         echo "We need to remove the rpm as root, please enter your root password"
190         echo
191         echo Starting wine rpm removal...
192         su -c "rpm -e wine; RET=$?"
193         if [ $RET -eq 0 ]; then
194           echo Done.
195         else
196           echo "FAILED. Probably you aren't installing as root."
197           echo "Expect problems (library conflicts with existing install etc.)."
198         fi
199       else
200         echo "Sorry, I won't install Wine when an rpm version is still installed."
201         echo "(Wine support suffered from way too many conflicts between RPM"
202         echo "and source installs)"
203         echo "Have a nice day !"
204         exit 1
205       fi
206     fi
207   fi
208
209   # check whether wine binary still available
210   if [ -n "`which wine 2>/dev/null|grep '/wine'`" ]; then
211     echo "Warning !! wine binary (still) found, which may indicate"
212     echo "a (conflicting) previous installation."
213     echo "You might want to abort and uninstall Wine first."
214     std_sleep
215   fi
216
217   # run the configure script, if necessary
218
219   if [ -f config.cache ] && [ -f Makefile ] && [ Makefile -nt configure ]
220   then {
221     echo
222     echo "I see that WINE has already been configured, so I'll skip that."
223     std_sleep
224     # load configure results
225     . ./config.cache
226   }
227   else {
228     echo "Running configure..."
229     echo
230     if ! ./configure -C $CONFARGS
231     then {
232       echo
233       echo "Configure failed, aborting install."
234       rm -f config.cache
235       exit 1
236     }
237     fi
238     # load configure results
239     . ./config.cache
240     # make sure X was found
241     eval "$ac_cv_have_x"
242     if [ "$have_x" != "yes" ]
243     then {
244       echo "Install the X development headers and try again."
245       rm -f config.cache
246       exit 1
247     }
248     fi
249   }
250   fi
251
252   # now do the compilation and install, we need to always do this because we
253   # don't want the 'make install' command we might run to run 'make' as root
254   if [ `whoami` != 'root' ]
255   then {
256     # ask the user if they want to build and install wine
257     echo
258     echo "We need to install wine as root user, do you want us to build wine,"
259     echo "'su root' and install Wine?  Enter 'no' to continue without installing"
260     conf_yesno_answer "(yes/no) "
261     ROOTINSTALL="$ANSWER"
262
263     if [ "$ROOTINSTALL" = "yes" ]
264     then {
265       # start out with the basic command
266       sucommand="make install"
267
268       # if the user doesn't have $libdir in their ld.so.conf add this
269       # to our sucommand string
270       if [ -f /etc/ld.so.conf ]
271       then
272         if ! grep -qs "$libdir" /etc/ld.so.conf
273         then {
274           echo
275           echo "$libdir doesn't exist in your /etc/ld.so.conf, it will be added"
276           echo "when we perform the install..."
277           sucommand="$sucommand;echo $libdir>>/etc/ld.so.conf"
278         }
279         fi
280         # run ldconfig always just in case some updated files dont get linked
281         sucommand="$sucommand;$ac_cv_path_LDCONFIG"
282       fi
283     }
284     fi # [ "$ROOTINSTALL" = "yes" ]
285
286     echo
287
288     echo "Compiling WINE. Grab a lunch or two, rent a video, or whatever,"
289     echo "in the meantime..."
290     echo
291     std_sleep
292
293     # try to just make wine, if this fails 'make depend' and try to remake
294     if ! { make; }
295     then {
296       if ! { make depend && make; }
297       then {
298         echo
299         echo "Compilation failed, aborting install."
300         exit 1
301       }
302       fi
303     }
304     fi
305
306     if [ "$ROOTINSTALL" = "yes" ]
307     then {
308       echo
309
310       echo "Performing 'make install' as root to install binaries, enter root password"
311
312       std_sleep
313
314       if ! su root -c "$sucommand"
315       then {
316         if ! su root -c "$sucommand"
317         then {
318              echo
319              echo "Either you entered an incorrect password or we failed to"
320              echo "run '$sucommand' correctly."
321              echo "If you didn't enter an incorrect password then please"
322              echo "report this error and any steps to possibly reproduce it to"
323              echo "http://bugs.winehq.com/"
324              echo
325              echo "Installation failed, aborting."
326              exit 1
327          }
328          fi
329        }
330       fi
331
332       echo
333
334       # see if wine is installed on the users system, if not prompt them
335       # and then exit
336       if [ ! `which wine` ]
337       then
338         echo "Could not find wine on your system.  Run wineinstall as root to install wine"
339         echo "before re-running wineinstall as a user."
340         echo
341         echo "Exiting wineinstall"
342         exit 1;
343       fi
344
345       WINEINSTALLED=yes
346     }
347     else {
348       # user didn't want to install wine so tell them about running from the
349       # current directory and set some stuff up for them
350
351       # setup to run from current directory
352       DLLPATH="$PWD/dlls"
353       if [ -z "$LD_LIBRARY_PATH" ]
354       then LD_LIBRARY_PATH="$PWD:$DLLPATH"
355       else LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$PWD:$DLLPATH"
356       fi
357       export LD_LIBRARY_PATH
358       echo
359       echo "NOTE! To run Wine without installing, you must set the environment variable"
360       echo "LD_LIBRARY_PATH to $PWD:$DLLPATH"
361       echo "in your logon scripts."
362       echo
363
364       WINEINSTALLED=no
365     }
366     fi # [ "$ROOTINSTALL" = "yes" ]
367   }
368   fi # [ `whoami` != 'root' ]
369
370 }
371 fi # BINDIST
372
373 # now check whether we should generate wine.conf
374 if [ -z "$DOGLOBALCONF" ]
375 then
376   DOGLOBALCONF=auto
377 fi
378
379 if [ "$DOGLOBALCONF" = 'auto' ]
380 then {
381   # see if we already have a system wine.conf
382   if [ ! -f $GCONF ] && [ `whoami` = 'root' ]
383   then
384     DOGLOBALCONF=no
385     echo "Creation of a global config file is not supported in wineinstall at this"
386     echo "time.  When the configuration architecture is cleaned up this functionality"
387     echo "will be restored to wineinstall."
388     echo
389   fi
390 }
391 fi
392
393 if [ "$DOLOCALCONF" = 'auto' ]
394 then {
395   # see if the user is root, if so, explicitly ask them if they want a
396   # local config file
397   if [ `whoami` = 'root' ]
398   then
399     echo "You are running as root.  Do you want a local config file,"
400     echo "file, ~/.wine/config, created?"
401     conf_yesno_answer "(yes/no) "
402     DOLOCALCONF="$ANSWER"
403   else
404     # if the user has an existing config file ask them if they want us to
405     # overwrite it, otherwise just ask them if they want to create one
406     if [ -f "$LCONF" ]
407     then
408       echo "Found existing $LCONF, do you want to overwrite this"
409       echo "existing Wine configuration file?"
410       conf_yesno_answer "(yes/no) "
411       DOLOCALCONF="$ANSWER"
412       echo
413       if [ "$ANSWER" = "yes" ]
414       then
415       {
416         echo "Would you like to make a backup of this old config file?"
417         conf_yesno_answer "(yes/no) "
418         echo
419         if [ "$ANSWER" = "yes" ]
420         then
421         {
422           echo "Renaming $LCONF to $LCONF.old"
423           mv -f "$LCONF" "$LCONF.old"
424           echo
425         }
426         fi
427       }
428       fi
429     else
430     {
431       echo "Create local config file ~/.wine/config?"
432       conf_yesno_answer "(yes/no) "
433       DOLOCALCONF="$ANSWER"
434       echo
435       if [ "$ANSWER" = 'no' ]
436       then
437         conf_question high need_root \
438           "Aborting install. Try again as root to generate a system wine.conf."
439         exit 1
440       fi
441     }
442     fi
443   fi
444 }
445 fi
446
447 # generate $TMPCONF from existing windows install, if any
448 if [ "$DOLOCALCONF" = 'yes' ]
449 then {
450   if [ "$DOWCHK" = 'yes' ] || [ "$DOWCHK" = 'auto' ]
451   then {
452     echo -n "Searching for an existing Windows installation..."
453     if ! $WINECONF -inifile "$WINEINI" > $TMPCONF 2>/dev/null
454     then {
455       rm -f $TMPCONF > /dev/null
456
457       echo " not found. (no matching /etc/fstab mount entry found)"
458       conf_question low do_without_windows \
459        "Windows was not found on your system, so I assume you want" \
460        "a Wine-only installation. Am I correct?"
461       conf_yesno_answer "(yes/no) "
462       if [ "$ANSWER" = 'no' ]
463       then {
464         conf_question high windows_not_found \
465          "Aborting install. Make sure your Windows partition is mounted and try again," \
466          "or create $LCONF manually by copying from $WINEINI and adapting the drive paths."
467         exit 1
468       }
469       fi
470       DOWINE=yes
471     }
472     else {
473       echo " found."
474
475       conf_question low do_without_windows \
476        "Windows was found on your system, and so we can use the Windows" \
477        "Drive as our Wine drive. You may, however, wish to create a clean" \
478        "Wine install anyways."
479       conf_yesno_answer "Should I use the Windows drive for the Wine install? (yes/no) "
480       if [ "$ANSWER" = 'yes' ]
481       then {
482         conf_reset_question windows_found
483         conf_question low windows_found \
484          "Created $LCONF using your existing Windows installation." \
485          "You probably want to review the file, though."
486         DOWINE=no
487       }
488       else {
489         DOWINE=yes
490       }
491       fi
492     }
493     fi
494   }
495   elif [ "$DOWINE" = 'auto' ]
496   then DOWINE=yes
497   fi
498 }
499 elif [ "$DOWINE" = 'auto' ]
500 then
501   DOWINE=no
502 fi
503
504 # setup a no-windows installation, if necessary
505 if [ "$DOWINE" = 'yes' ]
506 then {
507   # set an appropriate DCROOT
508   if [ `whoami` != 'root' ]
509   then DCROOT=~/c
510   else DCROOT=/c
511   fi
512
513   conf_question low drivec_path \
514      "Configuring Wine without Windows." \
515      "Some fake Windows directories must be created, to hold any .ini files, DLLs," \
516      "start menu entries, and other things your applications may need to install." \
517      "Where would you like your fake C drive to be placed?"
518   while [ -z "$CROOT" ]
519   do {
520     conf_string_answer "(default is $DCROOT) "
521     [ -z "$ANSWER" ] && ANSWER="$DCROOT"
522     if ! [ -d "$ANSWER" ]
523     then {
524       if mkdir -p "$ANSWER"
525       then CROOT="$ANSWER"
526       else
527           echo "Directory $ANSWER can't be created !"
528           conf_reset_question drivec_path
529       fi
530     }
531     else CROOT="$ANSWER"
532     fi
533   }
534   done
535   echo "Configuring Wine for a no-windows install in $CROOT..."
536
537     create_windows_directories
538     configure_wine_applications
539
540   # create $LCONF using the default config file $WINEINI
541   if [ "$DOLOCALCONF" = 'yes' ]
542   then {
543     sed "s|\"Path\" = \"/c\"\$|\"Path\" = \"${CROOT}\"|" $WINEINI > $TMPCONF
544     conf_reset_question default_config
545     conf_question low default_config \
546      "Created $LCONF using default Wine configuration." \
547      "You probably want to review the file, though."
548   }
549   fi
550
551   # now we really should install the registry
552   if [ "$DOREG" = 'auto' ]
553   then DOREG=yes
554   fi
555 }
556 fi
557 echo
558
559 #install the local config file $LCONF
560 if [ "$DOLOCALCONF" = 'yes' ]
561 then
562   if [ ! -w ~/.wine ]
563   then
564     mkdir ~/.wine
565   fi
566   cp $TMPCONF $LCONF > /dev/null
567 else
568   DOREG=no
569 fi
570
571 #install the global config file $GCONF
572 if [ "$DOGLOBALCONF" = 'yes' ]
573 then
574   if [ ! -f $sysconfdir ]
575   then
576     mkdir -p $sysconfdir
577   fi
578
579   cp $TMPCONF $GCONF > /dev/null
580 fi
581
582 # check whether we need to install default registry
583 # (not to be done if windows registry exists)
584 if [ "$DOREG" = 'auto' ]
585 then {
586   CROOT=`sed -n '/^\[Drive C\]$/,/^\[.*\]$/ s/^\"Path\" = \"\(.*\)\"/\1/p' $LCONF`
587   echo "Checking for real Windows registry..."
588   if [ -f "$CROOT/windows/system.dat" ]
589   then DOREG=no
590   elif [ -f "$CROOT/windows/system32/config/system" ]
591   then DOREG=no
592   elif [ -f "$CROOT/WINNT/system32/config/system" ]
593   then DOREG=no
594   else DOREG=yes
595   fi
596   if [ "$DOREG" = 'yes' ]
597   then echo "Not found, default Wine registry will be installed."
598   else echo "Windows registry found, will not install default Wine registry."
599   fi
600   echo
601 }
602 fi
603
604 # install default registry entries
605 if [ "$DOREG" = 'yes' ]
606 then {
607   if [ "$BINDIST" = 'no' ]
608   then {
609     echo "Compiling regedit..."
610     (cd programs/regedit; make)
611     echo
612   }
613   fi
614   echo "Preparing to install default Wine registry entries..."
615
616   # Make sure we are on a Windows drive
617   mv $LCONF $LCONF.orig
618   sed "s/\"Path\" = \"\${HOME}\"$/\"Path\" = \"\${PWD}\"/" $LCONF.orig> $LCONF
619
620   echo "Installing default Wine registry entries..."
621   echo
622   if ! $REGEDIT $DEFREG > /dev/null
623   then {
624     echo "Registry install failed."
625     mv $LCONF.orig $LCONF
626     conf_reset_question regedit_error
627     conf_question high regedit_error
628     exit 1
629   }
630   else {
631     echo
632     echo "Registry entries successfully installed."
633     mv $LCONF.orig $LCONF
634   }
635   fi
636   if [ "$SYSREG" = 'auto' ]
637   then SYSREG=yes
638   fi
639 }
640 fi
641
642 # make root's registry global, if desired
643 if [ `whoami` = 'root' ] && [ "$DOREG" = 'yes' ] && [ "$SYSREG" = 'yes' ]
644 then {
645   [ -d ~/.wine ] || mkdir ~/.wine
646   if ! [ -f $sysconfdir/wine.userreg ]
647   then {
648     echo "Linking root's user registry hive to the global registry..."
649     [ -f ~/.wine/wine.userreg ] && cp ~/.wine/wine.userreg $sysconfdir/wine.userreg
650     ln -sf $sysconfdir/wine.userreg ~/.wine/wine.userreg
651   }
652   fi
653   if ! [ -f $sysconfdir/wine.systemreg ]
654   then {
655     echo "Linking root's system registry hive to the global registry..."
656     [ -f ~/.wine/system.reg ] && cp ~/.wine/system.reg $sysconfdir/wine.systemreg
657     ln -sf $sysconfdir/wine.systemreg ~/.wine/system.reg
658   }
659   fi
660 }
661 fi
662
663 # cleanup any temporary files that may remain
664 if [ -f $TMPCONF ]
665 then rm -f $TMPCONF
666 fi
667
668
669 # it's a wrap
670 echo
671 echo "Installation complete for now. Good luck (this is still alpha software)."
672 echo "If you have problems with WINE, please read the documentation first,"
673 echo "as many kinds of potential problems are explained there."
674
675 exit 0