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