#!/usr/bin/perl -w

if (@ARGV) {
  if ($ARGV[0] eq 'real') {
       print "Real run !!!\nPrepare yourself to be rebooted.\n\n";
       $mode = 'real';
  }
  else {
      print "Syntax is :\nfor test(dry) run : $0\nfor real(wet) run : $0 real\n\n";
      exit;
  }
}
else {
    print "Test run\nTo run for real use argument ``real''\n\n";
    $mode = 'fake';
}

chdir '/dev';
@file_list = `ls`;
for $file(@file_list) {
  chomp $file;
     if ( $file eq 'fd' )		{ $trans = '/hurd/magic --directory fd' }
  elsif ( $file =~/^[hsf]d\d+(s\d+)?$/)	{ $trans = "/hurd/storeio $file" }
  elsif ( $file eq 'tty' )		{ $trans = '/hurd/magic tty' }
  elsif ( $file =~ /^tty(.+)$/ )	{ $trans = "/hurd/term /dev/$file pty-slave /dev/pty$1" }
  elsif ( $file =~ /^pty(.+)$/ )	{ $trans = "/hurd/term /dev/$file pty-master /dev/tty$1" }
  elsif ( $file eq 'zero' )		{ $trans = '/hurd/storeio'}
  elsif ( $file eq 'stdin' )		{ $trans = '/hurd/symlink fd/0' }
  elsif ( $file eq 'stdout' )		{ $trans = '/hurd/symlink fd/1' }
  elsif ( $file eq 'stderr' )		{ $trans = '/hurd/symlink fd/2' }
  elsif ( $file eq 'null' )		{ $trans = '/hurd/null' }
  elsif ( $file eq 'full' )		{ $trans = '/hurd/null --full' }
  elsif ( $file eq 'time' )		{ $trans = '/hurd/storeio --no-cache time' }
  elsif ( $file eq 'mem' )		{ $trans = '/hurd/storeio --no-cache mem' }
  elsif ( $file eq 'console' )		{ $trans = '/hurd/term /dev/console device console' }
  elsif ( $file eq 'log' )		{ $trans = '/hurd/ifsock' }
  elsif ( $file eq 'MAKEDEV' )		{ next }
  else {
      print "Warning : unknown device /dev/$file\n";
      next;
  }
  $command = 'settrans '.$file.' '.$trans;
     if ( $mode eq 'real' ) { system $command }
  elsif ( $mode eq 'fake' ) { print $command,"\n" }
}

chdir '/servers';
$command =
"settrans -c crash-kill /hurd/crash --kill
settrans -c crash-suspend /hurd/crash --suspend
settrans -c crash-dump-core /hurd/crash --dump-core
settrans -c socket/local /hurd/pflocal
settrans -c socket/inet /hurd/pfinet
settrans -c password /hurd/password
settrans -c exec /hurd/exec
";

   if ( $mode eq 'real' ) { system $command }
elsif ( $mode eq 'fake' ) { print $command,"\n" }
