8 use Digest::MD5 'md5_hex';
10 $ENV{PATH} .= ':/sbin:/usr/sbin';
12 $usage = "usage: $0 [-p port] [IP-address]\n";
13 $xinetd = '/etc/xinetd.d/fex';
18 die "you must be root to install F*EX\n";
21 $fex = 'fex.rus.uni-stuttgart.de';
22 if (system("host $fex >/dev/null") != 0) {
23 die "host $fex is not resolvable - check /etc/resolv.conf\n";
28 if (open $xinetd,$xinetd) {
30 if (/^\s*port\s*=\s*(\d+)/) {
31 $opt_p = $fexport = $1;
33 if (/^\s*bind\s*=\s*([\d.]+)$/) {
40 goto INSTALL if $0 =~ /upgrade$/;
42 if (`uname` =~ /^SunOS/) {
43 die "Solaris is currently not supported. "
44 ."Please contact framstag\@rus.uni-stuttgart.de for details.\n";
47 getopts('p:') or die $usage;
50 if ($arg and -f "locale/$arg/lib/fup.pl") {
51 exec 'locale/translate',$arg;
53 $ip = $arg || $fexip || 0;
56 # if (not $ip and open P,"ifconfig 2>/dev/null |") {
57 if (not $ip and open P,'host $(hostname)|') {
60 if (/(\d+\.\d+\.\d+\.\d+)/) {
67 print "Your IP [$guessed_ip] : ";
74 ($hostname) = gethostbyaddr(gethostbyname($ip),AF_INET);
75 die "cannot find hostname for IP $ip\n" unless $hostname;
77 print "checking prerequisites\n";
79 if (`which xinetd` =~ m{^/}) {
80 print "found xinetd\n";
82 print "xinetd executable NOT found\n";
86 foreach (qw'/usr/lib/sendmail /usr/sbin/sendmail') {
89 print "found $sendmail\n";
94 print "sendmail NOT found\n";
99 print "installation aborted, nothing has been touched yet\n";
100 print "what now? ==> see doc/installation\n";
106 $SH = IO::Socket::INET->new(
113 print "There is already a tcp-service running on $ip:$opt_p !\n";
114 print "Select another port for F*EX by running $0 -p OTHERPORT $ip\n";
115 print "or an alternative IP-address by running $0 OTHERADDRESS\n";
120 print "prerequisites checked, ok\n";
122 unless (getpwnam('fex')) {
123 print "creating user fex\n";
124 system 'useradd -s /bin/bash -c "File EXchange" -m fex';
128 if (open F,'/etc/passwd') {
130 $fexbash = $_ if /^fex:.*\/bash/;
135 die "no bash login shell for user fex\n";
142 @FEX = getpwnam('fex') or die "no user fex\n";
144 $ENV{HOME} = $FEXHOME; # needed for later eval fex.ph
146 die "no HOME directory for user fex\n" unless -d $FEXHOME;
147 if ($FEXHOME !~ /fex/) {
148 print "HOME=$FEXHOME for user fex does not contain \"fex\"\n";
149 print "REALLY continue?! ";
154 print "Installing:\n";
156 $pecl = "$FEXHOME/perl/Encode/ConfigLocal.pm";
158 mkdir "$FEXHOME/perl";
159 mkdir "$FEXHOME/perl/Encode";
160 open $pecl,'>',$pecl or die "$0: cannot write $pecl - $!\n";
162 "# hack for broken Perl in SuSe and Solaris, used via \@INC in fexsrv\n",
166 chownr('fex:root',"$FEXHOME/perl");
172 "lib/reactivation.txt",
176 "htdocs/FAQ/local.faq",
183 rename $f,$fs and print "$f --> $fs\n";
187 cpav(qw'bin cgi-bin lib etc htdocs doc',$FEXHOME);
188 unlink "$FEXHOME/doc/License";
189 unlink "$FEXHOME/htdocs/License";
191 $hl = "$FEXHOME/htdocs/locale";
192 unless (-d $hl) { mkdir $hl or die "$0: cannot mkdir $hl - $!\n" }
200 rename $f,$fn and print "$f --> $fn\n";
201 rename $fs,$f and print "$fs --> $f\n";
205 if (-d "$FEXHOME/spool") {
206 warn "checking $FEXHOME/spool ...\n";
209 $newinstall = $FEXHOME;
211 mkdir "$FEXHOME/spool",0700 or die "cannot mkdir $FEXHOME/spool - $!\n";
212 mkdir "$FEXHOME/spool/.error",0700;
214 chownr('fex',"$FEXHOME/spool/.");
217 if (open my $setup,'/root/bin/setup') {
224 system(qw'perl -p -i -e',
225 's:href="/?FAQ.html":href="/FAQ/FAQ.html":',
226 "$FEXHOME/lib/fup.pl"
229 $fph = "$FEXHOME/lib/fex.ph";
230 open $fph,$fph or die "cannot read $fph - $!\n";
232 s/'MYHOSTNAME.MYDOMAIN'/'$hostname'/;
239 # die "no \$spooldir in $fph\n" unless $spooldir;
240 $spooldir ||= '/home/fex/spool';
241 die "\$spooldir=$spooldir is not a directory, see $fph\n" unless -d $spooldir;
242 symlink $spooldir,"$FEXHOME/spool" unless -e "$FEXHOME/spool";
243 @sds1 = stat "$spooldir/.";
244 @sds2 = stat "$FEXHOME/spool/.";
245 if ("@sds1" ne "@sds2") {
246 die "$FEXHOME/spool is not a symbolic link to \$spooldir=$spooldir\n";
249 $fid = "$FEXHOME/.fex/id";
250 $aa = "$spooldir/$admin/@";
252 if ($newinstall or not -s $aa) {
255 print "Server hostname [$hostname] : ";
258 $hostname = $_ if $_;
259 last if gethostbyname($hostname);
260 print "No DNS for $hostname\n";
263 print "F*EX admin [$admin] : ";
267 last if $admin =~ /.\@./;
268 print "admin must be a valid email address!\n";
270 $aa = "$spooldir/$admin/@";
271 while (not $admin_pw) {
272 print "F*EX admin password: ";
274 $admin_pw =~ s/\s//g;
277 print "(admin password is in $aa)\n";
278 $conf =~ s/^\s*\$hostname\s*=.*/\$hostname = '$hostname';/m;
279 $conf =~ s/^\s*\$admin\s*=.*/\$admin = '$admin';/m;
282 print "\nFound old \$admin_pw in $fph !\n";
283 print "This is no longer supported for security reason.\n";
288 if ($_ ne $admin_pw) {
289 print "\nYou have to delete \$admin_pw in $fph and run\n";
290 print "$FEXHOME/bin/fac -u $admin $admin_pw\n";
291 print "\nThen rerun $0\n";
296 print "\$admin_pw is transfered to auth-ID in $aa\n\n";
297 $conf =~ s/^\s*(\$admin_pw)\s*=.*/# $1 is now auth_ID of user \$admin/m;
301 open $fph,">$fph.new" or die "$0: cannot write $fph.new - $!\n";
304 system "chown fex $fph.new";
305 rename "$fph.new",$fph or die "$0: cannot rename $fph.new to $fph - $!\n";
307 do $fph or die "$0: error in new $fph - $!\n";
309 if (@locales = glob "locale/*/lib/fup.pl") {
311 m{locale/(.+?)/} and $locale = $1;
312 if (-f "$FEXHOME/$_") {
313 system 'locale/translate',$locale;
314 chownr('fex',"$FEXHOME/locale/$locale");
315 $hl = "$FEXHOME/htdocs/locale/$locale";
316 symlink "$FEXHOME/locale/$locale/htdocs",$hl unless -l $hl;
318 push @nlocales,"./install $1\n";
322 if (glob "$FEXHOME/locale/*/lib/fup.pl") {
323 print "\nTo install another localized version, type:\n";
325 print "\nTo install a localized version, type:\n";
331 $fph = "$FEXHOME/lib/fex.ph";
334 unless (-f $xinetd) {
335 my $xc = '/etc/xinetd.conf';
338 if (/^\s*only_from/) {
339 print "WARNING: found \"only_from\" in $xc : fexsrv is restricted!\n";
344 if (-d '/etc/xinetd.d') {
345 unless (-f $xinetd) {
346 open $xinetd,">$xinetd" or die "cannot write $xinetd - $!\n";
347 open F,'etc/xinetd_fex' or die "cannot read etc/xinetd_fex - $!\n";
356 system qw'/etc/init.d/xinetd restart';
357 print "WARNING: cannot restart xinetd\n" if $?;
360 print "WARNING: No /etc/xinetd.d found.\n";
361 print "WARNING: You have to install etc/xinetd_fex manually.\n";
364 $crontab = `crontab -u fex -l 2>/dev/null`;
365 if ($crontab !~ /fex_cleanup/) {
366 open $crontab,">fex.cron" or die "cannot create fex.cron - $!\n";
367 print {$crontab} $crontab,"\n";
368 print {$crontab} " 3 2 * * * exec $FEXHOME/bin/backup\n";
369 print {$crontab} " 3 3 * * * exec $FEXHOME/bin/fex_cleanup\n";
371 system qw'crontab -u fex fex.cron';
374 chownr('fex:root',$FEXHOME,"$FEXHOME/spool/.");
375 chmodr('go-r',"$FEXHOME/lib","$FEXHOME/cgi-bin","$FEXHOME/spool/.");
378 print "Now check configuration file $FEXHOME/lib/fex.ph and run\n";
379 print "$FEXHOME/bin/fac for further configuration and user management.\n";
380 print "(You can do this as user \"fex\")\n";
383 chmodr('go-r',"$FEXHOME/lib","$FEXHOME/cgi-bin");
386 print "F*EX update installed.\n";
387 print "You can inform your users about the new features with:\n";
388 print "$FEXHOME/bin/fexwall 'new F*EX features on $hostname' ".
389 "< $FEXHOME/doc/newfeatures\n";
392 if (@local_rdomains and not @local_rhosts) {
393 print "\nWARNING:\n";
394 print "In $fph you have @local_rdomains but not @local_rhosts!\n";
395 print "Selfregistrating of external users will not work!\n";
396 print "See ${fph}_new/\n";
399 if (`$sendmail -h 2>&1` =~ /exim/ and
400 `grep trusted_users /etc/exim4/exim4.conf 2>/dev/null` !~ /\bfex\b/) {
401 print "\nWARNING:\n";
402 print "$sendmail is exim\n";
403 print "You MUST set in your exim4.conf:\n";
404 print "trusted_users = mail : uucp : fex\n";
410 my $ad = dirname($aa);
412 open $aa,'>',$aa or die "$0: cannot create $aa - $!\n";
413 print {$aa} "$admin_pw\n";
415 my $fd = dirname($fid);
417 rename $fid,$fid.'_save';
418 open $fid,'>',$fid or die "$0: cannot create $fid - $!\n";
419 print {$fid} "$hostname:$opt_p\n";
420 print {$fid} "$admin\n";
421 print {$fid} "$admin_pw\n";
423 chownr('fex',$ad,$fd);
431 if (m:^/*(lib|usr|home)?/*$:) {
432 die "ERROR: short path in chownr $user @_\n";
435 system qw'chown -R',$user,@_;
442 if (m:^/*(lib|usr|home)?/*$:) {
443 die "ERROR: short path in chmodr $mod @_\n";
446 system qw'chmod -R',$mod,@_;
450 my ($f,$d,$to,$from,$link);
455 our ($spooldir,$skeydir,$gkeydir);
456 $ENV{FEXLIB} = $FEXLIB = "$FEXHOME/lib";
457 require "$FEXLIB/fex.pp" or die "$0: cannot load $FEXLIB/fex.pp - $!\n";
458 die "no \$spooldir in $FEXLIB/fex.pp\n" unless $spooldir;
459 die "\$spooldir=$spooldir/" if $spooldir =~ m:^/*(root)?$:;
461 # User --> user@maildomain
463 foreach $f (glob "$spooldir/.dkeys/*") {
464 if ($link = readlink $f) {
465 (undef,$to,$from,$file) = split('/',$link);
467 $to .= '@'.$mdomain if $to !~ /@/;
468 $from .= '@'.$mdomain if $from !~ /@/;
469 if ($link ne "../$to/$from/$file") {
470 symlink "../$to/$from/$file",$f;
477 # fix spool layout: FROM and TO must have domains and must be lower case
478 foreach $d ((glob "$spooldir/*/*"),(glob "$spooldir/*")) {
479 if (not -l $d and -d $d and $d =~ m:(.+)/(.+):) {
482 if ($b !~ /^@/ and $b !~ /^[A-Z_-]+$/) {
483 if ($mdomain and $b !~ /@/) {
484 rename $d,sprintf("%s/%s@%s",$p,lc($b),$mdomain);
485 } elsif ($b ne lc($b)) {
486 rename $d,sprintf("%s/%s",$p,lc($b));
492 # split auth-ID and subuser file: @ --> @ @SUBUSER
493 foreach my $u (glob "$spooldir/*@*") {
494 next if -f "$u/\@SUBUSER";
495 open my $idf,"$u/\@" or next;
497 if (defined ($su = <$idf>) and $su =~ /\w/
498 and open my $suf,">$u/\@SUBUSER") {
500 while (defined ($su = <$idf>)) { print {$suf} $su }
503 if (open my $idf,">$u/\@") {
511 foreach my $sf (glob "$spooldir/*/\@SUBUSER") {
512 $user = (split '/',$sf)[-2];
516 if (/(.+\@.+):(.+)/) {
517 ($subuser,$id) = ($1,$2);
518 next if $subuser =~ /\*/;
519 $skey = md5_hex("$user:$subuser:$id");
520 if (open $skey,'>',"$skeydir/$skey") {
521 print {$skey} "from=$subuser\n",
526 mkdirp("$spooldir/$subuser/\@MAINUSER");
527 symlink $skey,"$spooldir/$subuser/\@MAINUSER/$user";
535 foreach my $gf (glob "$spooldir/*/\@GROUP/*") {
537 # normalize group name
538 if ($gf =~ m:(.+)/(.+):) {
542 $g2 =~ s/[^\w\*%^+=:,.!-]/_/g;
544 rename "$gd/$g1","$gd/$g2" and $gf = "$gd/$g2";
547 $group = (split '/',$gf)[-1];
548 $user = (split '/',$gf)[-3];
552 if (/(.+\@.+):(.+)/) {
554 $gkey = md5_hex("$user:$group:$gm:$id");
555 if (open $gkey,'>',"$gkeydir/$gkey") {
556 print {$gkey} "from=$gm\n",
562 mkdirp("$spooldir/$gm/\@GROUP");
563 symlink "../../$user/\@GROUP/$group","$spooldir/$gm/\@GROUP/$group";
575 die "cpav: $dd is not a directory" unless -d $dd;
576 open P,"tar cf - @_ | su -c 'cd $dd; umask 022; tar xvf - 2>&1' fex |"
577 or die "cpav: cannot tar - $!\n";
580 print "$_ --> $dd/$_\n" unless /\/$/;