Patch up old bad permissions
[webmin.git] / setup.sh
1 #!/bin/sh
2 # setup.sh
3 # This script should be run after the webmin archive is unpacked, in order
4 # to setup the various config files
5
6 # Find install directory
7 LANG=
8 export LANG
9 cd `dirname $0`
10 if [ -x /bin/pwd ]; then
11         wadir=`/bin/pwd`
12 else
13         wadir=`pwd`;
14 fi
15 srcdir=$wadir
16 ver=`cat "$wadir/version"`
17
18 # Find temp directory
19 if [ "$tempdir" = "" ]; then
20         tempdir=/tmp/.webmin
21 fi
22
23 if [ $? != "0" ]; then
24         echo "ERROR: Cannot find the Webmin install directory";
25         echo "";
26         exit 1;
27 fi
28
29 echo "***********************************************************************"
30 echo "*            Welcome to the Webmin setup script, version $ver        *"
31 echo "***********************************************************************"
32 echo "Webmin is a web-based interface that allows Unix-like operating"
33 echo "systems and common Unix services to be easily administered."
34 echo ""
35
36 # Only root can run this
37 id | grep "uid=0(" >/dev/null
38 if [ $? != "0" ]; then
39         uname -a | grep -i CYGWIN >/dev/null
40         if [ $? != "0" ]; then
41                 echo "ERROR: The Webmin install script must be run as root";
42                 echo "";
43                 exit 1;
44         fi
45 fi
46
47 # Use the supplied destination directory, if any
48 if [ "$1" != "" ]; then
49         wadir=$1
50         echo "Installing Webmin from $srcdir to $wadir ..."
51         if [ ! -d "$wadir" ]; then
52                 mkdir "$wadir"
53                 if [ "$?" != "0" ]; then
54                         echo "ERROR: Failed to create $wadir"
55                         echo ""
56                         exit 1
57                 fi
58         else
59                 # Make sure dest dir is not in use
60                 ls "$wadir" | grep -v rpmsave >/dev/null 2>&1
61                 if [ "$?" = "0" -a ! -r "$wadir/setup.sh" ]; then
62                         echo "ERROR: Installation directory $wadir contains other files"
63                         echo ""
64                         exit 1
65                 fi
66         fi
67 else
68         echo "Installing Webmin in $wadir ..."
69 fi
70 cd "$wadir"
71
72 # Work out perl library path
73 PERLLIB=$wadir
74 if [ "$perllib" != "" ]; then
75         PERLLIB="$PERLLIB:$perllib"
76 fi
77
78 # Validate source directory
79 allmods=`cd "$srcdir"; echo */module.info | sed -e 's/\/module.info//g'`
80 defaultallmods=`cd "$srcdir"; echo */module.info | xargs grep -L nondefault=1 2>/dev/null | sed -e 's/\/module.info//g'`
81 if [ "$defaultallmods" = "" ]; then
82         defaultallmods="$allmods"
83 fi
84 if [ "$allmods" = "" ]; then
85         echo "ERROR: Failed to get module list"
86         echo ""
87         exit 1
88 fi
89 echo ""
90
91 # Load package-defined variable overrides
92 if [ -r "$srcdir/setup-pre.sh" ]; then
93         . "$srcdir/setup-pre.sh"
94 fi
95
96 # Ask for webmin config directory
97 echo "***********************************************************************"
98 echo "Webmin uses separate directories for configuration files and log files."
99 echo "Unless you want to run multiple versions of Webmin at the same time"
100 echo "you can just accept the defaults."
101 echo ""
102 printf "Config file directory [/etc/webmin]: "
103 if [ "$config_dir" = "" ]; then
104         read config_dir
105 fi
106 if [ "$config_dir" = "" ]; then
107         config_dir=/etc/webmin
108 fi
109 abspath=`echo $config_dir | grep "^/"`
110 if [ "$abspath" = "" ]; then
111         echo "Config directory must be an absolute path"
112         echo ""
113         exit 2
114 fi
115 if [ ! -d $config_dir ]; then
116         mkdir $config_dir;
117         if [ $? != 0 ]; then
118                 echo "ERROR: Failed to create directory $config_dir"
119                 echo ""
120                 exit 2
121         fi
122 fi
123 if [ -r "$config_dir/config" ]; then
124         echo "Found existing Webmin configuration in $config_dir"
125         echo ""
126         upgrading=1
127 fi
128
129 # Check if upgrading from an old version
130 if [ "$upgrading" = 1 ]; then
131         echo ""
132
133         # Get current var path
134         var_dir=`cat $config_dir/var-path`
135
136         # Force creation if non-existant
137         mkdir -p $var_dir >/dev/null 2>&1
138
139         # Get current perl path
140         perl=`cat $config_dir/perl-path`
141
142         # Create temp files directory
143         $perl "$srcdir/maketemp.pl"
144         if [ "$?" != "0" ]; then
145                 echo "ERROR: Failed to create or check temp files directory $tempdir"
146                 echo ""
147                 exit 2
148         fi
149
150         # Get old os name and version
151         os_type=`grep "^os_type=" $config_dir/config | sed -e 's/os_type=//g'`
152         os_version=`grep "^os_version=" $config_dir/config | sed -e 's/os_version=//g'`
153         real_os_type=`grep "^real_os_type=" $config_dir/config | sed -e 's/real_os_type=//g'`
154         real_os_version=`grep "^real_os_version=" $config_dir/config | sed -e 's/real_os_version=//g'`
155
156         # Get old root, host, port, ssl and boot flag
157         oldwadir=`grep "^root=" $config_dir/miniserv.conf | sed -e 's/root=//g'`
158         port=`grep "^port=" $config_dir/miniserv.conf | sed -e 's/port=//g'`
159         ssl=`grep "^ssl=" $config_dir/miniserv.conf | sed -e 's/ssl=//g'`
160         atboot=`grep "^atboot=" $config_dir/miniserv.conf | sed -e 's/atboot=//g'`
161         inetd=`grep "^inetd=" $config_dir/miniserv.conf | sed -e 's/inetd=//g'`
162
163         if [ "$inetd" != "1" ]; then
164                 # Stop old version
165                 $config_dir/stop >/dev/null 2>&1
166         fi
167
168         # Copy files to target directory
169         if [ "$wadir" != "$srcdir" ]; then
170                 echo "Copying files to $wadir .."
171                 (cd "$srcdir" ; tar cf - . | (cd "$wadir" ; tar xf -))
172                 echo "..done"
173                 echo ""
174         fi
175
176         # Update ACLs
177         $perl "$wadir/newmods.pl" $config_dir $allmods
178
179         # Update miniserv.conf with new root directory and mime types file
180         grep -v "^root=" $config_dir/miniserv.conf | grep -v "^mimetypes=" >$tempdir/$$.miniserv.conf
181         if [ $? != "0" ]; then exit 1; fi
182         mv $tempdir/$$.miniserv.conf $config_dir/miniserv.conf
183         echo "root=$wadir" >> $config_dir/miniserv.conf
184         echo "mimetypes=$wadir/mime.types" >> $config_dir/miniserv.conf
185         grep logout= $config_dir/miniserv.conf >/dev/null
186         if [ $? != "0" ]; then
187                 echo "logout=$config_dir/logout-flag" >> $config_dir/miniserv.conf
188         fi
189         
190         # Check for third-party modules in old version
191         if [ "$wadir" != "$oldwadir" ]; then
192                 echo "Checking for third-party modules .."
193                 if [ "$webmin_upgrade" != "" ]; then
194                         autothird=1
195                 fi
196                 $perl "$wadir/thirdparty.pl" "$wadir" "$oldwadir" $autothird
197                 echo "..done"
198                 echo ""
199         fi
200
201         # Remove old cache of module infos
202         rm -f $config_dir/module.infos.cache
203 else
204         # Config directory exists .. make sure it is not in use
205         ls $config_dir | grep -v rpmsave >/dev/null 2>&1
206         if [ "$?" = "0" -a "$config_dir" != "/etc/webmin" ]; then
207                 echo "ERROR: Config directory $config_dir is not empty"
208                 echo ""
209                 exit 2
210         fi
211
212         # Ask for log directory
213         printf "Log file directory [/var/webmin]: "
214         if [ "$var_dir" = "" ]; then
215                 read var_dir
216         fi
217         if [ "$var_dir" = "" ]; then
218                 var_dir=/var/webmin
219         fi
220         abspath=`echo $var_dir | grep "^/"`
221         if [ "$abspath" = "" ]; then
222                 echo "Log file directory must be an absolute path"
223                 echo ""
224                 exit 3
225         fi
226         if [ "$var_dir" = "/" ]; then
227                 echo "Log directory cannot be /"
228                 exit ""
229                 exit 3
230         fi
231         if [ ! -d $var_dir ]; then
232                 mkdir $var_dir
233                 if [ $? != 0 ]; then
234                         echo "ERROR: Failed to create directory $var_dir"
235                         echo ""
236                         exit 3
237                 fi
238         fi
239         echo ""
240
241         # Ask where perl is installed
242         echo "***********************************************************************"
243         echo "Webmin is written entirely in Perl. Please enter the full path to the"
244         echo "Perl 5 interpreter on your system."
245         echo ""
246         if [ -x /usr/bin/perl ]; then
247                 perldef=/usr/bin/perl
248         elif [ -x /usr/local/bin/perl ]; then
249                 perldef=/usr/local/bin/perl
250         else
251                 perldef=""
252         fi
253         if [ "$perl" = "" ]; then
254                 if [ "$perldef" = "" ]; then
255                         printf "Full path to perl: "
256                         read perl
257                         if [ "$perl" = "" ]; then
258                                 echo "ERROR: No path entered!"
259                                 echo ""
260                                 exit 4
261                         fi
262                 else
263                         printf "Full path to perl (default $perldef): "
264                         read perl
265                         if [ "$perl" = "" ]; then
266                                 perl=$perldef
267                         fi
268                 fi
269         fi
270         echo ""
271
272         # Test perl 
273         echo "Testing Perl ..."
274         if [ ! -x $perl ]; then
275                 echo "ERROR: Failed to find perl at $perl"
276                 echo ""
277                 exit 5
278         fi
279         $perl -e 'print "foobar\n"' 2>/dev/null | grep foobar >/dev/null
280         if [ $? != "0" ]; then
281                 echo "ERROR: Failed to run test perl script. Maybe $perl is"
282                 echo "not the perl interpreter, or is not installed properly"
283                 echo ""
284                 exit 6
285         fi
286         $perl -e 'exit ($] < 5.002 ? 1 : 0)'
287         if [ $? = "1" ]; then
288                 echo "ERROR: Detected old perl version. Webmin requires"
289                 echo "perl 5.002 or better to run"
290                 echo ""
291                 exit 7
292         fi
293         $perl -e 'use Socket; print "foobar\n"' 2>/dev/null | grep foobar >/dev/null
294         if [ $? != "0" ]; then
295                 echo "ERROR: Perl Socket module not installed. Maybe Perl has"
296                 echo "not been properly installed on your system"
297                 echo ""
298                 exit 8
299         fi
300         $perl -e '$c = crypt("xx", "yy"); exit($c ? 0 : 1)'
301         if [ $? != "0" ]; then
302                 $perl -e 'use Crypt::UnixCrypt' >/dev/null 2>&1
303         fi
304         if [ $? != "0" ]; then
305                 echo "ERROR: Perl crypt function does not work. Maybe Perl has"
306                 echo "not been properly installed on your system"
307                 echo ""
308                 exit 8
309         fi
310         echo "Perl seems to be installed ok"
311         echo ""
312
313         # Create temp files directory
314         $perl "$srcdir/maketemp.pl"
315         if [ "$?" != "0" ]; then
316                 echo "ERROR: Failed to create or check temp files directory $tempdir"
317                 echo ""
318                 exit 2
319         fi
320
321         # Ask for operating system type
322         echo "***********************************************************************"
323         if [ "$os_type" = "" ]; then
324                 if [ "$autoos" = "" ]; then
325                         autoos=2
326                 fi
327                 $perl "$srcdir/oschooser.pl" "$srcdir/os_list.txt" $tempdir/$$.os $autoos
328                 if [ $? != 0 ]; then
329                         exit $?
330                 fi
331                 . $tempdir/$$.os
332                 rm -f $tempdir/$$.os
333         fi
334         echo "Operating system name:    $real_os_type"
335         echo "Operating system version: $real_os_version"
336         echo ""
337
338         # Ask for web server port, name and password
339         echo "***********************************************************************"
340         echo "Webmin uses its own password protected web server to provide access"
341         echo "to the administration programs. The setup script needs to know :"
342         echo " - What port to run the web server on. There must not be another"
343         echo "   web server already using this port."
344         echo " - The login name required to access the web server."
345         echo " - The password required to access the web server."
346         echo " - If the webserver should use SSL (if your system supports it)."
347         echo " - Whether to start webmin at boot time."
348         echo ""
349         printf "Web server port (default 10000): "
350         if [ "$port" = "" ]; then
351                 read port
352                 if [ "$port" = "" ]; then
353                         port=10000
354                 fi
355         fi
356         if [ $port -lt 1 ]; then
357                 echo "ERROR: $port is not a valid port number"
358                 echo ""
359                 exit 11
360         fi
361         if [ $port -gt 65535 ]; then
362                 echo "ERROR: $port is not a valid port number. Port numbers cannot be"
363                 echo "       greater than 65535"
364                 echo ""
365                 exit 12
366         fi
367         $perl -e 'use Socket; socket(FOO, PF_INET, SOCK_STREAM, getprotobyname("tcp")); setsockopt(FOO, SOL_SOCKET, SO_REUSEADDR, pack("l", 1)); bind(FOO, pack_sockaddr_in($ARGV[0], INADDR_ANY)) || exit(1); exit(0);' $port
368         if [ $? != "0" ]; then
369                 echo "ERROR: TCP port $port is already in use by another program"
370                 echo ""
371                 exit 13
372         fi
373         printf "Login name (default admin): "
374         if [ "$login" = "" ]; then
375                 read login
376                 if [ "$login" = "" ]; then
377                         login="admin"
378                 fi
379         fi
380         echo "$login" | grep : >/dev/null
381         if [ "$?" = "0" ]; then
382                 echo "ERROR: Username contains a : character"
383                 echo ""
384                 exit 14
385         fi
386         echo $login | grep " " >/dev/null
387         if [ "$?" = "0" ]; then
388                 echo "ERROR: Username contains a space"
389                 echo ""
390                 exit 14
391         fi
392         if [ "$login" = "webmin" ]; then
393                 echo "ERROR: Username 'webmin' is reserved for internal use"
394                 echo ""
395                 exit 14
396         fi
397         printf "Login password: "
398         if [ "$password" = "" -a "$crypt" = "" ]; then
399                 stty -echo
400                 read password
401                 stty echo
402                 printf "\n"
403                 printf "Password again: "
404                 stty -echo
405                 read password2
406                 stty echo
407                 printf "\n"
408                 if [ "$password" != "$password2" ]; then
409                         echo "ERROR: Passwords don't match"
410                         echo ""
411                         exit 14
412                 fi
413                 echo $password | grep : >/dev/null
414                 if [ "$?" = "0" ]; then
415                         echo "ERROR: Password contains a : character"
416                         echo ""
417                         exit 14
418                 fi
419         fi
420
421         # Ask the user if SSL should be used
422         if [ "$ssl" = "" ]; then
423                 ssl=0
424                 $perl -e 'use Net::SSLeay' >/dev/null 2>/dev/null
425                 if [ $? = "0" ]; then
426                         printf "Use SSL (y/n): "
427                         read sslyn
428                         if [ "$sslyn" = "y" -o "$sslyn" = "Y" ]; then
429                                 ssl=1
430                         fi
431                 else
432                         echo "The Perl SSLeay library is not installed. SSL not available."
433                         rm -f core
434                 fi
435         fi
436
437         # Don't use SSL if missing Net::SSLeay
438         if [ "$ssl" = "1" ]; then
439                 $perl -e 'use Net::SSLeay' >/dev/null 2>/dev/null
440                 if [ $? != "0" ]; then
441                         ssl=0
442                 fi
443         fi
444
445         # Ask whether to run at boot time
446         if [ "$atboot" = "" ]; then
447                 initsupp=`grep "^os_support=" "$srcdir/init/module.info" | sed -e 's/os_support=//g' | grep $os_type`
448                 atboot=0
449                 if [ "$initsupp" != "" ]; then
450                         printf "Start Webmin at boot time (y/n): "
451                         read atbootyn
452                         if [ "$atbootyn" = "y" -o "$atbootyn" = "Y" ]; then
453                                 atboot=1
454                         fi
455                 else
456                         echo "Webmin does not support being started at boot time on your system."
457                 fi
458         fi
459         makeboot=$atboot
460
461         # Copy files to target directory
462         echo "***********************************************************************"
463         if [ "$wadir" != "$srcdir" ]; then
464                 echo "Copying files to $wadir .."
465                 (cd "$srcdir" ; tar cf - . | (cd "$wadir" ; tar xf -))
466                 echo "..done"
467                 echo ""
468         fi
469
470         # Create webserver config file
471         echo $perl > $config_dir/perl-path
472         echo $var_dir > $config_dir/var-path
473         echo "Creating web server config files.."
474         cfile=$config_dir/miniserv.conf
475         echo "port=$port" >> $cfile
476         echo "root=$wadir" >> $cfile
477         echo "mimetypes=$wadir/mime.types" >> $cfile
478         echo "addtype_cgi=internal/cgi" >> $cfile
479         echo "realm=Webmin Server" >> $cfile
480         echo "logfile=$var_dir/miniserv.log" >> $cfile
481         echo "errorlog=$var_dir/miniserv.error" >> $cfile
482         echo "pidfile=$var_dir/miniserv.pid" >> $cfile
483         echo "logtime=168" >> $cfile
484         echo "ppath=$ppath" >> $cfile
485         echo "ssl=$ssl" >> $cfile
486         echo "env_WEBMIN_CONFIG=$config_dir" >> $cfile
487         echo "env_WEBMIN_VAR=$var_dir" >> $cfile
488         echo "atboot=$atboot" >> $cfile
489         echo "logout=$config_dir/logout-flag" >> $cfile
490         if [ "$listen" != "" ]; then
491                 echo "listen=$listen" >> $cfile
492         else
493                 echo "listen=10000" >> $cfile
494         fi
495         echo "denyfile=\\.pl\$" >> $cfile
496         echo "log=1" >> $cfile
497         echo "blockhost_failures=5" >> $cfile
498         echo "blockhost_time=60" >> $cfile
499         echo "syslog=1" >> $cfile
500         if [ "$allow" != "" ]; then
501                 echo "allow=$allow" >> $cfile
502         fi
503         if [ "$session" != "" ]; then
504                 echo "session=$session" >> $cfile
505         else
506                 echo "session=1" >> $cfile
507         fi
508         if [ "$pam" != "" ]; then
509                 echo "pam=$pam" >> $cfile
510         fi
511
512         # Append package-specific info to config file
513         if [ -r "$wadir/miniserv-conf" ]; then
514                 cat "$wadir/miniserv-conf" >>$cfile
515         fi
516
517         md5pass=`$perl -e 'print crypt("test", "\\$1\\$A9wB3O18\\$zaZgqrEmb9VNltWTL454R/") eq "\\$1\\$A9wB3O18\\$zaZgqrEmb9VNltWTL454R/" ? "1\n" : "0\n"'`
518
519         ufile=$config_dir/miniserv.users
520         if [ "$crypt" != "" ]; then
521                 echo "$login:$crypt:0" > $ufile
522         else
523                 if [ "$md5pass" = "1" ]; then
524                         $perl -e 'print "$ARGV[0]:",crypt($ARGV[1], "\$1\$XXXXXXXX"),":0\n"' "$login" "$password" > $ufile
525                 else
526                         $perl -e 'print "$ARGV[0]:",crypt($ARGV[1], "XX"),":0\n"' "$login" "$password" > $ufile
527                 fi
528         fi
529         chmod 600 $ufile
530         echo "userfile=$ufile" >> $cfile
531
532         kfile=$config_dir/miniserv.pem
533         openssl version >/dev/null 2>&1
534         if [ "$?" = "0" ]; then
535                 # We can generate a new SSL key for this host
536                 host=`hostname`
537                 openssl req -newkey rsa:512 -x509 -nodes -out $tempdir/cert -keyout $tempdir/key -days 1825 >/dev/null 2>&1 <<EOF
538 .
539 .
540 .
541 Webmin Webserver on $host
542 .
543 *
544 root@$host
545 EOF
546                 if [ "$?" = "0" ]; then
547                         cat $tempdir/cert $tempdir/key >$kfile
548                 fi
549                 rm -f $tempdir/cert $tempdir/key
550         fi
551         if [ ! -r $kfile ]; then
552                 # Fall back to the built-in key
553                 cp "$wadir/miniserv.pem" $kfile
554         fi
555         chmod 600 $kfile
556         echo "keyfile=$config_dir/miniserv.pem" >> $cfile
557
558         chmod 600 $cfile
559         echo "..done"
560         echo ""
561
562         echo "Creating access control file.."
563         afile=$config_dir/webmin.acl
564         rm -f $afile
565         if [ "$defaultmods" = "" ]; then
566                 echo $login: $defaultallmods >> $afile
567         else
568                 echo $login: $defaultmods >> $afile
569         fi
570         chmod 600 $afile
571         echo "..done"
572         echo ""
573
574         if [ "$login" != "root" -a "$login" != "admin" ]; then
575                 # Allow use of RPC by this user
576                 echo rpc=1 >>$config_dir/$login.acl
577         fi
578 fi
579
580 if [ "$noperlpath" = "" ]; then
581         echo "Inserting path to perl into scripts.."
582         (find "$wadir" -name '*.cgi' -print ; find "$wadir" -name '*.pl' -print) | $perl "$wadir/perlpath.pl" $perl -
583         echo "..done"
584         echo ""
585 fi
586
587 echo "Creating start and stop scripts.."
588 rm -f $config_dir/stop $config_dir/start $config_dir/restart $config_dir/reload
589 echo "#!/bin/sh" >>$config_dir/start
590 echo "echo Starting Webmin server in $wadir" >>$config_dir/start
591 echo "trap '' 1" >>$config_dir/start
592 echo "LANG=" >>$config_dir/start
593 echo "export LANG" >>$config_dir/start
594 echo "#PERLIO=:raw" >>$config_dir/start
595 echo "unset PERLIO" >>$config_dir/start
596 echo "export PERLIO" >>$config_dir/start
597 echo "PERLLIB=$PERLLIB" >>$config_dir/start
598 echo "export PERLLIB" >>$config_dir/start
599 uname -a | grep -i 'HP/*UX' >/dev/null
600 if [ $? = "0" ]; then
601         echo "exec '$wadir/miniserv.pl' $config_dir/miniserv.conf &" >>$config_dir/start
602 else
603         echo "exec '$wadir/miniserv.pl' $config_dir/miniserv.conf" >>$config_dir/start
604 fi
605
606 echo "#!/bin/sh" >>$config_dir/stop
607 echo "echo Stopping Webmin server in $wadir" >>$config_dir/stop
608 echo "pidfile=\`grep \"^pidfile=\" $config_dir/miniserv.conf | sed -e 's/pidfile=//g'\`" >>$config_dir/stop
609 echo "kill \`cat \$pidfile\`" >>$config_dir/stop
610
611 echo "#!/bin/sh" >>$config_dir/restart
612 echo "$config_dir/stop && $config_dir/start" >>$config_dir/restart
613
614 echo "#!/bin/sh" >>$config_dir/reload
615 echo "echo Reloading Webmin server in $wadir" >>$config_dir/reload
616 echo "pidfile=\`grep \"^pidfile=\" $config_dir/miniserv.conf | sed -e 's/pidfile=//g'\`" >>$config_dir/reload
617 echo "kill -USR1 \`cat \$pidfile\`" >>$config_dir/reload
618
619 chmod 755 $config_dir/start $config_dir/stop $config_dir/restart $config_dir/reload
620 echo "..done"
621 echo ""
622
623 if [ "$upgrading" = 1 ]; then
624         echo "Updating config files.."
625 else
626         echo "Copying config files.."
627 fi
628 newmods=`$perl "$wadir/copyconfig.pl" "$os_type/$real_os_type" "$os_version/$real_os_version" "$wadir" $config_dir "" $allmods`
629 if [ "$upgrading" != 1 ]; then
630         # Store the OS and version
631         echo "os_type=$os_type" >> $config_dir/config
632         echo "os_version=$os_version" >> $config_dir/config
633         echo "real_os_type=$real_os_type" >> $config_dir/config
634         echo "real_os_version=$real_os_version" >> $config_dir/config
635         if [ -r /etc/system.cnf ]; then
636                 # Found a caldera system config file .. get the language
637                 source /etc/system.cnf
638                 if [ "$CONF_LST_LANG" = "us" ]; then
639                         CONF_LST_LANG=en
640                 elif [ "$CONF_LST_LANG" = "uk" ]; then
641                         CONF_LST_LANG=en
642                 fi
643                 grep "lang=$CONF_LST_LANG," "$wadir/lang_list.txt" >/dev/null 2>&1
644                 if [ "$?" = 0 ]; then
645                         echo "lang=$CONF_LST_LANG" >> $config_dir/config
646                 fi
647         fi
648
649         # Turn on logging by default
650         echo "log=1" >> $config_dir/config
651
652         # Use licence module specified by environment variable
653         if [ "$licence_module" != "" ]; then
654                 echo licence_module=$licence_module >>$config_dir/config
655         fi
656
657         # Disallow unknown referers by default
658         echo "referers_none=1" >>$config_dir/config
659 else
660         # one-off hack to set log variable in config from miniserv.conf
661         grep log= $config_dir/config >/dev/null
662         if [ "$?" = "1" ]; then
663                 grep log= $config_dir/miniserv.conf >> $config_dir/config
664                 grep logtime= $config_dir/miniserv.conf >> $config_dir/config
665                 grep logclear= $config_dir/miniserv.conf >> $config_dir/config
666         fi
667
668         # Disallow unknown referers if not set
669         grep referers_none= $config_dir/config >/dev/null
670         if [ "$?" != "0" ]; then
671                 echo "referers_none=1" >>$config_dir/config
672         fi
673 fi
674 echo $ver > $config_dir/version
675 echo "..done"
676 echo ""
677
678 # Set passwd_ fields in miniserv.conf from global config
679 for field in passwd_file passwd_uindex passwd_pindex passwd_cindex passwd_mindex; do
680         grep $field= $config_dir/miniserv.conf >/dev/null
681         if [ "$?" != "0" ]; then
682                 grep $field= $config_dir/config >> $config_dir/miniserv.conf
683         fi
684 done
685 grep passwd_mode= $config_dir/miniserv.conf >/dev/null
686 if [ "$?" != "0" ]; then
687         echo passwd_mode=0 >> $config_dir/miniserv.conf
688 fi
689
690 # If Perl crypt supports MD5, then make it the default
691 if [ "$md5pass" = "1" ]; then
692         echo md5pass=1 >> $config_dir/config
693 fi
694
695 # Set a special theme if none was set before
696 if [ "$theme" = "" ]; then
697         theme=`cat "$wadir/defaulttheme" 2>/dev/null`
698 fi
699 oldthemeline=`grep "^theme=" $config_dir/config`
700 oldtheme=`echo $oldthemeline | sed -e 's/theme=//g'`
701 if [ "$theme" != "" ] && [ "$oldthemeline" = "" ] && [ -d "$wadir/$theme" ]; then
702         echo "theme=$theme" >> $config_dir/config
703         echo "preroot=$theme" >> $config_dir/miniserv.conf
704 fi
705
706 # Set the product field in the global config
707 grep product= $config_dir/config >/dev/null
708 if [ "$?" != "0" ]; then
709         echo product=webmin >> $config_dir/config
710 fi
711
712 if [ "$makeboot" = "1" ]; then
713         echo "Configuring Webmin to start at boot time.."
714         (cd "$wadir/init" ; WEBMIN_CONFIG=$config_dir WEBMIN_VAR=$var_dir "$wadir/init/atboot.pl" $bootscript)
715         echo "..done"
716         echo ""
717 fi
718
719 # If password delays are not specifically disabled, enable them
720 grep passdelay= $config_dir/miniserv.conf >/dev/null
721 if [ "$?" != "0" ]; then
722         echo passdelay=1 >> $config_dir/miniserv.conf
723 fi
724
725 if [ "$nouninstall" = "" ]; then
726         echo "Creating uninstall script $config_dir/uninstall.sh .."
727         cat >$config_dir/uninstall.sh <<EOF
728 #!/bin/sh
729 printf "Are you sure you want to uninstall Webmin? (y/n) : "
730 read answer
731 printf "\n"
732 if [ "\$answer" = "y" ]; then
733         $config_dir/stop
734         echo "Running uninstall scripts .."
735         (cd "$wadir" ; WEBMIN_CONFIG=$config_dir WEBMIN_VAR=$var_dir LANG= "$wadir/run-uninstalls.pl")
736         echo "Deleting $wadir .."
737         rm -rf "$wadir"
738         echo "Deleting $config_dir .."
739         rm -rf "$config_dir"
740         echo "Done!"
741 fi
742 EOF
743         chmod +x $config_dir/uninstall.sh
744         echo "..done"
745         echo ""
746 fi
747
748 echo "Changing ownership and permissions .."
749 # Make all config dirs non-world-readable
750 for m in $newmods; do
751         chown -R root $config_dir/$m
752         chgrp -R bin $config_dir/$m
753         chmod -R og-rw $config_dir/$m
754 done
755 # Make miniserv config files non-world-readable
756 for f in miniserv.conf miniserv.pem miniserv.users; do
757         chown -R root $config_dir/$f
758         chgrp -R bin $config_dir/$f
759         chmod -R og-rw $config_dir/$f
760 done
761 chmod +r $config_dir/version
762 if [ "$nochown" = "" ]; then
763         # Make program directory non-world-writable, but executable
764         chown -R root "$wadir"
765         chgrp -R bin "$wadir"
766         chmod -R og-w "$wadir"
767         chmod -R a+rx "$wadir"
768 fi
769 if [ $var_dir != "/var" ]; then
770         # Make log directory non-world-readable or writable
771         chown -R root $var_dir
772         chgrp -R bin $var_dir
773         chmod -R og-rwx $var_dir
774 fi
775 # Fix up bad permissions from some older installs
776 for m in ldap-client ldap-server ldap-useradmin mailboxes mysql postgresql servers virtual-server; do
777         if [ -d "$config_dir/$m" ]; then
778                 chown root $config_dir/$m
779                 chgrp bin $config_dir/$m
780                 chmod og-rw $config_dir/$m
781                 chmod og-rw $config_dir/$m/config 2>/dev/null
782         fi
783 done
784 echo "..done"
785 echo ""
786
787 # Save target directory if one was specified
788 if [ "$wadir" != "$srcdir" ]; then
789         echo $wadir >$config_dir/install-dir
790 else
791         rm -f $config_dir/install-dir
792 fi
793
794 if [ "$nopostinstall" = "" ]; then
795         echo "Running postinstall scripts .."
796         (cd "$wadir" ; WEBMIN_CONFIG=$config_dir WEBMIN_VAR=$var_dir "$wadir/run-postinstalls.pl")
797         echo "..done"
798         echo ""
799 fi
800
801 # Run package-defined post-install script
802 if [ -r "$srcdir/setup-post.sh" ]; then
803         . "$srcdir/setup-post.sh"
804 fi
805
806 if [ "$nostart" = "" ]; then
807         if [ "$inetd" != "1" ]; then
808                 echo "Attempting to start Webmin mini web server.."
809                 $config_dir/start
810                 if [ $? != "0" ]; then
811                         echo "ERROR: Failed to start web server!"
812                         echo ""
813                         exit 14
814                 fi
815                 echo "..done"
816                 echo ""
817         fi
818
819         echo "***********************************************************************"
820         echo "Webmin has been installed and started successfully. Use your web"
821         echo "browser to go to"
822         echo ""
823         host=`hostname`
824         if [ "$ssl" = "1" ]; then
825                 echo "  https://$host:$port/"
826         else
827                 echo "  http://$host:$port/"
828         fi
829         echo ""
830         echo "and login with the name and password you entered previously."
831         echo ""
832         if [ "$ssl" = "1" ]; then
833                 echo "Because Webmin uses SSL for encryption only, the certificate"
834                 echo "it uses is not signed by one of the recognized CAs such as"
835                 echo "Verisign. When you first connect to the Webmin server, your"
836                 echo "browser will ask you if you want to accept the certificate"
837                 echo "presented, as it does not recognize the CA. Say yes."
838                 echo ""
839         fi
840 fi
841
842 if [ "$oldwadir" != "$wadir" -a "$upgrading" = 1 -a "$deletedold" != 1 ]; then
843         echo "The directory from the previous version of Webmin"
844         echo "   $oldwadir"
845         echo "Can now be safely deleted to free up disk space, assuming"
846         echo "that all third-party modules have been copied to the new"
847         echo "version."
848         echo ""
849 fi
850
851