]> git.treefish.org Git - fex.git/blobdiff - install
Original release 20160919
[fex.git] / install
diff --git a/install b/install
index 7ffdfc00aaf4b9277bd7bf2b4f77e4221a95f17c..c300815685cafff88ce63e82f0cd9ca5b3dd18d1 100755 (executable)
--- a/install
+++ b/install
@@ -7,6 +7,8 @@ use Socket;
 use IO::Socket::INET;
 use Digest::MD5        'md5_hex';
 
+our (@local_rdomains,@local_rhosts);
+
 $ENV{PATH} .= ':/sbin:/usr/sbin';
 
 $usage = "usage: $0 [-p port] [IP-address]\n";
@@ -18,17 +20,13 @@ 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";
-}
+# $fexupdate = '/root/bin/fexupdate';
+# die "found $fexupdate\n" if -x $fexupdate;
 
 $opt_p = 80;
 
@@ -37,13 +35,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 +58,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;
@@ -64,12 +68,13 @@ if (not $ip and open P,'host $(hostname)|') {
     }
   }
   close P;
-  print "Your IP [$guessed_ip] : ";
-  chomp($ip = <STDIN>);
+  unless (-f $xinetd) {
+    print "Your IP [$guessed_ip] : ";
+    chomp($ip = <STDIN>);
+  }
   $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;
@@ -121,7 +126,14 @@ print "prerequisites checked, ok\n";
 
 unless (getpwnam('fex')) {
   print "creating user fex\n";
-  system 'useradd -s /bin/bash -c "File EXchange" -m fex';
+  system 'groupadd --system fex 2>/dev/null || groupadd fex';
+  my @g = getgrnam('fex') or die "$0: cannot groupadd fex\n";
+  my $gid = $g[2];
+  if (getpwuid($gid)) {
+    system "useradd -s /bin/bash -c 'File EXchange' -g $gid -m fex"
+  } else {
+    system "useradd -s /bin/bash -c 'File EXchange' -u $gid -g $gid -m fex"
+  }
   exit $? if $?;
 }
 
@@ -141,11 +153,37 @@ 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?! ";
+  $_ = <STDIN>;
+  exit unless /^y/i;
+}
+
+# old bug fix
+if (-d "$FEXHOME/htdocs/locale") {
+  chmod 0755,"$FEXHOME/htdocs/locale";
+  chmod 0755,grep { -d $_ } glob("$FEXHOME/locale/*/htdocs");
+}
 
 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:0',"$FEXHOME/perl");
+}
+
 @save = (
   "lib/fex.ph",
   "lib/fup.pl",
@@ -171,27 +209,38 @@ 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";
+foreach $s (@save) {
+  $f = "$FEXHOME/$s";
+  $fs = $f.'_save';
+  $fn = $f.'_new';
+  if (-e $fs) {
+    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;
-  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 my $dir (qw'.dkeys .ukeys .akeys .skeys .gkeys .xkeys .locks') {
+  mkdir "$FEXHOME/spool/$dir",0700;
+}
+  
+chownr('fex',"$FEXHOME/spool/.");
 
-foreach $s (@save) {
-  $f = "$FEXHOME/$s";
-  $fs = $f.'_save';
-  $fn = $f.'_new';
-  if (-e $fs) {
-    system "rm -rf $fn";
-    rename $f,$fn and print "$f --> $fn\n";
-    rename $fs,$f and print "$fs --> $f\n";
+# fex-VM?
+if (open my $setup,'/root/bin/setup') {
+  while (<$setup>) {
+    exit if /#.*X-VM/;  
   }
+  close $setup;
 }
 
 system(qw'perl -p -i -e',
@@ -208,12 +257,21 @@ while (<$fph>) {
 close $fph;
 
 eval $conf;
-$spooldir ||= "$FEXHOME/spool";
+
+# die "no \$spooldir in $fph\n" unless $spooldir;
+$spooldir ||= '/home/fex/spool';
+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] : ";
@@ -231,6 +289,7 @@ if ($newinstall) {
     last if $admin =~ /.\@./;
     print "admin must be a valid email address!\n";
   }
+  $aa = "$spooldir/$admin/@";
   while (not $admin_pw) {
     print "F*EX admin password: ";
     $admin_pw = <STDIN>;
@@ -261,24 +320,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,17 +328,15 @@ 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;
+      chownr('fex',"$FEXHOME/htdocs/locale/$locale");
     } else { 
       push @nlocales,"./install $1\n";
     }
@@ -349,13 +388,14 @@ unless (-f $xinetd) {
   if ($crontab !~ /fex_cleanup/) {
     open $crontab,">fex.cron" or die "cannot create fex.cron - $!\n";
     print {$crontab} $crontab,"\n";
+    print {$crontab} " 3 2 * * * exec $FEXHOME/bin/backup\n";
     print {$crontab} " 3 3 * * * exec $FEXHOME/bin/fex_cleanup\n";
     close $crontab;
-    system qw(crontab -u fex fex.cron);
+    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:0',$FEXHOME,"$FEXHOME/spool/.","$FEXHOME/htdocs/.");
+  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 +403,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";
@@ -374,30 +414,72 @@ unless (-f $xinetd) {
 
 if (@local_rdomains and not @local_rhosts) {
   print "\nWARNING:\n";
-  print "In $fph you have @local_rdomains but not @local_rhosts!\n";
+  print "In $fph you have \@local_rdomains but not \@local_rhosts!\n";
   print "Selfregistrating of external users will not work!\n";
   print "See ${fph}_new/\n";
 }
 
-if (`$sendmail -h 2>&1` =~ /exim/ and 
+if (`$sendmail -h 2>&1 </dev/null` =~ /exim/ and 
     `grep trusted_users /etc/exim4/exim4.conf 2>/dev/null` !~ /\bfex\b/) {
   print "\nWARNING:\n";
   print "$sendmail is exim\n";
   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 +557,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) {