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