8 use Digest::MD5 'md5_hex';
10 our (@local_rdomains,@local_rhosts);
12 $ENV{PATH} .= ':/sbin:/usr/sbin';
14 $usage = "usage: $0 [-p port] [IP-address]\n";
15 $xinetd = '/etc/xinetd.d/fex';
20 die "you must be root to install F*EX\n";
23 $fex = 'fex.rus.uni-stuttgart.de';
24 if (system("host $fex >/dev/null") != 0) {
25 die "host $fex is not resolvable - check /etc/resolv.conf\n";
30 if (open $xinetd,$xinetd) {
32 if (/^\s*port\s*=\s*(\d+)/) {
33 $opt_p = $fexport = $1;
35 if (/^\s*bind\s*=\s*([\d.]+)$/) {
42 goto INSTALL if $0 =~ /upgrade$/;
44 if (`uname` =~ /^SunOS/) {
45 die "Solaris is currently not supported. "
46 ."Please contact framstag\@rus.uni-stuttgart.de for details.\n";
49 getopts('p:') or die $usage;
52 if ($arg and -f "locale/$arg/lib/fup.pl") {
53 exec 'locale/translate',$arg;
55 $ip = $arg || $fexip || 0;
58 # if (not $ip and open P,"ifconfig 2>/dev/null |") {
59 if (not $ip and open P,'host $(hostname)|') {
62 if (/(\d+\.\d+\.\d+\.\d+)/) {
69 print "Your IP [$guessed_ip] : ";
76 ($hostname) = gethostbyaddr(gethostbyname($ip),AF_INET);
77 die "cannot find hostname for IP $ip\n" unless $hostname;
79 print "checking prerequisites\n";
81 if (`which xinetd` =~ m{^/}) {
82 print "found xinetd\n";
84 print "xinetd executable NOT found\n";
88 foreach (qw'/usr/lib/sendmail /usr/sbin/sendmail') {
91 print "found $sendmail\n";
96 print "sendmail NOT found\n";
101 print "installation aborted, nothing has been touched yet\n";
102 print "what now? ==> see doc/installation\n";
108 $SH = IO::Socket::INET->new(
115 print "There is already a tcp-service running on $ip:$opt_p !\n";
116 print "Select another port for F*EX by running $0 -p OTHERPORT $ip\n";
117 print "or an alternative IP-address by running $0 OTHERADDRESS\n";
122 print "prerequisites checked, ok\n";
124 unless (getpwnam('fex')) {
125 print "creating user fex\n";
126 system 'groupadd -g 80 fex 2>/dev/null || groupadd fex';
127 my @g = getgrnam('fex') or die "$0: cannot groupadd fex\n";
129 if (getpwuid($gid)) {
130 system "useradd -s /bin/bash -c 'File EXchange' -g $gid -m fex"
132 system "useradd -s /bin/bash -c 'File EXchange' -u $gid -g $gid -m fex"
137 if (open F,'/etc/passwd') {
139 $fexbash = $_ if /^fex:.*\/bash/;
144 die "no bash login shell for user fex\n";
151 @FEX = getpwnam('fex') or die "no user fex\n";
153 $ENV{HOME} = $FEXHOME; # needed for later eval fex.ph
155 die "no HOME directory for user fex\n" unless -d $FEXHOME;
156 if ($FEXHOME !~ /fex/) {
157 print "HOME=$FEXHOME for user fex does not contain \"fex\"\n";
158 print "REALLY continue?! ";
163 print "Installing:\n";
165 $pecl = "$FEXHOME/perl/Encode/ConfigLocal.pm";
167 mkdir "$FEXHOME/perl";
168 mkdir "$FEXHOME/perl/Encode";
169 open $pecl,'>',$pecl or die "$0: cannot write $pecl - $!\n";
171 "# hack for broken Perl in SuSe and Solaris, used via \@INC in fexsrv\n",
175 chownr('fex:root',"$FEXHOME/perl");
181 "lib/reactivation.txt",
185 "htdocs/FAQ/local.faq",
192 rename $f,$fs and print "$f --> $fs\n";
196 cpav(qw'bin cgi-bin lib etc htdocs doc',$FEXHOME);
197 unlink "$FEXHOME/doc/License";
198 unlink "$FEXHOME/htdocs/License";
200 $hl = "$FEXHOME/htdocs/locale";
201 unless (-d $hl) { mkdir $hl or die "$0: cannot mkdir $hl - $!\n" }
209 rename $f,$fn and print "$f --> $fn\n";
210 rename $fs,$f and print "$fs --> $f\n";
214 if (-d "$FEXHOME/spool") {
215 warn "checking $FEXHOME/spool ...\n";
218 $newinstall = $FEXHOME;
220 mkdir "$FEXHOME/spool",0700 or die "cannot mkdir $FEXHOME/spool - $!\n";
221 mkdir "$FEXHOME/spool/.error",0700;
223 foreach my $dir (qw'.dkeys .ukeys .akeys .skeys .gkeys .xkeys .locks') {
224 mkdir "$FEXHOME/spool/$dir",0700;
227 chownr('fex',"$FEXHOME/spool/.");
230 if (open my $setup,'/root/bin/setup') {
237 system(qw'perl -p -i -e',
238 's:href="/?FAQ.html":href="/FAQ/FAQ.html":',
239 "$FEXHOME/lib/fup.pl"
242 $fph = "$FEXHOME/lib/fex.ph";
243 open $fph,$fph or die "cannot read $fph - $!\n";
245 s/'MYHOSTNAME.MYDOMAIN'/'$hostname'/;
252 # die "no \$spooldir in $fph\n" unless $spooldir;
253 $spooldir ||= '/home/fex/spool';
254 die "\$spooldir=$spooldir is not a directory, see $fph\n" unless -d $spooldir;
255 symlink $spooldir,"$FEXHOME/spool" unless -e "$FEXHOME/spool";
256 @sds1 = stat "$spooldir/.";
257 @sds2 = stat "$FEXHOME/spool/.";
258 if ("@sds1" ne "@sds2") {
259 die "$FEXHOME/spool is not a symbolic link to \$spooldir=$spooldir\n";
262 $fid = "$FEXHOME/.fex/id";
263 $aa = "$spooldir/$admin/@";
265 if ($newinstall or not -s $aa) {
268 print "Server hostname [$hostname] : ";
271 $hostname = $_ if $_;
272 last if gethostbyname($hostname);
273 print "No DNS for $hostname\n";
276 print "F*EX admin [$admin] : ";
280 last if $admin =~ /.\@./;
281 print "admin must be a valid email address!\n";
283 $aa = "$spooldir/$admin/@";
284 while (not $admin_pw) {
285 print "F*EX admin password: ";
287 $admin_pw =~ s/\s//g;
290 print "(admin password is in $aa)\n";
291 $conf =~ s/^\s*\$hostname\s*=.*/\$hostname = '$hostname';/m;
292 $conf =~ s/^\s*\$admin\s*=.*/\$admin = '$admin';/m;
295 print "\nFound old \$admin_pw in $fph !\n";
296 print "This is no longer supported for security reason.\n";
301 if ($_ ne $admin_pw) {
302 print "\nYou have to delete \$admin_pw in $fph and run\n";
303 print "$FEXHOME/bin/fac -u $admin $admin_pw\n";
304 print "\nThen rerun $0\n";
309 print "\$admin_pw is transfered to auth-ID in $aa\n\n";
310 $conf =~ s/^\s*(\$admin_pw)\s*=.*/# $1 is now auth_ID of user \$admin/m;
314 open $fph,">$fph.new" or die "$0: cannot write $fph.new - $!\n";
317 system "chown fex $fph.new";
318 rename "$fph.new",$fph or die "$0: cannot rename $fph.new to $fph - $!\n";
320 do $fph or die "$0: error in new $fph - $!\n";
322 if (@locales = glob "locale/*/lib/fup.pl") {
324 m{locale/(.+?)/} and $locale = $1;
325 if (-f "$FEXHOME/$_") {
326 system 'locale/translate',$locale;
327 chownr('fex',"$FEXHOME/locale/$locale");
328 $hl = "$FEXHOME/htdocs/locale/$locale";
329 symlink "$FEXHOME/locale/$locale/htdocs",$hl unless -l $hl;
330 chownr('fex',"$FEXHOME/htdocs/locale/$locale");
332 push @nlocales,"./install $1\n";
336 if (glob "$FEXHOME/locale/*/lib/fup.pl") {
337 print "\nTo install another localized version, type:\n";
339 print "\nTo install a localized version, type:\n";
345 $fph = "$FEXHOME/lib/fex.ph";
348 unless (-f $xinetd) {
349 my $xc = '/etc/xinetd.conf';
352 if (/^\s*only_from/) {
353 print "WARNING: found \"only_from\" in $xc : fexsrv is restricted!\n";
358 if (-d '/etc/xinetd.d') {
359 unless (-f $xinetd) {
360 open $xinetd,">$xinetd" or die "cannot write $xinetd - $!\n";
361 open F,'etc/xinetd_fex' or die "cannot read etc/xinetd_fex - $!\n";
370 system qw'/etc/init.d/xinetd restart';
371 print "WARNING: cannot restart xinetd\n" if $?;
374 print "WARNING: No /etc/xinetd.d found.\n";
375 print "WARNING: You have to install etc/xinetd_fex manually.\n";
378 $crontab = `crontab -u fex -l 2>/dev/null`;
379 if ($crontab !~ /fex_cleanup/) {
380 open $crontab,">fex.cron" or die "cannot create fex.cron - $!\n";
381 print {$crontab} $crontab,"\n";
382 print {$crontab} " 3 2 * * * exec $FEXHOME/bin/backup\n";
383 print {$crontab} " 3 3 * * * exec $FEXHOME/bin/fex_cleanup\n";
385 system qw'crontab -u fex fex.cron';
388 chownr('fex:root',$FEXHOME,"$FEXHOME/spool/.");
389 chmodr('go-r',"$FEXHOME/lib","$FEXHOME/cgi-bin","$FEXHOME/spool/.");
392 print "Now check configuration file $FEXHOME/lib/fex.ph and run\n";
393 print "$FEXHOME/bin/fac for further configuration and user management.\n";
394 print "(You can do this as user \"fex\")\n";
397 chmodr('go-r',"$FEXHOME/lib","$FEXHOME/cgi-bin");
400 print "F*EX update installed.\n";
401 print "You can inform your users about the new features with:\n";
402 print "$FEXHOME/bin/fexwall 'new F*EX features on $hostname' ".
403 "< $FEXHOME/doc/newfeatures\n";
406 if (@local_rdomains and not @local_rhosts) {
407 print "\nWARNING:\n";
408 print "In $fph you have \@local_rdomains but not \@local_rhosts!\n";
409 print "Selfregistrating of external users will not work!\n";
410 print "See ${fph}_new/\n";
413 if (`$sendmail -h 2>&1 </dev/null` =~ /exim/ and
414 `grep trusted_users /etc/exim4/exim4.conf 2>/dev/null` !~ /\bfex\b/) {
415 print "\nWARNING:\n";
416 print "$sendmail is exim\n";
417 print "You MUST set in your exim4.conf:\n";
418 print "trusted_users = mail : uucp : fex\n";
424 my $ad = dirname($aa);
426 open $aa,'>',$aa or die "$0: cannot create $aa - $!\n";
427 print {$aa} "$admin_pw\n";
429 my $fd = dirname($fid);
431 rename $fid,$fid.'_save';
432 open $fid,'>',$fid or die "$0: cannot create $fid - $!\n";
433 print {$fid} "$hostname:$opt_p\n";
434 print {$fid} "$admin\n";
435 print {$fid} "$admin_pw\n";
437 chownr('fex',$ad,$fd);
445 if (m:^/*(lib|usr|home)?/*$:) {
446 die "ERROR: short path in chownr $user @_\n";
449 system qw'chown -R',$user,@_;
456 if (m:^/*(lib|usr|home)?/*$:) {
457 die "ERROR: short path in chmodr $mod @_\n";
460 system qw'chmod -R',$mod,@_;
464 my ($f,$d,$to,$from,$link);
469 our ($spooldir,$skeydir,$gkeydir);
470 $ENV{FEXLIB} = $FEXLIB = "$FEXHOME/lib";
471 require "$FEXLIB/fex.pp" or die "$0: cannot load $FEXLIB/fex.pp - $!\n";
472 die "no \$spooldir in $FEXLIB/fex.pp\n" unless $spooldir;
473 die "\$spooldir=$spooldir/" if $spooldir =~ m:^/*(root)?$:;
475 # User --> user@maildomain
477 foreach $f (glob "$spooldir/.dkeys/*") {
478 if ($link = readlink $f) {
479 (undef,$to,$from,$file) = split('/',$link);
481 $to .= '@'.$mdomain if $to !~ /@/;
482 $from .= '@'.$mdomain if $from !~ /@/;
483 if ($link ne "../$to/$from/$file") {
484 symlink "../$to/$from/$file",$f;
491 # fix spool layout: FROM and TO must have domains and must be lower case
492 foreach $d ((glob "$spooldir/*/*"),(glob "$spooldir/*")) {
493 if (not -l $d and -d $d and $d =~ m:(.+)/(.+):) {
496 if ($b !~ /^@/ and $b !~ /^[A-Z_-]+$/) {
497 if ($mdomain and $b !~ /@/) {
498 rename $d,sprintf("%s/%s@%s",$p,lc($b),$mdomain);
499 } elsif ($b ne lc($b)) {
500 rename $d,sprintf("%s/%s",$p,lc($b));
506 # split auth-ID and subuser file: @ --> @ @SUBUSER
507 foreach my $u (glob "$spooldir/*@*") {
508 next if -f "$u/\@SUBUSER";
509 open my $idf,"$u/\@" or next;
511 if (defined ($su = <$idf>) and $su =~ /\w/
512 and open my $suf,">$u/\@SUBUSER") {
514 while (defined ($su = <$idf>)) { print {$suf} $su }
517 if (open my $idf,">$u/\@") {
525 foreach my $sf (glob "$spooldir/*/\@SUBUSER") {
526 $user = (split '/',$sf)[-2];
530 if (/(.+\@.+):(.+)/) {
531 ($subuser,$id) = ($1,$2);
532 next if $subuser =~ /\*/;
533 $skey = md5_hex("$user:$subuser:$id");
534 if (open $skey,'>',"$skeydir/$skey") {
535 print {$skey} "from=$subuser\n",
540 mkdirp("$spooldir/$subuser/\@MAINUSER");
541 symlink $skey,"$spooldir/$subuser/\@MAINUSER/$user";
549 foreach my $gf (glob "$spooldir/*/\@GROUP/*") {
551 # normalize group name
552 if ($gf =~ m:(.+)/(.+):) {
556 $g2 =~ s/[^\w\*%^+=:,.!-]/_/g;
558 rename "$gd/$g1","$gd/$g2" and $gf = "$gd/$g2";
561 $group = (split '/',$gf)[-1];
562 $user = (split '/',$gf)[-3];
566 if (/(.+\@.+):(.+)/) {
568 $gkey = md5_hex("$user:$group:$gm:$id");
569 if (open $gkey,'>',"$gkeydir/$gkey") {
570 print {$gkey} "from=$gm\n",
576 mkdirp("$spooldir/$gm/\@GROUP");
577 symlink "../../$user/\@GROUP/$group","$spooldir/$gm/\@GROUP/$group";
589 die "cpav: $dd is not a directory" unless -d $dd;
590 open P,"tar cf - @_ | su -c 'cd $dd; umask 022; tar xvf - 2>&1' fex |"
591 or die "cpav: cannot tar - $!\n";
594 print "$_ --> $dd/$_\n" unless /\/$/;