]>
Commit | Line | Data |
---|---|---|
aa2870e6 | 1 | #!/usr/bin/perl |
70df8302 MT |
2 | ############################################################################### |
3 | # # | |
4 | # IPFire.org - A linux based firewall # | |
5 | # Copyright (C) 2007 Michael Tremer & Christian Schmidt # | |
6 | # # | |
7 | # This program is free software: you can redistribute it and/or modify # | |
8 | # it under the terms of the GNU General Public License as published by # | |
9 | # the Free Software Foundation, either version 3 of the License, or # | |
10 | # (at your option) any later version. # | |
11 | # # | |
12 | # This program is distributed in the hope that it will be useful, # | |
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # | |
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # | |
15 | # GNU General Public License for more details. # | |
16 | # # | |
17 | # You should have received a copy of the GNU General Public License # | |
18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. # | |
19 | # # | |
20 | ############################################################################### | |
aa2870e6 MT |
21 | |
22 | use strict; | |
23 | # enable only the following on debugging purpose | |
24 | # use warnings; | |
25 | ||
26 | require '/var/ipfire/general-functions.pl'; | |
27 | require "${General::swroot}/lang.pl"; | |
28 | require "${General::swroot}/header.pl"; | |
29 | ||
30 | my %extrahdsettings = (); | |
31 | my $ok = "true"; | |
32 | my @devices = (); | |
33 | my @deviceline = (); | |
34 | my $deviceentry = ""; | |
35 | my $devicefile = "/var/ipfire/extrahd/devices"; | |
36 | my $fstab = "/var/ipfire/extrahd/fstab"; | |
37 | ||
38 | ### Values that have to be initialized | |
39 | $extrahdsettings{'PATH'} = ''; | |
40 | $extrahdsettings{'FS'} = ''; | |
41 | $extrahdsettings{'DEVICE'} = ''; | |
42 | $extrahdsettings{'ACTION'} = ''; | |
43 | ||
44 | open( FILE, "< $devicefile" ) or die "Unable to read $devicefile"; | |
45 | @devices = <FILE>; | |
46 | close FILE; | |
47 | ||
48 | ############################################################################################################################ | |
49 | ############################################################################################################################ | |
50 | ||
51 | print "$ARGV[0] $ARGV[1]"; | |
52 | ||
53 | if ( "$ARGV[0]" eq "mount" ) { | |
54 | system("/bin/cp -f /etc/fstab $fstab"); | |
55 | ||
56 | foreach $deviceentry (sort @devices) | |
57 | { | |
58 | @deviceline = split( /\;/, $deviceentry ); | |
59 | if ( "$ARGV[1]" eq "$deviceline[2]" ) { | |
60 | print "Insert /dev/$deviceline[0] ($deviceline[1]) --> $deviceline[2] into /etc/fstab!\n"; | |
61 | unless ( -d $deviceline[2] ) { system("/bin/mkdir -p $deviceline[2] && chmod 0777 $deviceline[2]"); } | |
62 | open(FILE, ">>$fstab"); | |
63 | print FILE "/dev/$deviceline[0]\t$deviceline[2]\t$deviceline[1]\tdefaults\t0\t0\n"; | |
64 | close(FILE); | |
65 | } | |
66 | } | |
67 | ||
68 | system("/bin/cp -f $fstab /etc/fstab"); | |
69 | if ( `/bin/mount -a` ) { | |
70 | exit(0); | |
71 | } else { | |
72 | exit(1); | |
73 | } | |
74 | ||
75 | } elsif ( "$ARGV[0]" eq "umount" ) { | |
76 | system("/bin/umount $ARGV[1]"); | |
77 | if ( ! `/bin/mount | /bin/fgrep $ARGV[1]` ) { | |
78 | system("/bin/cp -f /etc/fstab $fstab"); | |
79 | system("/bin/fgrep -v $ARGV[1] <$fstab >/etc/fstab"); | |
80 | print "Succesfully umounted $ARGV[1].\n"; | |
81 | exit(0); | |
82 | } else { | |
83 | print "Can't umount $ARGV[1].\n"; | |
84 | exit(1); | |
85 | } | |
86 | ||
87 | } else { | |
88 | print "Usage: $0 (mount|umount) mountpoint\n"; | |
89 | } | |
90 | ||
91 | ############################################################################################################################ | |
92 | ############################################################################################################################ |