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";
28 # $fexupdate = '/root/bin/fexupdate';
29 # die "found $fexupdate\n" if -x $fexupdate;
33 if (open $xinetd,$xinetd) {
35 if (/^\s*port\s*=\s*(\d+)/) {
36 $opt_p = $fexport = $1;
38 if (/^\s*bind\s*=\s*([\d.]+)$/) {
45 goto INSTALL if $0 =~ /upgrade$/;
47 if (`uname` =~ /^SunOS/) {
48 die "Solaris is currently not supported. "
49 ."Please contact framstag\@rus.uni-stuttgart.de for details.\n";
52 getopts('p:') or die $usage;
55 if ($arg and -f "locale/$arg/lib/fup.pl") {
56 exec 'locale/translate',$arg;
58 $ip = $arg || $fexip || 0;
61 # if (not $ip and open P,"ifconfig 2>/dev/null |") {
62 if (not $ip and open P,'host $(hostname)|') {
65 if (/(\d+\.\d+\.\d+\.\d+)/) {
72 print "Your IP [$guessed_ip] : ";
79 ($hostname) = gethostbyaddr(gethostbyname($ip),AF_INET);
80 die "cannot find hostname for IP $ip\n" unless $hostname;
82 print "checking prerequisites\n";
84 if (`which xinetd` =~ m{^/}) {
85 print "found xinetd\n";
87 print "xinetd executable NOT found\n";
91 foreach (qw'/usr/lib/sendmail /usr/sbin/sendmail') {
94 print "found $sendmail\n";
99 print "sendmail NOT found\n";
104 print "installation aborted, nothing has been touched yet\n";
105 print "what now? ==> see doc/installation\n";
111 $SH = IO::Socket::INET->new(
118 print "There is already a tcp-service running on $ip:$opt_p !\n";
119 print "Select another port for F*EX by running $0 -p OTHERPORT $ip\n";
120 print "or an alternative IP-address by running $0 OTHERADDRESS\n";
125 print "prerequisites checked, ok\n";
127 unless (getpwnam('fex')) {
128 print "creating user fex\n";
129 system 'groupadd --system fex 2>/dev/null || groupadd fex';
130 my @g = getgrnam('fex') or die "$0: cannot groupadd fex\n";
132 if (getpwuid($gid)) {
133 system "useradd -s /bin/bash -c 'File EXchange' -g $gid -m fex"
135 system "useradd -s /bin/bash -c 'File EXchange' -u $gid -g $gid -m fex"
140 if (open F,'/etc/passwd') {
142 $fexbash = $_ if /^fex:.*\/bash/;
147 die "no bash login shell for user fex\n";
154 @FEX = getpwnam('fex') or die "no user fex\n";
156 $ENV{HOME} = $FEXHOME; # needed for later eval fex.ph
158 die "no HOME directory for user fex\n" unless -d $FEXHOME;
159 if ($FEXHOME !~ /fex/) {
160 print "HOME=$FEXHOME for user fex does not contain \"fex\"\n";
161 print "REALLY continue?! ";
166 print "Installing:\n";
168 $pecl = "$FEXHOME/perl/Encode/ConfigLocal.pm";
170 mkdir "$FEXHOME/perl";
171 mkdir "$FEXHOME/perl/Encode";
172 open $pecl,'>',$pecl or die "$0: cannot write $pecl - $!\n";
174 "# hack for broken Perl in SuSe and Solaris, used via \@INC in fexsrv\n",
178 chownr('fex:root',"$FEXHOME/perl");
184 "lib/reactivation.txt",
188 "htdocs/FAQ/local.faq",
195 rename $f,$fs and print "$f --> $fs\n";
199 cpav(qw'bin cgi-bin lib etc htdocs doc',$FEXHOME);
200 unlink "$FEXHOME/doc/License";
201 unlink "$FEXHOME/htdocs/License";
203 $hl = "$FEXHOME/htdocs/locale";
204 unless (-d $hl) { mkdir $hl or die "$0: cannot mkdir $hl - $!\n" }
212 rename $f,$fn and print "$f --> $fn\n";
213 rename $fs,$f and print "$fs --> $f\n";
217 if (-d "$FEXHOME/spool") {
218 warn "checking $FEXHOME/spool ...\n";
221 $newinstall = $FEXHOME;
223 mkdir "$FEXHOME/spool",0700 or die "cannot mkdir $FEXHOME/spool - $!\n";
224 mkdir "$FEXHOME/spool/.error",0700;
226 foreach my $dir (qw'.dkeys .ukeys .akeys .skeys .gkeys .xkeys .locks') {
227 mkdir "$FEXHOME/spool/$dir",0700;
230 chownr('fex',"$FEXHOME/spool/.");
233 if (open my $setup,'/root/bin/setup') {
240 system(qw'perl -p -i -e',
241 's:href="/?FAQ.html":href="/FAQ/FAQ.html":',
242 "$FEXHOME/lib/fup.pl"
245 $fph = "$FEXHOME/lib/fex.ph";
246 open $fph,$fph or die "cannot read $fph - $!\n";
248 s/'MYHOSTNAME.MYDOMAIN'/'$hostname'/;
255 # die "no \$spooldir in $fph\n" unless $spooldir;
256 $spooldir ||= '/home/fex/spool';
257 die "\$spooldir=$spooldir is not a directory, see $fph\n" unless -d $spooldir;
258 symlink $spooldir,"$FEXHOME/spool" unless -e "$FEXHOME/spool";
259 @sds1 = stat "$spooldir/.";
260 @sds2 = stat "$FEXHOME/spool/.";
261 if ("@sds1" ne "@sds2") {
262 die "$FEXHOME/spool is not a symbolic link to \$spooldir=$spooldir\n";
265 $fid = "$FEXHOME/.fex/id";
266 $aa = "$spooldir/$admin/@";
268 if ($newinstall or not -s $aa) {
271 print "Server hostname [$hostname] : ";
274 $hostname = $_ if $_;
275 last if gethostbyname($hostname);
276 print "No DNS for $hostname\n";
279 print "F*EX admin [$admin] : ";
283 last if $admin =~ /.\@./;
284 print "admin must be a valid email address!\n";
286 $aa = "$spooldir/$admin/@";
287 while (not $admin_pw) {
288 print "F*EX admin password: ";
290 $admin_pw =~ s/\s//g;
293 print "(admin password is in $aa)\n";
294 $conf =~ s/^\s*\$hostname\s*=.*/\$hostname = '$hostname';/m;
295 $conf =~ s/^\s*\$admin\s*=.*/\$admin = '$admin';/m;
298 print "\nFound old \$admin_pw in $fph !\n";
299 print "This is no longer supported for security reason.\n";
304 if ($_ ne $admin_pw) {
305 print "\nYou have to delete \$admin_pw in $fph and run\n";
306 print "$FEXHOME/bin/fac -u $admin $admin_pw\n";
307 print "\nThen rerun $0\n";
312 print "\$admin_pw is transfered to auth-ID in $aa\n\n";
313 $conf =~ s/^\s*(\$admin_pw)\s*=.*/# $1 is now auth_ID of user \$admin/m;
317 open $fph,">$fph.new" or die "$0: cannot write $fph.new - $!\n";
320 system "chown fex $fph.new";
321 rename "$fph.new",$fph or die "$0: cannot rename $fph.new to $fph - $!\n";
323 do $fph or die "$0: error in new $fph - $!\n";
325 if (@locales = glob "locale/*/lib/fup.pl") {
327 m{locale/(.+?)/} and $locale = $1;
328 if (-f "$FEXHOME/$_") {
329 system 'locale/translate',$locale;
330 chownr('fex',"$FEXHOME/locale/$locale");
331 $hl = "$FEXHOME/htdocs/locale/$locale";
332 symlink "$FEXHOME/locale/$locale/htdocs",$hl unless -l $hl;
333 chownr('fex',"$FEXHOME/htdocs/locale/$locale");
335 push @nlocales,"./install $1\n";
339 if (glob "$FEXHOME/locale/*/lib/fup.pl") {
340 print "\nTo install another localized version, type:\n";
342 print "\nTo install a localized version, type:\n";
348 $fph = "$FEXHOME/lib/fex.ph";
351 unless (-f $xinetd) {
352 my $xc = '/etc/xinetd.conf';
355 if (/^\s*only_from/) {
356 print "WARNING: found \"only_from\" in $xc : fexsrv is restricted!\n";
361 if (-d '/etc/xinetd.d') {
362 unless (-f $xinetd) {
363 open $xinetd,">$xinetd" or die "cannot write $xinetd - $!\n";
364 open F,'etc/xinetd_fex' or die "cannot read etc/xinetd_fex - $!\n";
373 system qw'/etc/init.d/xinetd restart';
374 print "WARNING: cannot restart xinetd\n" if $?;
377 print "WARNING: No /etc/xinetd.d found.\n";
378 print "WARNING: You have to install etc/xinetd_fex manually.\n";
381 $crontab = `crontab -u fex -l 2>/dev/null`;
382 if ($crontab !~ /fex_cleanup/) {
383 open $crontab,">fex.cron" or die "cannot create fex.cron - $!\n";
384 print {$crontab} $crontab,"\n";
385 print {$crontab} " 3 2 * * * exec $FEXHOME/bin/backup\n";
386 print {$crontab} " 3 3 * * * exec $FEXHOME/bin/fex_cleanup\n";
388 system qw'crontab -u fex fex.cron';
391 chownr('fex:root',$FEXHOME,"$FEXHOME/spool/.","$FEXHOME/htdocs/.");
392 chmodr('go-r',"$FEXHOME/lib","$FEXHOME/cgi-bin","$FEXHOME/spool/.");
395 print "Now check configuration file $FEXHOME/lib/fex.ph and run\n";
396 print "$FEXHOME/bin/fac for further configuration and user management.\n";
397 print "(You can do this as user \"fex\")\n";
400 chmodr('go-r',"$FEXHOME/lib","$FEXHOME/cgi-bin");
403 print "F*EX update installed.\n";
404 print "You can inform your users about the new features with:\n";
405 print "$FEXHOME/bin/fexwall 'new F*EX features on $hostname' ".
406 "< $FEXHOME/doc/newfeatures\n";
409 chmod 0755,"$FEXHOME/htdocs/locale";
410 chmod 0755,glob("$FEXHOME/locale/*/htdocs");
412 if (@local_rdomains and not @local_rhosts) {
413 print "\nWARNING:\n";
414 print "In $fph you have \@local_rdomains but not \@local_rhosts!\n";
415 print "Selfregistrating of external users will not work!\n";
416 print "See ${fph}_new/\n";
419 if (`$sendmail -h 2>&1 </dev/null` =~ /exim/ and
420 `grep trusted_users /etc/exim4/exim4.conf 2>/dev/null` !~ /\bfex\b/) {
421 print "\nWARNING:\n";
422 print "$sendmail is exim\n";
423 print "You MUST set in your exim4.conf:\n";
424 print "trusted_users = mail : uucp : fex\n";
430 my $ad = dirname($aa);
432 open $aa,'>',$aa or die "$0: cannot create $aa - $!\n";
433 print {$aa} "$admin_pw\n";
435 my $fd = dirname($fid);
437 rename $fid,$fid.'_save';
438 open $fid,'>',$fid or die "$0: cannot create $fid - $!\n";
439 print {$fid} "$hostname:$opt_p\n";
440 print {$fid} "$admin\n";
441 print {$fid} "$admin_pw\n";
443 chownr('fex',$ad,$fd);
451 if (m:^/*(lib|usr|home)?/*$:) {
452 die "ERROR: short path in chownr $user @_\n";
455 system qw'chown -R',$user,@_;
462 if (m:^/*(lib|usr|home)?/*$:) {
463 die "ERROR: short path in chmodr $mod @_\n";
466 system qw'chmod -R',$mod,@_;
470 my ($f,$d,$to,$from,$link);
475 our ($spooldir,$skeydir,$gkeydir);
476 $ENV{FEXLIB} = $FEXLIB = "$FEXHOME/lib";
477 require "$FEXLIB/fex.pp" or die "$0: cannot load $FEXLIB/fex.pp - $!\n";
478 die "no \$spooldir in $FEXLIB/fex.pp\n" unless $spooldir;
479 die "\$spooldir=$spooldir/" if $spooldir =~ m:^/*(root)?$:;
481 # User --> user@maildomain
483 foreach $f (glob "$spooldir/.dkeys/*") {
484 if ($link = readlink $f) {
485 (undef,$to,$from,$file) = split('/',$link);
487 $to .= '@'.$mdomain if $to !~ /@/;
488 $from .= '@'.$mdomain if $from !~ /@/;
489 if ($link ne "../$to/$from/$file") {
490 symlink "../$to/$from/$file",$f;
497 # fix spool layout: FROM and TO must have domains and must be lower case
498 foreach $d ((glob "$spooldir/*/*"),(glob "$spooldir/*")) {
499 if (not -l $d and -d $d and $d =~ m:(.+)/(.+):) {
502 if ($b !~ /^@/ and $b !~ /^[A-Z_-]+$/) {
503 if ($mdomain and $b !~ /@/) {
504 rename $d,sprintf("%s/%s@%s",$p,lc($b),$mdomain);
505 } elsif ($b ne lc($b)) {
506 rename $d,sprintf("%s/%s",$p,lc($b));
512 # split auth-ID and subuser file: @ --> @ @SUBUSER
513 foreach my $u (glob "$spooldir/*@*") {
514 next if -f "$u/\@SUBUSER";
515 open my $idf,"$u/\@" or next;
517 if (defined ($su = <$idf>) and $su =~ /\w/
518 and open my $suf,">$u/\@SUBUSER") {
520 while (defined ($su = <$idf>)) { print {$suf} $su }
523 if (open my $idf,">$u/\@") {
531 foreach my $sf (glob "$spooldir/*/\@SUBUSER") {
532 $user = (split '/',$sf)[-2];
536 if (/(.+\@.+):(.+)/) {
537 ($subuser,$id) = ($1,$2);
538 next if $subuser =~ /\*/;
539 $skey = md5_hex("$user:$subuser:$id");
540 if (open $skey,'>',"$skeydir/$skey") {
541 print {$skey} "from=$subuser\n",
546 mkdirp("$spooldir/$subuser/\@MAINUSER");
547 symlink $skey,"$spooldir/$subuser/\@MAINUSER/$user";
555 foreach my $gf (glob "$spooldir/*/\@GROUP/*") {
557 # normalize group name
558 if ($gf =~ m:(.+)/(.+):) {
562 $g2 =~ s/[^\w\*%^+=:,.!-]/_/g;
564 rename "$gd/$g1","$gd/$g2" and $gf = "$gd/$g2";
567 $group = (split '/',$gf)[-1];
568 $user = (split '/',$gf)[-3];
572 if (/(.+\@.+):(.+)/) {
574 $gkey = md5_hex("$user:$group:$gm:$id");
575 if (open $gkey,'>',"$gkeydir/$gkey") {
576 print {$gkey} "from=$gm\n",
582 mkdirp("$spooldir/$gm/\@GROUP");
583 symlink "../../$user/\@GROUP/$group","$spooldir/$gm/\@GROUP/$group";
595 die "cpav: $dd is not a directory" unless -d $dd;
596 open P,"tar cf - @_ | su -c 'cd $dd; umask 022; tar xvf - 2>&1' fex |"
597 or die "cpav: cannot tar - $!\n";
600 print "$_ --> $dd/$_\n" unless /\/$/;