]>
Commit | Line | Data |
---|---|---|
1 | #!/usr/bin/perl | |
2 | ############################################################################### | |
3 | # # | |
4 | # IPFire.org - A linux based firewall # | |
5 | # Copyright (C) 2010 IPFire Team <info@ipfire.org> # | |
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 | ############################################################################### | |
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 | if ( "$ARGV[0]" eq "mount" ) { | |
52 | system("/bin/cp -f /etc/fstab $fstab"); | |
53 | ||
54 | foreach $deviceentry (sort @devices) | |
55 | { | |
56 | @deviceline = split( /\;/, $deviceentry ); | |
57 | if ( "$ARGV[1]" eq "$deviceline[2]" ) { | |
58 | print "Insert $deviceline[0] ($deviceline[1]) --> $deviceline[2] into /etc/fstab!\n"; | |
59 | unless ( -d $deviceline[2] ) { system("/bin/mkdir -p $deviceline[2] && chmod 0777 $deviceline[2]"); } | |
60 | open(FILE, ">>$fstab"); | |
61 | print FILE "$deviceline[0]\t$deviceline[2]\t$deviceline[1]\tdefaults\t0\t0\n"; | |
62 | close(FILE); | |
63 | } | |
64 | } | |
65 | ||
66 | system("/bin/cp -f $fstab /etc/fstab"); | |
67 | if ( `/bin/mount -a` ) { | |
68 | exit(0); | |
69 | } else { | |
70 | exit(1); | |
71 | } | |
72 | ||
73 | } elsif ( "$ARGV[0]" eq "umount" ) { | |
74 | system("/bin/umount $ARGV[1]"); | |
75 | if ( ! `/bin/mount | /bin/fgrep $ARGV[1]` ) { | |
76 | system("/bin/cp -f /etc/fstab $fstab"); | |
77 | system("/bin/fgrep -v $ARGV[1] <$fstab >/etc/fstab"); | |
78 | print "Successfully umounted $ARGV[1].\n"; | |
79 | exit(0); | |
80 | } else { | |
81 | print "Can't umount $ARGV[1].\n"; | |
82 | exit(1); | |
83 | } | |
84 | ||
85 | } elsif ( "$ARGV[0]" eq "scanhd") { | |
86 | system("/usr/local/bin/scanhd $ARGV[1]"); | |
87 | ||
88 | } else { | |
89 | print "Usage: $0 (mount|umount|scanhd) mountpoint\n"; | |
90 | } | |
91 | ||
92 | ############################################################################################################################ | |
93 | ############################################################################################################################ |