Imported Upstream version 2.4.4p3
[debian/amanda] / client-src / amsinixfixdevs.sh
1
2 eval '(exit $?0)' && eval 'exec perl -x -S $0 ${1+"$@"}'
3         & eval 'exec perl -x -S $0 $argv:q'
4                 if 0;
5
6 #!perl
7
8 # Check whether we're on a SINIX system.
9 $uname=`uname`;
10 chomp $uname;
11 if ( $uname !~ /SINIX/ ) {
12   die("Sorry, this script only works for SINIX systems!\n");
13 }
14
15 # Check whether the user is root.
16 $id=`id -un`;
17 chomp $id;
18 if ( $id ne "root" ) {
19   die("Sorry, this script needs to be run by the superuser!\n");
20 }
21
22 # Determine all filesystems currently mounted.
23 print "\nDetermining all filesystems currently mounted...\n";
24 open(VD, "/usr/bin/mount -p 2>/dev/null |") or
25   die("$0: unable to open mount pipe: $!\n");
26 while ( <VD> ) {
27   if ( m!^(/dev/\S*)\s+-\s+(\S+)\s+(vxfs|ufs)\s+! ) {
28     $v = $1;
29     print "Found filesystem $v\n";
30     $vd{$v}++;
31   }
32 }
33 close VD or
34   warn "$0: error in closing mount pipe: $!\n";
35
36 # Determine all virtual disks.
37 undef($v);
38 print "\nDetermining all virtual disks...\n";
39 open(VD, "/sbin/dkconfig -lA 2>/dev/null |") or
40   die("$0: unable to open dkconfig pipe: $!\n");
41 while ( <VD> ) {
42   if ( m!^(/dev/\S*):\s+\d+\s+blocks! ) {
43     $v = $1;
44     print "Found virtual disk $v\n";
45     $vd{$v}++;
46   }
47 }
48 close VD or
49   warn "$0: error in closing dkconfig pipe: $!\n";
50
51 # Check whether our target directories are present.
52 foreach $d ( "/dev/dsk", "/dev/rdsk" ) {
53   if ( ! -x $d ) {
54     if ( ! mkdir($d, 0755) ) {
55       die("Failed to create directory $d!\n");
56     }
57   }
58 }
59
60 # Now fix the device entries for all virtual disks.
61 print "\nFixing device entries...\n";
62 foreach $v ( keys(%vd) ) {
63   # determine the basename of the device
64   ( $name ) = $v =~ m!^/dev/(.+)$!;
65   if ( $name =~ m!/! ) {
66     ( $p, $dev_orig ) = $name =~ m!(.*/)(.*)!;
67   }
68   else {
69     $p = "";
70     $dev_orig = $name;
71   }
72
73   # replace all slashes with _'s
74   $dev_new = $name;
75   $dev_new =~ s!/!_!g;
76
77   # First the link for the block device.
78   if ( ! -e "/dev/dsk/$dev_new" ) {
79     print "Creating link for /dev/dsk/$dev_new...";
80     if ( ! symlink($v, "/dev/dsk/$dev_new") ) {
81       print "FAILED\n";
82       next;
83     }
84     print "done\n";
85   }
86
87   # Now the link for the raw devive.
88   if ( ! -e "/dev/rdsk/$dev_new" ) {
89     print "Creating link for /dev/rdsk/$dev_new...";
90     if ( ! symlink("/dev/${p}r$dev_orig", "/dev/rdsk/$dev_new") ) {
91       print "FAILED\n";
92       next;
93     }
94     print "done\n";
95   }
96 }