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