Script para la exportación de directorios en sistemas Linux.
#!/bin/bash
DIR=vacio
READ=vacio
WRITE=vacio
MACHINE=vacio
SERVICES=vacio
NOTVALID=1
clear
while getopts d:rwm:s OPCION
do
if [ "$OPCION" = "d" ];then
DIR=$OPTARG
NOTVALID=2
fi
if [ "$OPCION" = "r" ];then
READ=si
fi
if [ "$OPCION" = "w" ];then
WRITE=si
fi
if [ "$OPCION" = "m" ];then
MACHINE=$OPTARG
NOTVALID=2
fi
if [ "$OPCION" = "s" ];then
SERVICES=si
fi
done
if [ "$NOTVALID" = 2 ];then
if [ "$DIR" = "vacio" ] || [ "$DIR" = "" ];then
echo "[X] El directorio introducido no es valido."
sleep 2
exit
else
test -d $DIR
EXISTE=$?
if [ "$EXISTE" = 1 ];then
echo "[X] El directorio introducido no existe."
sleep 2
echo "[?] ¿Desea crearlo? (s/n)"
read ANS
if [ "$ANS" = "s" ];then
mkdir $DIR
else
NOTVALID=1
fi
else
if [ "$MACHINE" = "vacio" ];then
echo "[i] Introduzca una maquina o una red para establecer el compartimento:"
read MACHINE
echo "[?] ¿Se trata de una red? (s/n)"
read ANS
if [ "$ANS" = "s" ];then
echo "Ajustando parametros de mascara para la red $MACHINE ..."
sleep 2
MACHINE=$MACHINE"/255.255.255.0"
fi
fi
fi
fi
fi
EXISTE=1
if [ "$NOTVALID" = 1 ];then
until [ "$EXISTE" = 0 ]
do
echo "[i] Introduzca un directorio a exportar:"
echo "Directorio (Ruta completa):"
read DIR
test -d $DIR
EXISTE=$?
if [ "$EXISTE" = 1 ];then
echo "[X] El directorio introducido no existe."
sleep 2
echo "[?] ¿Desea crearlo? (s/n)"
read ANS
if [ "$ANS" = "s" ];then
mkdir $DIR
EXISTE=0
fi
else
echo "Asignando permisos minimos necesarios ..."
sleep 2
chmod o+r $DIR
echo "[i] Introduzca una maquina para añadir al fichero de compartimento:"
read MACHINE
echo "[?] ¿Se trata de una red? (s/n)"
read ANS
if [ "$ANS" = "s" ];then
echo "Ajustando parametros de mascara para la red $MACHINE ..."
sleep 2
MACHINE=$MACHINE"/255.255.255.0"
fi
fi
done
fi
echo "READ=$READ,WRITE=$WRITE"
read x
if [ "$READ" = "si" ] && [ "$WRITE" = "vacio" ];then
MACHINE=$MACHINE"(ro)"
else
if [ "$READ" = "vacio" ] && [ "$WRITE" = "si" ];then
MACHINE=$MACHINE"(rw)"
else
if [ "$READ" = "si" ] && [ "$WRITE" = "si" ];then
MACHINE=$MACHINE"(rw)"
fi
if [ "$READ" = "vacio" ] && [ "$WRITE" = "vacio" ];then
echo "[?] ¿Desea dar permiso de solo lectura al recurso, o de lectura y escritura? (r-solo lectura, w-lectura y escritura)"
read ANS
if [ "$ANS" = "r" ];then
MACHINE=$MACHINE"(ro)"
fi
if [ "$ANS" = "w" ];then
MACHINE=$MACHINE"(rw)"
fi
fi
fi
fi
echo "Concediendo los permisos establecidos ..."
sleep 2
if [ "$SERVICES" = "si" ];then
/etc/init.d/nfs restart
/etc/init.d/portmap restart
fi
echo "$DIR $MACHINE" >> /etc/exports
domingo 30 de noviembre de 2008
Suscribirse a:
Enviar comentarios (Atom)
0 comentarios:
Publicar un comentario en la entrada