-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnfs_server.sh
68 lines (50 loc) · 1.22 KB
/
nfs_server.sh
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
59
60
61
62
63
64
65
66
67
68
#!/bin/bash
n_lines=$(cat $svc_cf | wc -l)
if [[ $n_lines -lt 1 ]]
then
perror "El fichero de perfil de servicio debe tener una o mas lineas"
exit 61
fi
while read line; do
n_words1=$(wc -w <<< $line)
if [[ $n_words1 -ne 1 ]]
then
perror "El formato del fichero de perfil de servicio es incorrecto"
exit 62
fi
done < $svc_cf
ssh -T $host >/dev/null << 'EOSSH'
perror() { echo -e "$@" 1>&2; }
apt install -y nfs-kernel-server &>/dev/null
if [[ $? -ne 0 ]]
then
perror "Error en la instalacion de los paquetes necesarios"
exit 63
fi
input=conf
while IFS= read -r line
do
filename_pat='[[:alnum:]/_.-]+'
pattern="^(${filename_pat})$"
if [[ ! "$line" =~ $pattern ]]
then
perror "La siguiente linea no cumple con el formato correcto: \n$line"
exit 64
fi
dir_to_export=$line
if [[ ! -d $dir_to_export ]]
then
perror "Directorio a exportar no existe o es un fichero de un tipo distinto a directorio"
exit 65
fi
echo "$dir_to_export *(rw,sync)" >> /etc/exports
echo -e "La siguiente linea ha sido procesada satisfactoriamente: \n$line"
done < "$input"
exportfs -ra &>/dev/null
if [[ $? -ne 0 ]]
then
perror "Error en la exportacion de los directorios"
exit 66
fi
EOSSH
exit $?