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