]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blob - config/extrahd/extrahd.pl
d4782f867e6d7ae3902025e64dd0068e8712bd36
[people/pmueller/ipfire-2.x.git] / config / extrahd / extrahd.pl
1 #!/usr/bin/perl
2 #
3 # IPFire Scripts
4 #
5 # This code is distributed under the terms of the GPL
6 #
7 # (c) The IPFire Team
8 #
9
10 use strict;
11 # enable only the following on debugging purpose
12 # use warnings;
13
14 require '/var/ipfire/general-functions.pl';
15 require "${General::swroot}/lang.pl";
16 require "${General::swroot}/header.pl";
17
18 my %extrahdsettings = ();
19 my $ok = "true";
20 my @devices = ();
21 my @deviceline = ();
22 my $deviceentry = "";
23 my $devicefile = "/var/ipfire/extrahd/devices";
24 my $fstab = "/var/ipfire/extrahd/fstab";
25
26 ### Values that have to be initialized
27 $extrahdsettings{'PATH'} = '';
28 $extrahdsettings{'FS'} = '';
29 $extrahdsettings{'DEVICE'} = '';
30 $extrahdsettings{'ACTION'} = '';
31
32 open( FILE, "< $devicefile" ) or die "Unable to read $devicefile";
33 @devices = <FILE>;
34 close FILE;
35
36 ############################################################################################################################
37 ############################################################################################################################
38
39 print "$ARGV[0] $ARGV[1]";
40
41 if ( "$ARGV[0]" eq "mount" ) {
42 system("/bin/cp -f /etc/fstab $fstab");
43
44 foreach $deviceentry (sort @devices)
45 {
46 @deviceline = split( /\;/, $deviceentry );
47 if ( "$ARGV[1]" eq "$deviceline[2]" ) {
48 print "Insert /dev/$deviceline[0] ($deviceline[1]) --> $deviceline[2] into /etc/fstab!\n";
49 unless ( -d $deviceline[2] ) { system("/bin/mkdir -p $deviceline[2] && chmod 0777 $deviceline[2]"); }
50 open(FILE, ">>$fstab");
51 print FILE "/dev/$deviceline[0]\t$deviceline[2]\t$deviceline[1]\tdefaults\t0\t0\n";
52 close(FILE);
53 }
54 }
55
56 system("/bin/cp -f $fstab /etc/fstab");
57 if ( `/bin/mount -a` ) {
58 exit(0);
59 } else {
60 exit(1);
61 }
62
63 } elsif ( "$ARGV[0]" eq "umount" ) {
64 system("/bin/umount $ARGV[1]");
65 if ( ! `/bin/mount | /bin/fgrep $ARGV[1]` ) {
66 system("/bin/cp -f /etc/fstab $fstab");
67 system("/bin/fgrep -v $ARGV[1] <$fstab >/etc/fstab");
68 print "Succesfully umounted $ARGV[1].\n";
69 exit(0);
70 } else {
71 print "Can't umount $ARGV[1].\n";
72 exit(1);
73 }
74
75 } else {
76 print "Usage: $0 (mount|umount) mountpoint\n";
77 }
78
79 ############################################################################################################################
80 ############################################################################################################################