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+)/) {
66 print "Your IP [$guessed_ip] : ";
72 ($hostname) = gethostbyaddr(gethostbyname($ip),AF_INET);
73 die "cannot find hostname for IP $ip\n" unless $hostname;
75 print "checking prerequisites\n";
77 if (`which xinetd` =~ m{^/}) {
78 print "found xinetd\n";
80 print "xinetd executable NOT found\n";
84 foreach (qw'/usr/lib/sendmail /usr/sbin/sendmail') {
87 print "found $sendmail\n";
92 print "sendmail NOT found\n";
97 print "installation aborted, nothing has been touched yet\n";
98 print "what now? ==> see doc/installation\n";
104 $SH = IO::Socket::INET->new(
111 print "There is already a tcp-service running on $ip:$opt_p !\n";
112 print "Select another port for F*EX by running $0 -p OTHERPORT $ip\n";
113 print "or an alternative IP-address by running $0 OTHERADDRESS\n";
118 print "prerequisites checked, ok\n";
120 unless (getpwnam('fex')) {
121 print "creating user fex\n";
122 system 'useradd -s /bin/bash -c "File EXchange" -m fex';
126 if (open F,'/etc/passwd') {
128 $fexbash = $_ if /^fex:.*\/bash/;
133 die "no bash login shell for user fex\n";
140 @FEX = getpwnam('fex') or die "no user fex\n";
142 $ENV{HOME} = $FEXHOME; # needed for later eval fex.ph
144 die "no HOME directory for user fex\n" unless -d $FEXHOME;
145 if ($FEXHOME !~ /fex/) {
146 print "HOME=$FEXHOME for user fex does not contain \"fex\"\n";
147 print "REALLY continue?! ";
152 print "Installing:\n";
154 $pecl = "$FEXHOME/perl/Encode/ConfigLocal.pm";
156 mkdir "$FEXHOME/perl";
157 mkdir "$FEXHOME/perl/Encode";
158 open $pecl,'>',$pecl or die "$0: cannot write $pecl - $!\n";
160 "# hack for broken Perl in SuSe and Solaris, used via \@INC in fexsrv\n",
164 chownr('fex:root',"$FEXHOME/perl");
170 "lib/reactivation.txt",
174 "htdocs/FAQ/local.faq",
181 rename $f,$fs and print "$f --> $fs\n";
185 cpav(qw'bin cgi-bin lib etc htdocs doc',$FEXHOME);
186 unlink "$FEXHOME/doc/License";
187 unlink "$FEXHOME/htdocs/License";
189 $hl = "$FEXHOME/htdocs/locale";
190 unless (-d $hl) { mkdir $hl or die "$0: cannot mkdir $hl - $!\n" }
198 rename $f,$fn and print "$f --> $fn\n";
199 rename $fs,$f and print "$fs --> $f\n";
203 if (-d "$FEXHOME/spool") {
204 warn "checking $FEXHOME/spool ...\n";
207 $newinstall = $FEXHOME;
209 mkdir "$FEXHOME/spool",0700 or die "cannot mkdir $FEXHOME/spool - $!\n";
210 mkdir "$FEXHOME/spool/.error",0700;
212 chownr('fex',"$FEXHOME/spool/.");
214 system(qw'perl -p -i -e',
215 's:href="/?FAQ.html":href="/FAQ/FAQ.html":',
216 "$FEXHOME/lib/fup.pl"
219 $fph = "$FEXHOME/lib/fex.ph";
220 open $fph,$fph or die "cannot read $fph - $!\n";
222 s/'MYHOSTNAME.MYDOMAIN'/'$hostname'/;
229 die "no \$spooldir in $fph\n" unless $spooldir;
230 die "\$spooldir=$spooldir is not a directory, see $fph\n" unless -d $spooldir;
231 symlink $spooldir,"$FEXHOME/spool" unless -e "$FEXHOME/spool";
232 @sds1 = stat "$spooldir/.";
233 @sds2 = stat "$FEXHOME/spool/.";
234 if ("@sds1" ne "@sds2") {
235 die "$FEXHOME/spool is not a symbolic link to \$spooldir=$spooldir\n";
238 $fid = "$FEXHOME/.fex/id";
239 $aa = "$spooldir/$admin/@";
241 if ($newinstall or not -s $aa) {
244 print "Server hostname [$hostname] : ";
247 $hostname = $_ if $_;
248 last if gethostbyname($hostname);
249 print "No DNS for $hostname\n";
252 print "F*EX admin [$admin] : ";
256 last if $admin =~ /.\@./;
257 print "admin must be a valid email address!\n";
259 while (not $admin_pw) {
260 print "F*EX admin password: ";
262 $admin_pw =~ s/\s//g;
265 print "(admin password is in $aa)\n";
266 $conf =~ s/^\s*\$hostname\s*=.*/\$hostname = '$hostname';/m;
267 $conf =~ s/^\s*\$admin\s*=.*/\$admin = '$admin';/m;
270 print "\nFound old \$admin_pw in $fph !\n";
271 print "This is no longer supported for security reason.\n";
276 if ($_ ne $admin_pw) {
277 print "\nYou have to delete \$admin_pw in $fph and run\n";
278 print "$FEXHOME/bin/fac -u $admin $admin_pw\n";
279 print "\nThen rerun $0\n";
284 print "\$admin_pw is transfered to auth-ID in $aa\n\n";
285 $conf =~ s/^\s*(\$admin_pw)\s*=.*/# $1 is now auth_ID of user \$admin/m;
289 open $fph,">$fph.new" or die "$0: cannot write $fph.new - $!\n";
292 system "chown fex $fph.new";
293 rename "$fph.new",$fph or die "$0: cannot rename $fph.new to $fph - $!\n";
295 do $fph or die "$0: error in new $fph - $!\n";
297 if (@locales = glob "locale/*/lib/fup.pl") {
299 m{locale/(.+?)/} and $locale = $1;
300 if (-f "$FEXHOME/$_") {
301 system 'locale/translate',$locale;
302 chownr('fex',"$FEXHOME/locale/$locale");
303 $hl = "$FEXHOME/htdocs/locale/$locale";
304 symlink "$FEXHOME/locale/$locale/htdocs",$hl unless -l $hl;
306 push @nlocales,"./install $1\n";
310 if (glob "$FEXHOME/locale/*/lib/fup.pl") {
311 print "\nTo install another localized version, type:\n";
313 print "\nTo install a localized version, type:\n";
319 $fph = "$FEXHOME/lib/fex.ph";
322 unless (-f $xinetd) {
323 my $xc = '/etc/xinetd.conf';
326 if (/^\s*only_from/) {
327 print "WARNING: found \"only_from\" in $xc : fexsrv is restricted!\n";
332 if (-d '/etc/xinetd.d') {
333 unless (-f $xinetd) {
334 open $xinetd,">$xinetd" or die "cannot write $xinetd - $!\n";
335 open F,'etc/xinetd_fex' or die "cannot read etc/xinetd_fex - $!\n";
344 system qw'/etc/init.d/xinetd restart';
345 print "WARNING: cannot restart xinetd\n" if $?;
348 print "WARNING: No /etc/xinetd.d found.\n";
349 print "WARNING: You have to install etc/xinetd_fex manually.\n";
352 $crontab = `crontab -u fex -l 2>/dev/null`;
353 if ($crontab !~ /fex_cleanup/) {
354 open $crontab,">fex.cron" or die "cannot create fex.cron - $!\n";
355 print {$crontab} $crontab,"\n";
356 print {$crontab} " 3 3 * * * exec $FEXHOME/bin/fex_cleanup\n";
358 system qw(crontab -u fex fex.cron);
361 chownr('fex:root',"$FEXHOME $FEXHOME/spool/.");
362 chmodr('go-r',"$FEXHOME/lib","$FEXHOME/cgi-bin","$FEXHOME/spool/.");
365 print "Now check configuration file $FEXHOME/lib/fex.ph and run\n";
366 print "$FEXHOME/bin/fac for further configuration and user management.\n";
367 print "(You can do this as user \"fex\")\n";
370 chmodr('go-r',"$FEXHOME/lib","$FEXHOME/cgi-bin");
373 print "F*EX update installed.\n";
374 print "You can inform your users about the new features with:\n";
375 print "$FEXHOME/bin/fexwall 'new F*EX features on $hostname' ".
376 "< $FEXHOME/doc/newfeatures\n";
379 if (@local_rdomains and not @local_rhosts) {
380 print "\nWARNING:\n";
381 print "In $fph you have @local_rdomains but not @local_rhosts!\n";
382 print "Selfregistrating of external users will not work!\n";
383 print "See ${fph}_new/\n";
386 if (`$sendmail -h 2>&1` =~ /exim/ and
387 `grep trusted_users /etc/exim4/exim4.conf 2>/dev/null` !~ /\bfex\b/) {
388 print "\nWARNING:\n";
389 print "$sendmail is exim\n";
390 print "You MUST set in your exim4.conf:\n";
391 print "trusted_users = mail : uucp : fex\n";
397 my $ad = dirname($aa);
399 open $aa,'>',$aa or die "$0: cannot create $aa - $!\n";
400 print {$aa} "$admin_pw\n";
402 my $fd = dirname($fid);
404 rename $fid,$fid.'_save';
405 open $fid,'>',$fid or die "$0: cannot create $fid - $!\n";
406 print {$fid} "$hostname:$opt_p\n";
407 print {$fid} "$admin\n";
408 print {$fid} "$admin_pw\n";
410 chownr('fex',$ad,$fd);
418 if (m:^/*(lib|usr|home)?/*$:) {
419 die "ERROR: short path in chownr $user @_\n";
422 system qw'chown -R',$user,@_;
429 if (m:^/*(lib|usr|home)?/*$:) {
430 die "ERROR: short path in chmodr $mod @_\n";
433 system qw'chmod -R',$mod,@_;
437 my ($f,$d,$to,$from,$link);
442 our ($spooldir,$skeydir,$gkeydir);
443 $ENV{FEXLIB} = $FEXLIB = "$FEXHOME/lib";
444 require "$FEXLIB/fex.pp" or die "$0: cannot load $FEXLIB/fex.pp - $!\n";
445 die "no \$spooldir in $FEXLIB/fex.pp\n" unless $spooldir;
446 die "\$spooldir=$spooldir/" if $spooldir =~ m:^/*(root)?$:;
448 # User --> user@maildomain
450 foreach $f (glob "$spooldir/.dkeys/*") {
451 if ($link = readlink $f) {
452 (undef,$to,$from,$file) = split('/',$link);
454 $to .= '@'.$mdomain if $to !~ /@/;
455 $from .= '@'.$mdomain if $from !~ /@/;
456 if ($link ne "../$to/$from/$file") {
457 symlink "../$to/$from/$file",$f;
464 # fix spool layout: FROM and TO must have domains and must be lower case
465 foreach $d ((glob "$spooldir/*/*"),(glob "$spooldir/*")) {
466 if (not -l $d and -d $d and $d =~ m:(.+)/(.+):) {
469 if ($b !~ /^@/ and $b !~ /^[A-Z_-]+$/) {
470 if ($mdomain and $b !~ /@/) {
471 rename $d,sprintf("%s/%s@%s",$p,lc($b),$mdomain);
472 } elsif ($b ne lc($b)) {
473 rename $d,sprintf("%s/%s",$p,lc($b));
479 # split auth-ID and subuser file: @ --> @ @SUBUSER
480 foreach my $u (glob "$spooldir/*@*") {
481 next if -f "$u/\@SUBUSER";
482 open my $idf,"$u/\@" or next;
484 if (defined ($su = <$idf>) and $su =~ /\w/
485 and open my $suf,">$u/\@SUBUSER") {
487 while (defined ($su = <$idf>)) { print {$suf} $su }
490 if (open my $idf,">$u/\@") {
498 foreach my $sf (glob "$spooldir/*/\@SUBUSER") {
499 $user = (split '/',$sf)[-2];
503 if (/(.+\@.+):(.+)/) {
504 ($subuser,$id) = ($1,$2);
505 next if $subuser =~ /\*/;
506 $skey = md5_hex("$user:$subuser:$id");
507 if (open $skey,'>',"$skeydir/$skey") {
508 print {$skey} "from=$subuser\n",
513 mkdirp("$spooldir/$subuser/\@MAINUSER");
514 symlink $skey,"$spooldir/$subuser/\@MAINUSER/$user";
522 foreach my $gf (glob "$spooldir/*/\@GROUP/*") {
524 # normalize group name
525 if ($gf =~ m:(.+)/(.+):) {
529 $g2 =~ s/[^\w\*%^+=:,.!-]/_/g;
531 rename "$gd/$g1","$gd/$g2" and $gf = "$gd/$g2";
534 $group = (split '/',$gf)[-1];
535 $user = (split '/',$gf)[-3];
539 if (/(.+\@.+):(.+)/) {
541 $gkey = md5_hex("$user:$group:$gm:$id");
542 if (open $gkey,'>',"$gkeydir/$gkey") {
543 print {$gkey} "from=$gm\n",
549 mkdirp("$spooldir/$gm/\@GROUP");
550 symlink "../../$user/\@GROUP/$group","$spooldir/$gm/\@GROUP/$group";
562 die "cpav: $dd is not a directory" unless -d $dd;
563 open P,"tar cf - @_ | su -c 'cd $dd; umask 022; tar xvf - 2>&1' fex |"
564 or die "cpav: cannot tar - $!\n";
567 print "$_ --> $dd/$_\n" unless /\/$/;