X-Git-Url: https://git.treefish.org/fex.git/blobdiff_plain/7fa382617fbaccc0ce522b2b3adbbee9db5ad227..20150615:/install?ds=sidebyside diff --git a/install b/install index 7ffdfc0..9c49c06 100755 --- a/install +++ b/install @@ -18,18 +18,11 @@ if ($<) { die "you must be root to install F*EX\n"; } -goto INSTALL if $0 =~ /upgrade$/; - $fex = 'fex.rus.uni-stuttgart.de'; if (system("host $fex >/dev/null") != 0) { die "host $fex is not resolvable - check /etc/resolv.conf\n"; } -if (`uname` =~ /^SunOS/) { - die "Solaris is currently not supported. " - ."Please contact framstag\@rus.uni-stuttgart.de for details.\n"; -} - $opt_p = 80; if (open $xinetd,$xinetd) { @@ -37,13 +30,20 @@ if (open $xinetd,$xinetd) { if (/^\s*port\s*=\s*(\d+)/) { $opt_p = $fexport = $1; } - if (/^\s*bind\s*=\s*([\d.]+)/) { + if (/^\s*bind\s*=\s*([\d.]+)$/) { $fexip = $ip = $1; } } close $xinetd; } +goto INSTALL if $0 =~ /upgrade$/; + +if (`uname` =~ /^SunOS/) { + die "Solaris is currently not supported. " + ."Please contact framstag\@rus.uni-stuttgart.de for details.\n"; +} + getopts('p:') or die $usage; $arg = shift; @@ -53,7 +53,6 @@ if ($arg and -f "locale/$arg/lib/fup.pl") { $ip = $arg || $fexip || 0; } - # if (not $ip and open P,"ifconfig 2>/dev/null |") { if (not $ip and open P,'host $(hostname)|') { $guessed_ip = 0; @@ -69,7 +68,6 @@ if (not $ip and open P,'host $(hostname)|') { $ip ||= $guessed_ip; } -$ip =~ /^\d+\.\d+\.\d+\.\d+$/ or die $usage; ($hostname) = gethostbyaddr(gethostbyname($ip),AF_INET); die "cannot find hostname for IP $ip\n" unless $hostname; @@ -141,11 +139,31 @@ umask 077; @FEX = getpwnam('fex') or die "no user fex\n"; $FEXHOME = $FEX[7]; +$ENV{HOME} = $FEXHOME; # needed for later eval fex.ph die "no HOME directory for user fex\n" unless -d $FEXHOME; +if ($FEXHOME !~ /fex/) { + print "HOME=$FEXHOME for user fex does not contain \"fex\"\n"; + print "REALLY continue?! "; + $_ = ; + exit unless /^y/i; +} print "Installing:\n"; +$pecl = "$FEXHOME/perl/Encode/ConfigLocal.pm"; +unless (-f $pecl) { + mkdir "$FEXHOME/perl"; + mkdir "$FEXHOME/perl/Encode"; + open $pecl,'>',$pecl or die "$0: cannot write $pecl - $!\n"; + print {$pecl} + "# hack for broken Perl in SuSe and Solaris, used via \@INC in fexsrv\n", + "1;\n"; + close $pecl; + print $pecl,"\n"; + chownr('fex:root',"$FEXHOME/perl"); +} + @save = ( "lib/fex.ph", "lib/fup.pl", @@ -171,29 +189,28 @@ unlink "$FEXHOME/htdocs/License"; $hl = "$FEXHOME/htdocs/locale"; unless (-d $hl) { mkdir $hl or die "$0: cannot mkdir $hl - $!\n" } -if (-d "$FEXHOME/spool") { - warn "checking spool ...\n"; - &convert_spool; - system "chown -R fex $spooldir/"; -} else { - $newinstall = $FEXHOME; - chmod 0700,$FEXHOME; - mkdir "$FEXHOME/spool",0700 or die "cannot mkdir $FEXHOME/spool - $!\n"; - mkdir "$FEXHOME/spool/.error",0700; - system "chown -R fex $FEXHOME/spool"; -} - foreach $s (@save) { $f = "$FEXHOME/$s"; $fs = $f.'_save'; $fn = $f.'_new'; if (-e $fs) { - system "rm -rf $fn"; + unlink $fn; rename $f,$fn and print "$f --> $fn\n"; rename $fs,$f and print "$fs --> $f\n"; } } +if (-d "$FEXHOME/spool") { + warn "checking $FEXHOME/spool ...\n"; + &convert_spool; +} else { + $newinstall = $FEXHOME; + chmod 0700,$FEXHOME; + mkdir "$FEXHOME/spool",0700 or die "cannot mkdir $FEXHOME/spool - $!\n"; + mkdir "$FEXHOME/spool/.error",0700; +} +chownr('fex',"$FEXHOME/spool/."); + system(qw'perl -p -i -e', 's:href="/?FAQ.html":href="/FAQ/FAQ.html":', "$FEXHOME/lib/fup.pl" @@ -208,12 +225,20 @@ while (<$fph>) { close $fph; eval $conf; -$spooldir ||= "$FEXHOME/spool"; + +die "no \$spooldir in $fph\n" unless $spooldir; +die "\$spooldir=$spooldir is not a directory, see $fph\n" unless -d $spooldir; +symlink $spooldir,"$FEXHOME/spool" unless -e "$FEXHOME/spool"; +@sds1 = stat "$spooldir/."; +@sds2 = stat "$FEXHOME/spool/."; +if ("@sds1" ne "@sds2") { + die "$FEXHOME/spool is not a symbolic link to \$spooldir=$spooldir\n"; +} $fid = "$FEXHOME/.fex/id"; $aa = "$spooldir/$admin/@"; -if ($newinstall) { +if ($newinstall or not -s $aa) { print "\n"; for (;;) { print "Server hostname [$hostname] : "; @@ -261,24 +286,6 @@ if ($newinstall) { } } -sub mkfid { - my $ad = dirname($aa); - mkdir $ad; - open $aa,'>',$aa or die "$0: cannot create $aa - $!\n"; - print {$aa} "$admin_pw\n"; - close $aa; - my $fd = dirname($fid); - mkdir $fd; - rename $fid,$fid.'_save'; - open $fid,'>',$fid or die "$0: cannot create $fid - $!\n"; - print {$fid} "$hostname:$opt_p\n"; - print {$fid} "$admin\n"; - print {$fid} "$admin_pw\n"; - close $fid; - chmod 0700,$fd; - system "chown -R fex $fd $ad"; -} - open $fph,">$fph.new" or die "$0: cannot write $fph.new - $!\n"; print {$fph} $conf; close $fph; @@ -287,15 +294,12 @@ rename "$fph.new",$fph or die "$0: cannot rename $fph.new to $fph - $!\n"; do $fph or die "$0: error in new $fph - $!\n"; -rename "locale/deutsch","locale/german" if -d "locale/deutsch"; -rename "locale/espanol","locale/spanish" if -d "locale/espanol"; - if (@locales = glob "locale/*/lib/fup.pl") { foreach (@locales) { m{locale/(.+?)/} and $locale = $1; if (-f "$FEXHOME/$_") { system 'locale/translate',$locale; - system "chown -R fex $FEXHOME/locale/$locale"; + chownr('fex',"$FEXHOME/locale/$locale"); $hl = "$FEXHOME/htdocs/locale/$locale"; symlink "$FEXHOME/locale/$locale/htdocs",$hl unless -l $hl; } else { @@ -354,8 +358,8 @@ unless (-f $xinetd) { system qw(crontab -u fex fex.cron); } - system "chown -R fex:root $FEXHOME $FEXHOME/spool/"; - system "chmod -R go-r $FEXHOME/lib $FEXHOME/cgi-bin $FEXHOME/spool/"; + chownr('fex:root',"$FEXHOME $FEXHOME/spool/."); + chmodr('go-r',"$FEXHOME/lib","$FEXHOME/cgi-bin","$FEXHOME/spool/."); print "\n"; print "Now check configuration file $FEXHOME/lib/fex.ph and run\n"; @@ -363,7 +367,7 @@ unless (-f $xinetd) { print "(You can do this as user \"fex\")\n"; } else { - system "chmod -R go-r $FEXHOME/lib $FEXHOME/cgi-bin"; + chmodr('go-r',"$FEXHOME/lib","$FEXHOME/cgi-bin"); print "\n"; print "F*EX update installed.\n"; @@ -386,18 +390,60 @@ if (`$sendmail -h 2>&1` =~ /exim/ and print "You MUST set in your exim4.conf:\n"; print "trusted_users = mail : uucp : fex\n"; } + exit; +sub mkfid { + my $ad = dirname($aa); + mkdir $ad; + open $aa,'>',$aa or die "$0: cannot create $aa - $!\n"; + print {$aa} "$admin_pw\n"; + close $aa; + my $fd = dirname($fid); + mkdir $fd; + rename $fid,$fid.'_save'; + open $fid,'>',$fid or die "$0: cannot create $fid - $!\n"; + print {$fid} "$hostname:$opt_p\n"; + print {$fid} "$admin\n"; + print {$fid} "$admin_pw\n"; + close $fid; + chownr('fex',$ad,$fd); + chmod 0700,$ad,$fd; +} + +sub chownr { + my $user = shift; + local $_; + foreach (@_) { + if (m:^/*(lib|usr|home)?/*$:) { + die "ERROR: short path in chownr $user @_\n"; + } + } + system qw'chown -R',$user,@_; +} + +sub chmodr { + my $mod = shift; + local $_; + foreach (@_) { + if (m:^/*(lib|usr|home)?/*$:) { + die "ERROR: short path in chmodr $mod @_\n"; + } + } + system qw'chmod -R',$mod,@_; +} sub convert_spool { my ($f,$d,$to,$from,$link); local $) = $FEX[3]; - local $> = $FEX[2]; + local $> = $FEX[2]; our ($spooldir,$skeydir,$gkeydir); $ENV{FEXLIB} = $FEXLIB = "$FEXHOME/lib"; require "$FEXLIB/fex.pp" or die "$0: cannot load $FEXLIB/fex.pp - $!\n"; + die "no \$spooldir in $FEXLIB/fex.pp\n" unless $spooldir; + die "\$spooldir=$spooldir/" if $spooldir =~ m:^/*(root)?$:; # User --> user@maildomain if ($mdomain) { @@ -475,6 +521,16 @@ sub convert_spool { # create new GKEYs foreach my $gf (glob "$spooldir/*/\@GROUP/*") { next unless -f $gf; + # normalize group name + if ($gf =~ m:(.+)/(.+):) { + my $gd = $1; + my $g1 = $2; + my $g2 = $2; + $g2 =~ s/[^\w\*%^+=:,.!-]/_/g; + if ($g1 ne $g2) { + rename "$gd/$g1","$gd/$g2" and $gf = "$gd/$g2"; + } + } $group = (split '/',$gf)[-1]; $user = (split '/',$gf)[-3]; if (open $gf,$gf) {