wineinstall improvements, mostly for usage in package postinstall
[wine] / tools / wineinstall
1 #!/bin/bash
2 # WINE Installation script
3 # Can do almost everything from compiling to configuring...
4
5 # Mar 31 1999 - Ove Kåven
6 #  First version
7 # Dec 9 1999 - Ove Kåven
8 #  require Xpm
9 # Feb 25 2000 - Ove Kåven
10 #  auto-add /usr/local/lib to /etc/ld.so.conf
11 # Mar 2 2000 - Ove Kåven
12 #  source rather than grep config.cache
13 #  use sourced config.cache to start ldconfig
14 #  reconfigure if config.cache doesn't exist
15 # Mar 30 2000 - Ove Kåven
16 #  autoconfigure no-windows installs
17 #  do not install registry on real-windows installs
18 #  some support for binary package installs
19 #  set and tell user about LD_LIBRARY_PATH if necessary
20 #  set EXTRA_LD_LIBRARY_PATH in wine.conf
21 # Apr 9 2000 - Ove Kåven
22 #  make root's registry global (system-default)
23 # May 9 2000 - Ove Kåven
24 #  use ttydrv when running regapi, so we don't have to run from X
25 #  change debugger path in registry
26 # Oct 29 2000 - Ove Kåven
27 #  added --enable-opengl to default confargs
28 #  added conf_question, conf_yesno_answer, and conf_string_answer functions
29 #  added DEFCAT variable
30
31 #--- defaults (change these if you are a packager)
32 CONFARGS=--enable-opengl      # configure args, e.g. --prefix=/usr --sysconfdir=/etc
33 prefix=/usr/local             # installation prefix
34 sysconfdir=$prefix/etc        # where wine.conf and global registry is supposed to be
35 bindir=$prefix/bin            # where winelib apps will be (or is) installed
36 libdir=$prefix/lib            # where libwine.so will be (or is) installed
37 exdir=documentation/samples   # where the example system.ini resides
38 CONF=$sysconfdir/wine.conf    # default path of the wine.conf
39 BINDIST=no                    # whether called from a binary package config script
40 DOCONF=auto                   # whether to autogenerate wine.conf
41 DOWCHK=auto                   # whether to autoconfigure existing-windows installation
42 DOWINE=auto                   # whether to autoconfigure no-windows installation
43 DOREG=auto                    # whether to install default registry
44 SYSREG=yes                    # whether to make root's registry global (system-default)
45
46 # "make install" still installs the dlls into $libdir, but this may change in the future
47 # (DLLPATH should point to them if/when they are not in standard ld.so paths)
48 DLLPATH=$libdir/wine          # default path of the dll .so files (except libwine.so)
49
50 # having the Wine debugger launched automatically will be a plus for us
51 DEBUGGER=$bindir/winedbg      # the (installed) path of winedbg
52 HDEBUGGER=debugger/winedbg    # the (non-installed) path of winedbg
53
54 # this is only for existing-windows installs
55 WINECONF=tools/wineconf       # the path of wineconf perl script
56
57 # this is only for no-windows installs
58 WINEINI=wine.ini              # the path of default wine.ini (also used by wineconf)
59 WININI=/dev/null              # the path of default win.ini
60 SYSTEMINI=$exdir/system.ini   # the path of default system.ini
61 REGAPI=programs/regapi/regapi # the path of regapi winelib application
62 DEFREG=winedefault.reg        # the path of the registry file to be fed to regapi
63 # CROOT=/var/wine             # the path of the fake Drive C (asks user if not set)
64 DEFCAT=cat                    # program to cat $DEFREG with (some packages need zcat)
65 #--- end of defaults
66
67 # temporary files used by the installer
68 TMPCONF=/tmp/wineinstall.conf
69 TMPREG=/tmp/wineinstall.reg
70
71 # functions
72
73 function conf_question {
74   # parameters: $1 = importance, $2 = question-id, $3+ = message lines
75   # the first two parameters can be used by e.g. debconf in debian packages
76   # but here we just print the message
77   shift 2
78   echo
79   local LINE="$1"
80   while shift
81   do {
82     echo "$LINE"
83     LINE="$1"
84   }
85   done
86 }
87
88 function conf_yesno_answer {
89   unset ANSWER
90   while [ "$ANSWER" != 'yes' ] && [ "$ANSWER" != 'no' ]
91   do {
92     echo -n "$1"
93     read ANSWER
94   }
95   done
96 }
97
98 function conf_string_answer {
99   echo -n "$1"
100   read ANSWER
101 }
102
103 # startup...
104
105 echo "WINE Installer v0.5"
106 echo
107
108 if [ "$BINDIST" = 'no' ]
109 then {
110
111 if ! [ -f configure ]
112 then {
113   echo "You're running this from the wrong directory."
114   echo "Change to the Wine directory and try again."
115   exit 1
116 }
117 fi
118
119 # check whether RPM installed, and if it is, remove any old wine rpm.
120 hash rpm &>/dev/null
121 RET=$?
122 if [ $RET -eq 0 ]; then
123   if [ -n "`rpm -qi wine 2>/dev/null|grep "^Name"`" ]; then
124     echo "Warning: Old Wine RPM install detected. Do you want to remove it first?"
125     conf_yesno_answer "(yes/no) "
126     if [ "$ANSWER" = 'yes' ]; then
127       echo Starting wine rpm removal...
128       rpm -e wine; RET=$?
129       if [ $RET -eq 0 ]; then
130         echo Done.
131       else
132         echo "FAILED. Probably you aren't installing as root."
133       fi
134     else
135       echo "Sorry, I won't install Wine when an rpm version is still installed."
136       echo "(Wine support suffered from way too many conflicts)"
137       echo "Have a nice day !"
138       exit
139     fi 
140   fi
141 fi
142
143 # run the configure script, if necessary
144
145 if [ -f config.cache ] && [ -f Makefile ] && [ Makefile -nt configure ]
146 then {
147   echo "I see that WINE has already been configured, so I'll skip that."
148   # load configure results
149   . ./config.cache
150 }
151 else {
152   echo "Running configure..."
153   echo
154   if ! ./configure $CONFARGS
155   then {
156     echo
157     echo "Configure failed, aborting install."
158     rm -f config.cache
159     exit 1
160   }
161   fi
162   # load configure results
163   . ./config.cache
164   # make sure X was found
165   eval "$ac_cv_have_x"
166   if [ "$have_x" != "yes" ]
167   then {
168     echo "Install the X development headers and try again."
169     rm -f config.cache
170     exit 1
171   }
172   elif [ "$ac_cv_header_X11_xpm_h" != "yes" ]
173   then {
174     echo "Install the Xpm development headers and try again."
175     rm -f config.cache
176     exit 1
177   }
178   fi
179 }
180 fi
181
182 # now do the compilation
183
184 if [ -f wine ] && [ wine -nt Makefile ]
185 then {
186   echo "Hmm, looks like WINE is already compiled. I'll skip that too, I guess."
187 }
188 else {
189   echo "Compiling WINE. Grab a lunch or two, rent a video, or whatever, in the meantime..."
190   echo
191   if ! { make depend && make; }
192   then {
193     echo
194     echo "Compilation failed, aborting install."
195     exit 1
196   }
197   fi
198   echo
199 }
200 fi
201
202 # and installation, if root
203
204 if [ `whoami` != 'root' ]
205 then {
206   echo "You aren't root, so I'll skip the make install."
207   # setup to run from current directory
208   DLLPATH="$PWD/dlls"
209   if [ -z "$LD_LIBRARY_PATH" ]
210   then LD_LIBRARY_PATH="$PWD:$DLLPATH"
211   else LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$PWD:$DLLPATH"
212   fi
213   export LD_LIBRARY_PATH
214   DEBUGGER="$PWD/$HDEBUGGER"
215   echo
216   echo "NOTE! To run Wine without installing, you must set the environment variable"
217   echo "LD_LIBRARY_PATH to $PWD:$DLLPATH"
218   echo "in your logon scripts."
219 }
220 else {
221   echo "Now installing binaries onto the system..."
222   echo
223   if ! make install
224   then {
225     echo
226     echo "Installation failed, aborting."
227     exit 1
228   }
229   fi
230   if [ -f /etc/ld.so.conf ] && ! grep -qs "$libdir" /etc/ld.so.conf
231   then {
232     echo
233     echo "$libdir didn't exist in your /etc/ld.so.conf, adding it now..."
234     echo "$libdir" >>/etc/ld.so.conf
235     echo "Re-running ldconfig..."
236     eval "$ac_cv_path_LDCONFIG"
237   }
238   fi
239 }
240 fi
241
242 }
243 fi # BINDIST
244
245 # now check whether we should generate wine.conf
246 if [ -z "$DOCONF" ]
247 then DOCONF=auto
248 fi
249
250 if [ "$DOCONF" = 'auto' ]
251 then {
252   # see if we already have a system wine.conf
253   if [ -f $CONF ]
254   then DOCONF=no
255   fi
256 }
257 fi
258
259 if [ "$DOCONF" != 'no' ]
260 then {
261   if [ `whoami` != 'root' ]
262   then {
263     CONF=~/.winerc
264     if ! [ -f $CONF ]
265     then {
266       if [ "$DOCONF" != 'yes' ]
267       then {
268         conf_question medium make_user_winerc \
269          "Since you aren't root, and there's no system wine.conf, I assume" \
270          "you want a user-specific .winerc. Am I correct?"
271         conf_yesno_answer "(yes/no) "
272         DOCONF="$ANSWER"
273       }
274       fi
275       if [ "$DOCONF" = 'no' ]
276       then {
277         conf_question high need_root \
278          "Aborting install. Try again as root to generate a system wine.conf."
279         exit 1
280       }
281       fi
282       echo
283     }
284     fi
285   }
286   else {
287     mkdir -p $sysconfdir
288     DOCONF=yes
289   }
290   fi
291 }
292 fi
293
294 # generate wine.conf from existing windows install, if any
295 if [ "$DOCONF" = 'yes' ]
296 then {
297   if [ "$DOWCHK" = 'yes' ] || [ "$DOWCHK" = 'auto' ]
298   then {
299     echo
300     echo -n "Searching for an existing Windows installation..."
301     if ! $WINECONF > $CONF 2>/dev/null
302     then {
303       rm -f $CONF
304       echo " not found."
305       conf_question low do_without_windows \
306        "Windows was not found on your system, so I assume you want a Wine-only installation." \
307        "Am I correct?"
308       conf_yesno_answer "(yes/no) "
309       if [ "$ANSWER" = 'no' ]
310       then {
311         conf_question high windows_not_found \
312          "Aborting install. Make sure your Windows partition is mounted and try again," \
313          "or create $CONF manually by copying from $WINEINI and adapting the drive paths."
314         exit 1
315       }
316       fi
317       DOWINE=yes
318     }
319     else {
320       echo " found."
321       conf_question low windows_found \
322        "Created $CONF using your existing Windows installation." \
323        "You probably want to review the file, though."
324       DOWINE=no
325     }
326     fi
327   }
328   elif [ "$DOWINE" = 'auto' ]
329   then DOWINE=yes
330   fi
331 }
332 elif [ "$DOWINE" = 'auto' ]
333 then DOWINE=no
334 fi
335
336 # setup a no-windows installation, if necessary
337 if [ "$DOWINE" = 'yes' ]
338 then {
339   if [ `whoami` != 'root' ]
340   then DCROOT=~/c
341   else DCROOT=/c
342   fi
343   conf_question low drivec_path \
344    "Configuring Wine without Windows. Some fake Windows directories must be created, to" \
345    "hold any .ini files, DLLs, and start menu entries your applications may need to install."
346   while [ -z "$CROOT" ]
347   do {
348     conf_string_answer "Where would you like your fake C drive to be placed? (default is $DCROOT)"
349     if [ -z "$ANSWER" ]
350     then CROOT="$DCROOT"
351     fi
352     if ! [ -d "$ANSWER" ]
353     then {
354       if mkdir -p "$ANSWER"
355       then CROOT="$ANSWER"
356       fi
357     }
358     fi
359   }
360   done
361   echo "Configuring Wine for a no-windows install in $CROOT..."
362   for tdir in "$CROOT/windows" "$CROOT/windows/system" "$CROOT/windows/Start Menu" "$CROOT/windows/Start Menu/Programs" "$CROOT/Common Files" "$CROOT/windows/Profiles/Administrator" "$CROOT/Program Files"
363   do [ -d "$tdir" ] || mkdir "$tdir"
364   done
365   [ -f "$CROOT/windows/win.ini" ]    || cp "$WININI"    "$CROOT/windows/win.ini"
366   [ -f "$CROOT/windows/system.ini" ] || cp "$SYSTEMINI" "$CROOT/windows/system.ini"
367   if [ "$DOCONF" = 'yes' ]
368   then {
369     sed "s|Path=/c\$|Path=${CROOT}|" $WINEINI > $CONF
370     conf_question low default_config \
371      "Created $CONF using default Wine configuration." \
372      "You probably want to review the file, though."
373   }
374   fi
375   # now we really should install the registry
376   if [ "$DOREG" = 'auto' ]
377   then DOREG=yes
378   fi
379 }
380 elif [ -z "$CROOT" ]
381 then {
382   echo
383   echo "Reading current Wine configuration from $CONF..."
384   CROOT=`sed -n '/^\[Drive C\]$/,/^\[.*\]$/ s/^Path=\(.*\)/\1/p' $CONF`
385   echo "Drive C is configured at $CROOT."
386 }
387 fi
388 echo
389
390 # fixup EXTRA_LD_LIBRARY_PATH
391 if [ "$DOCONF" = 'yes' ]
392 then {
393   echo "Setting EXTRA_LD_LIBRARY_PATH in .winerc to $DLLPATH..."
394   sed "s|EXTRA_LD_LIBRARY_PATH=.*|EXTRA_LD_LIBRARY_PATH=${DLLPATH}|" $CONF > $CONF.new
395   mv -f $CONF.new $CONF
396   echo
397 }
398 fi
399
400 # check whether we need to install default registry
401 # (not to be done if windows registry exists)
402 if [ "$DOREG" = 'auto' ]
403 then {
404   echo "Checking for real Windows registry..."
405   if [ -f "$CROOT/windows/system.dat" ]
406   then DOREG=no
407   elif [ -f "$CROOT/windows/system32/config/system" ]
408   then DOREG=no
409   else DOREG=yes
410   fi
411   if [ "$DOREG" = 'yes' ]
412   then echo "Not found, default Wine registry will be installed."
413   else echo "Windows registry found, will not install default Wine registry."
414   fi
415   echo
416 }
417 fi
418
419 # install default registry entries
420 if [ "$DOREG" = 'yes' ]
421 then {
422   if [ "$BINDIST" = 'no' ]
423   then {
424     echo "Compiling regapi..."
425     echo
426     (cd programs/regapi; make)
427     echo
428   }
429   fi
430   echo "Preparing to install default Wine registry entries..."
431
432   # create a temporary wineinstall.conf file using ttydrv,
433   # so that we don't have to run regapi under X
434   sed "s/GraphicsDriver=.*/GraphicsDriver=ttydrv/" $CONF > $TMPCONF
435
436   # create a temporary wineinstall.reg with fixed debugger path
437   $DEFCAT $DEFREG | sed "s|debugger/winedbg|${DEBUGGER}|" > $TMPREG
438
439   echo "Installing default Wine registry entries..."
440   echo
441   if ! $REGAPI --config $TMPCONF setValue < $TMPREG > /dev/null
442   then {
443     rm -f $TMPCONF $TMPREG
444     echo "Registry install failed."
445     conf_question high regapi_error
446     exit 1
447   }
448   else echo "Registry entries successfully installed."
449   fi
450   rm -f $TMPCONF $TMPREG
451   if [ "$SYSREG" = 'auto' ]
452   then SYSREG=yes
453   fi
454 }
455 fi
456
457 # make root's registry global, if desired
458 if [ `whoami` = 'root' ] && [ "$SYSREG" = 'yes' ]
459 then {
460   [ -d ~/.wine ] || mkdir ~/.wine
461   if ! [ -f $sysconfdir/wine.userreg ]
462   then {
463     echo "Linking root's user registry hive to the global registry..."
464     cp ~/.wine/wine.userreg $sysconfdir/wine.userreg
465     ln -sf $sysconfdir/wine.userreg ~/.wine/wine.userreg
466   }
467   fi
468   if ! [ -f $sysconfdir/wine.systemreg ]
469   then {
470     echo "Linking root's system registry hive to the global registry..."
471     cp ~/.wine/system.reg $sysconfdir/wine.systemreg
472     ln -sf $sysconfdir/wine.systemreg ~/.wine/system.reg
473   }
474   fi
475 }
476 fi
477
478 # it's a wrap
479 echo
480 echo "Installation complete for now. Good luck (this is still alpha software)."
481 echo "If you have problems with WINE, please read the documentation first,"
482 echo "as many kinds of potential problems are explained there."