-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuesp-addfstabentry
executable file
·58 lines (46 loc) · 1.17 KB
/
uesp-addfstabentry
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/bin/sh
#<server>:</remote/export> </local/directory> <nfs-type> <options> 0 0
# $1 = Server
# $2 = Remote path
# $3 = Local path to mount
#
SERVER="$1"
REMOTEPATH="$2"
LOCALPATH="$3"
NFSTYPE="nfs"
NFSOPTIONS="defaults,_netdev"
FSTAB="/etc/fstab"
if [ -z "$1" ] || [ -z "$2" ] || [ -z "$3" ]
then
echo " ERROR: Missing parameter in call to uesp-addfstabentry(Server, RemotePath, LocalPath)!"
exit -1
fi
RESULT=`egrep -ic "^$SERVER:$REMOTEPATH[ ^I]*" "$FSTAB"`
if [ "$RESULT" -gt 0 ]
then
echo " OK: Entry for '$SERVER:$REMOTEPATH' already exists in '$FSTAB'."
exit 0
fi
echo "$SERVER:$REMOTEPATH $LOCALPATH $NFSTYPE $NFSOPTIONS 0 0" >> "$FSTAB"
if [ $? != 0 ]
then
echo " ERROR: Failed to add entry for '$SERVER:$REMOTEPATH' to '$FSTAB'!"
exit -2
fi
if [ ! -d "$LOCALPATH" ]
then
mkdir -p "$LOCALPATH"
if [ $? != 0 ]
then
echo " ERROR: Failed to create local mount directory '$LOCALPATH'!"
exit -3
fi
echo " OK: Created local mount directory '$LOCALPATH'."
COPYPATH=`echo "$LOCALPATH" | sed "s:/mnt/:/mntcopy/:"`
if [ ! -d "$COPYPATH" ]
then
mkdir -p "$COPYPATH"
fi
fi
echo " OK: Added entry for '$SERVER:$REMOTEPATH' to '$FSTAB'."
exit 0