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