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