]> git.ipfire.org Git - ipfire-2.x.git/blame - config/extrahd/extrahd.pl
core161: add ovpnmain.cgi
[ipfire-2.x.git] / config / extrahd / extrahd.pl
CommitLineData
aa2870e6 1#!/usr/bin/perl
70df8302
MT
2###############################################################################
3# #
4# IPFire.org - A linux based firewall #
e528205e 5# Copyright (C) 2010 IPFire Team <info@ipfire.org> #
70df8302
MT
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
22use strict;
23# enable only the following on debugging purpose
24# use warnings;
25
26require '/var/ipfire/general-functions.pl';
27require "${General::swroot}/lang.pl";
28require "${General::swroot}/header.pl";
29
30my %extrahdsettings = ();
31my $ok = "true";
32my @devices = ();
33my @deviceline = ();
34my $deviceentry = "";
35my $devicefile = "/var/ipfire/extrahd/devices";
36my $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
44open( FILE, "< $devicefile" ) or die "Unable to read $devicefile";
45@devices = <FILE>;
46close FILE;
47
48############################################################################################################################
49############################################################################################################################
50
aa2870e6
MT
51if ( "$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]" ) {
784d72a2 58 print "Insert $deviceline[0] ($deviceline[1]) --> $deviceline[2] into /etc/fstab!\n";
aa2870e6
MT
59 unless ( -d $deviceline[2] ) { system("/bin/mkdir -p $deviceline[2] && chmod 0777 $deviceline[2]"); }
60 open(FILE, ">>$fstab");
784d72a2 61 print FILE "$deviceline[0]\t$deviceline[2]\t$deviceline[1]\tdefaults\t0\t0\n";
aa2870e6
MT
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");
d5f061e9 78 print "Successfully umounted $ARGV[1].\n";
aa2870e6
MT
79 exit(0);
80 } else {
81 print "Can't umount $ARGV[1].\n";
82 exit(1);
83 }
84
e528205e
AF
85} elsif ( "$ARGV[0]" eq "scanhd") {
86 system("/usr/local/bin/scanhd $ARGV[1]");
87
aa2870e6 88} else {
e528205e 89 print "Usage: $0 (mount|umount|scanhd) mountpoint\n";
aa2870e6
MT
90}
91
92############################################################################################################################
93############################################################################################################################