Make wineinstall use wineprefixcreate instead of duplicating the
[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 LCONF=~/.wine/config          # default path of the local config file
30 BINDIST=no                    # whether called from a binary package config script
31 DOLOCALCONF=auto              # whether to autogenerate localconf
32 DOWCHK=auto                   # whether to autoconfigure existing-windows installation
33 DOWINE=auto                   # whether to autoconfigure no-windows installation
34 DOREG=auto                    # whether to install default registry
35 DOAPP=auto                    # whether to install applications, distributed with Wine
36 SYSREG=yes                    # whether to make root's registry global (system-default)
37
38 # this is only for existing-windows installs
39 WINECONF=tools/wineconf       # path to the wineconf perl script
40
41 # this is only for no-windows installs
42 WINEINI=$exdir/config         # path to the default wine config file (also used by wineconf)
43 # CROOT=/var/wine             # path of the fake Drive C (asks user if not set)
44 #--- end of defaults
45
46 # temporary files used by the installer
47 TMPCONF=/tmp/wineinstall.conf
48
49 # functions
50
51 function std_sleep {
52   sleep 1
53 }
54
55 function conf_question {
56   # parameters: $1 = importance, $2 = question-id, $3+ = message lines
57   # the first two parameters can be used by e.g. debconf in debian packages
58   # but here we just print the message
59   shift 2
60   echo
61   local LINE="$1"
62   while shift
63   do {
64     echo "$LINE"
65     LINE="$1"
66   }
67   done
68 }
69
70 function conf_reset_question {
71   # parameters: $1 = question-id
72   # this is used to flush any cached answers and "already-displayed" flags
73   shift # dummy command
74 }
75
76 function conf_yesno_answer {
77   unset ANSWER
78   while [ "$ANSWER" != 'yes' ] && [ "$ANSWER" != 'no' ]
79   do {
80     echo -n "$1"
81     read ANSWER
82   }
83   done
84 }
85
86 function conf_string_answer {
87   echo -n "$1"
88   read ANSWER
89 }
90
91 # startup...
92
93 echo "WINE Installer v0.74"
94 echo
95
96 if [ "$BINDIST" = 'no' ]
97 then {
98
99   if ! [ -f configure ]
100   then {
101     if [ -f ../configure ]
102     then {
103       pushd ..
104     }
105     else {
106       echo "You're running this from the wrong directory."
107       echo "Change to the Wine source's main directory and try again."
108       exit 1
109     }
110     fi
111   }
112   fi
113
114   if [ `whoami` = 'root' ]
115   then {
116     echo "You are running wineinstall as root, this is not advisable. Please rerun as a user."
117     echo "Aborting."
118     exit 1
119   }
120   fi
121
122   if [ ! -w . ]
123   then {
124     echo "The source directory is not writable. You probably extracted the sources as root."
125     echo "You should remove the source tree and extract it again as a normal user."
126     exit 1
127   }
128   fi
129
130   # check whether RPM installed, and if it is, remove any old wine rpm.
131   hash rpm &>/dev/null
132   RET=$?
133   if [ $RET -eq 0 ]; then
134     if [ -n "`rpm -qi wine 2>/dev/null|grep "^Name"`" ]; then
135       echo "Warning: Old Wine RPM install detected. Do you want to remove it first?"
136       conf_yesno_answer "(yes/no) "
137       if [ "$ANSWER" = 'yes' ]; then
138         echo "We need to remove the rpm as root, please enter your root password"
139         echo
140         echo Starting wine rpm removal...
141         su -c "rpm -e wine; RET=$?"
142         if [ $RET -eq 0 ]; then
143           echo Done.
144         else
145           echo "FAILED. Probably you aren't installing as root."
146           echo "Expect problems (library conflicts with existing install etc.)."
147         fi
148       else
149         echo "Sorry, I won't install Wine when an rpm version is still installed."
150         echo "(Wine support suffered from way too many conflicts between RPM"
151         echo "and source installs)"
152         echo "Have a nice day !"
153         exit 1
154       fi
155     fi
156   fi
157
158   # check whether wine binary still available
159   if [ -n "`which wine 2>/dev/null|grep '/wine'`" ]; then
160     echo "Warning !! wine binary (still) found, which may indicate"
161     echo "a (conflicting) previous installation."
162     echo "You might want to abort and uninstall Wine first."
163     std_sleep
164   fi
165
166   # run the configure script, if necessary
167
168   if [ -f config.cache ] && [ -f Makefile ] && [ Makefile -nt configure ]
169   then {
170     echo
171     echo "I see that WINE has already been configured, so I'll skip that."
172     std_sleep
173     # load configure results
174     . ./config.cache
175   }
176   else {
177     echo "Running configure..."
178     echo
179     if ! ./configure -C $CONFARGS --prefix=$prefix
180     then {
181       echo
182       echo "Configure failed, aborting install."
183       rm -f config.cache
184       exit 1
185     }
186     fi
187     # load configure results
188     . ./config.cache
189     # make sure X was found
190     eval "$ac_cv_have_x"
191     if [ "$have_x" != "yes" ]
192     then {
193       echo "Install the X development headers and try again."
194       rm -f config.cache
195       exit 1
196     }
197     fi
198   }
199   fi
200
201   # now do the compilation and install, we need to always do this because we
202   # don't want the 'make install' command we might run to run 'make' as root
203   if [ `whoami` != 'root' ]
204   then {
205     # ask the user if they want to build and install wine
206     echo
207     echo "We need to install wine as root user, do you want us to build wine,"
208     echo "'su root' and install Wine?  Enter 'no' to continue without installing"
209     conf_yesno_answer "(yes/no) "
210     ROOTINSTALL="$ANSWER"
211
212     if [ "$ROOTINSTALL" = "yes" ]
213     then {
214       # start out with the basic command
215       sucommand="make install"
216
217       # if the user doesn't have $libdir in their ld.so.conf add this
218       # to our sucommand string
219       if [ -f /etc/ld.so.conf ]
220       then
221         if ! grep -s "$libdir" /etc/ld.so.conf >/dev/null 2>&1
222         then {
223           echo
224           echo "$libdir doesn't exist in your /etc/ld.so.conf, it will be added"
225           echo "when we perform the install..."
226           sucommand="$sucommand;echo $libdir>>/etc/ld.so.conf"
227         }
228         fi
229         # run ldconfig always just in case some updated files don't get linked
230         sucommand="$sucommand;$ac_cv_path_LDCONFIG"
231       fi
232     }
233     fi # [ "$ROOTINSTALL" = "yes" ]
234
235     echo
236
237     echo "Compiling WINE. Grab a lunch or two, rent a video, or whatever,"
238     echo "in the meantime..."
239     echo
240     std_sleep
241
242     # try to just make wine, if this fails 'make depend' and try to remake
243     if ! { make; }
244     then {
245       if ! { make depend && make; }
246       then {
247         echo
248         echo "Compilation failed, aborting install."
249         exit 1
250       }
251       fi
252     }
253     fi
254
255     if [ "$ROOTINSTALL" = "yes" ]
256     then {
257       echo
258
259       echo "Performing 'make install' as root to install binaries, enter root password"
260
261       std_sleep
262
263       if ! su root -c "$sucommand"
264       then {
265         if ! su root -c "$sucommand"
266         then {
267              echo
268              echo "Either you entered an incorrect password or we failed to"
269              echo "run '$sucommand' correctly."
270              echo "If you didn't enter an incorrect password then please"
271              echo "report this error and any steps to possibly reproduce it to"
272              echo "http://bugs.winehq.org/"
273              echo
274              echo "Installation failed, aborting."
275              exit 1
276          }
277          fi
278        }
279       fi
280
281       echo
282
283       # see if wine is installed on the users system, if not prompt them
284       # and then exit
285       if [ ! `which wine` ]
286       then
287         echo "Could not find wine on your system.  Run wineinstall as root to install wine"
288         echo "before re-running wineinstall as a user."
289         echo
290         echo "Exiting wineinstall"
291         exit 1;
292       fi
293
294       WINEINSTALLED=yes
295     }
296     else {
297       WINEINSTALLED=no
298     }
299     fi # [ "$ROOTINSTALL" = "yes" ]
300   }
301   fi # [ `whoami` != 'root' ]
302
303 }
304 fi # BINDIST
305
306 # now check whether we should generate wine.conf
307 if [ "$DOLOCALCONF" = 'auto' ]
308 then {
309   # see if the user is root, if so, explicitly ask them if they want a
310   # local config file
311   if [ `whoami` = 'root' ]
312   then
313     echo "You are running as root.  Do you want a local config file,"
314     echo "file, ~/.wine/config, created?"
315     conf_yesno_answer "(yes/no) "
316     DOLOCALCONF="$ANSWER"
317   else
318     # if the user has an existing config file ask them if they want us to
319     # overwrite it, otherwise just ask them if they want to create one
320     if [ -f "$LCONF" ]
321     then
322       echo "Found existing $LCONF, do you want to overwrite this"
323       echo "existing Wine configuration file?"
324       conf_yesno_answer "(yes/no) "
325       DOLOCALCONF="$ANSWER"
326       echo
327       if [ "$ANSWER" = "yes" ]
328       then
329       {
330         echo "Would you like to make a backup of this old config file?"
331         conf_yesno_answer "(yes/no) "
332         echo
333         if [ "$ANSWER" = "yes" ]
334         then
335         {
336           echo "Renaming $LCONF to $LCONF.old"
337           mv -f "$LCONF" "$LCONF.old"
338           echo
339         }
340         fi
341       }
342       fi
343     else
344     {
345       echo "Create local config file ~/.wine/config?"
346       conf_yesno_answer "(yes/no) "
347       DOLOCALCONF="$ANSWER"
348       echo
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     }
356     fi
357   fi
358 }
359 fi
360
361 # generate $TMPCONF from existing windows install, if any
362 if [ "$DOLOCALCONF" = 'yes' ]
363 then {
364   if [ "$DOWCHK" = 'yes' ] || [ "$DOWCHK" = 'auto' ]
365   then {
366     echo -n "Searching for an existing Windows installation..."
367     if ! $WINECONF -inifile "$WINEINI" > $TMPCONF 2>/dev/null
368     then {
369       rm -f $TMPCONF > /dev/null
370
371       echo " not found. (no matching /etc/fstab mount entry found)"
372       conf_question low do_without_windows \
373        "Windows was not found on your system, so I assume you want" \
374        "a Wine-only installation. Am I correct?"
375       conf_yesno_answer "(yes/no) "
376       if [ "$ANSWER" = 'no' ]
377       then {
378         conf_question high windows_not_found \
379          "Aborting install. Make sure your Windows partition is mounted and try again," \
380          "or create $LCONF manually by copying from $WINEINI and adapting the drive paths."
381         exit 1
382       }
383       fi
384       DOWINE=yes
385     }
386     else {
387       echo " found."
388
389       conf_question low do_without_windows \
390        "Windows was found on your system, and so we can use the Windows" \
391        "Drive as our Wine drive. You may, however, wish to create a clean" \
392        "Wine install anyways."
393       conf_yesno_answer "Should I use the Windows drive for the Wine install? (yes/no) "
394       if [ "$ANSWER" = 'yes' ]
395       then {
396         conf_reset_question windows_found
397         conf_question low windows_found \
398          "Created $LCONF using your existing Windows installation." \
399          "You probably want to review the file, though."
400         DOWINE=no
401       }
402       else {
403         DOWINE=yes
404       }
405       fi
406     }
407     fi
408   }
409   elif [ "$DOWINE" = 'auto' ]
410   then DOWINE=yes
411   fi
412 }
413 elif [ "$DOWINE" = 'auto' ]
414 then
415   DOWINE=no
416 fi
417
418 # setup a no-windows installation, if necessary
419 if [ "$DOWINE" = 'yes' ]
420 then {
421   # set an appropriate DCROOT
422   if [ `whoami` != 'root' ]
423   then DCROOT=~/.wine/drive_c
424   else DCROOT=/c
425   fi
426
427   conf_question low drivec_path \
428      "Configuring Wine without Windows." \
429      "Some fake Windows directories must be created, to hold any .ini files, DLLs," \
430      "start menu entries, and other things your applications may need to install." \
431      "Where would you like your fake C drive to be placed?"
432   while [ -z "$CROOT" ]
433   do {
434     conf_string_answer "(default is $DCROOT) "
435     [ -z "$ANSWER" ] && ANSWER="$DCROOT"
436     if ! [ -d "$ANSWER" ]
437     then {
438       if mkdir -p "$ANSWER"
439       then CROOT="$ANSWER"
440       else
441           echo "Directory $ANSWER can't be created !"
442           conf_reset_question drivec_path
443       fi
444     }
445     else CROOT="$ANSWER"
446     fi
447   }
448   done
449   echo "Configuring Wine for a no-windows install in $CROOT..."
450
451   if [ ! -d ~/.wine/dosdevices ]
452   then
453     mkdir ~/.wine/dosdevices
454     ln -s /mnt/fd0 ~/.wine/dosdevices/a:
455     ln -s $CROOT ~/.wine/dosdevices/c:
456     ln -s /cdrom ~/.wine/dosdevices/d:
457     ln -s /tmp ~/.wine/dosdevices/e:
458     ln -s ~ ~/.wine/dosdevices/f:
459     ln -s / ~/.wine/dosdevices/z:
460   fi
461
462   if [ "$WINEINSTALLED" = 'no' ]
463   then
464       tools/wineprefixcreate --update --use-wine-tree .
465   else
466       wineprefixcreate --update
467   fi
468
469   # create $LCONF using the default config file $WINEINI
470   if [ "$DOLOCALCONF" = 'yes' ]
471   then {
472     cp $WINEINI $TMPCONF
473     conf_reset_question default_config
474     conf_question low default_config \
475      "Created $LCONF using default Wine configuration." \
476      "You probably want to review the file, though."
477   }
478   fi
479
480   # now we really should install the registry
481   if [ "$DOREG" = 'auto' ]
482   then DOREG=yes
483   fi
484 }
485 fi
486 echo
487
488 #install the local config file $LCONF
489 if [ "$DOLOCALCONF" = 'yes' ]
490 then
491   if [ ! -w ~/.wine ]
492   then
493     mkdir ~/.wine
494   fi
495   cp $TMPCONF $LCONF > /dev/null
496 else
497   DOREG=no
498 fi
499
500 # make root's registry global, if desired
501 if [ `whoami` = 'root' ] && [ "$DOREG" = 'yes' ] && [ "$SYSREG" = 'yes' ]
502 then {
503   [ -d ~/.wine ] || mkdir ~/.wine
504   if ! [ -f $sysconfdir/wine.userreg ]
505   then {
506     echo "Linking root's user registry hive to the global registry..."
507     [ -f ~/.wine/wine.userreg ] && cp ~/.wine/wine.userreg $sysconfdir/wine.userreg
508     ln -sf $sysconfdir/wine.userreg ~/.wine/wine.userreg
509   }
510   fi
511   if ! [ -f $sysconfdir/wine.systemreg ]
512   then {
513     echo "Linking root's system registry hive to the global registry..."
514     [ -f ~/.wine/system.reg ] && cp ~/.wine/system.reg $sysconfdir/wine.systemreg
515     ln -sf $sysconfdir/wine.systemreg ~/.wine/system.reg
516   }
517   fi
518 }
519 fi
520
521 # cleanup any temporary files that may remain
522 if [ -f $TMPCONF ]
523 then rm -f $TMPCONF
524 fi
525
526
527 # it's a wrap
528 echo
529 echo "Installation complete for now. Good luck (this is still alpha software)."
530 echo "If you have problems with WINE, please read the documentation first,"
531 echo "as many kinds of potential problems are explained there."
532
533 exit 0