Trying to repair dfferences b/w the merge
[vsys.git] / factory / nfsmount
1 #!/usr/bin/perl
2
3 use strict;
4
5 my $slicename=$ARGV[0];
6 my $already_mounted_testfile = "/tmp/$slicename"."_nfsmounted";
7
8 my $slice_dir="/vservers/$slicename/";
9
10 if (-f $already_mounted_testfile) {
11         die("Sorry, only one successful NFS mount allowed per slice!");
12 }
13
14 my $remotepath = <STDIN>;
15 my $localpath = <STDIN>;
16 chomp($localpath);
17 chomp($remotepath);
18 $localpath=~s/\.\.//g;
19
20 $localpath=$slice_dir.$localpath;
21
22 unless (-d $localpath) {
23         die("Localpath does not exist, please create it first.");
24 }
25
26 my $hostexpr="(?=^.{1,254}$)(^(?:(?!\d+\.|-)[a-zA-Z0-9_\-]{1,63}(?<!-)\.?)+(?:[a-zA-Z]{2,})$)";
27 my $pathexpr="\/?[\w\d]+\/[\w\d]*\/?";
28 my $nfshost;
29 my $nfspath;
30
31 ($nfshost,$nfspath)=split ':',$remotepath;
32
33 if ($nfshost!~/(?=^.{1,254}$)(^(?:(?!\d+\.|-)[a-zA-Z0-9_\-]{1,63}(?<!-)\.?)+(?:[a-zA-Z]{2,})$)/) {
34         die("The hostname $nfshost does not seem to be right.");
35 }
36
37 if ($nfspath!~/^(((\.\.){1}\/)*|(\/){1})?(([a-zA-Z0-9]*)\/)*([a-zA-Z0-9]*)+$/) {
38         die("The remote path $nfspath does not seem to be right.");
39
40
41 my $mntcmd="/bin/mount $remotepath $localpath";
42 system($mntcmd);
43
44 if ($?) {
45     print "Mount failed: $?";
46 }
47 else {
48     open FIL, ">$already_mounted_testfile";
49     print FIL "$remotepath $localpath";
50     close FIL;
51 }