Explorar el Código

Correcion de Errores en el parser y todas las funciones

Guzmán Castanedo Villalba hace 6 años
padre
commit
10a72049d3
Se han modificado 1 ficheros con 29 adiciones y 26 borrados
  1. 29 26
      userspanel.sh

+ 29 - 26
userspanel.sh

@@ -26,7 +26,7 @@ function leerComando {
 	#printf "\n"
 	#Parseamos la linea de comando con todas las opciones posibles.
 	printf "$Comando\n"
-	Temp=$(getopt -q -o d:g:G:p:s:fre: --long home-dir:,gid:,groups:,pasword:,shell:,force,remove,expiredate: -- $Comando)
+	Temp=$(getopt -q -o d:g:G:p:s:fre: --long home-dir:,gid:,groups:,password:,shell:,force,remove,expiredate: -- $Comando)
 	eval set -- "$Temp"
 	printf "$Temp\n"
 	while true; do
@@ -45,17 +45,19 @@ function leerComando {
 				;;
 			-p|--password)
 				password=$2
-				shift
+				shift 2
 				;;
 			-s|--shell)
 				shell=$2
-				shift
+				shift 2
 				;;
 			-f|--force)
 				force=true
+				shift
 				;;
 			-r|--remove)
 				remove=true
+				shift
 				;;
 			-e|--expiredate)
 				expireDate=$2
@@ -105,7 +107,7 @@ function altaUsuario {
 		#No existe grupo. Vamos a crearlo
 		crearGrupo $gid
 		if [ $? -ne 0 ]; then
-			printf "ERROR FATAL: No se puede crear grupo (codigo salida: $?).\n"
+			printf "ERROR FATAL: No se puede crear grupo.\n"
 			return 1
 		fi
 	fi
@@ -113,22 +115,22 @@ function altaUsuario {
 	if [ ! -z $otherGroups ]; then
 		opciones=$opciones" -G $otherGroups"
 	fi
-	#if [ -z $password ]; then
-	#	igual=false
-	#	while [ $igual = false ]; do
-	#		printf "(PASSWORD)> "
-	#		read -s password
-	#		printf "\n(Confirme PASSWORD)> "
-	#		read -s password2
-	#		printf "\n"
-	#		if [ $password = $password2 ]; then
-	#			igual=true
-	#		else
-	#			printf "ERROR: No coinciden. Vuelva a intentarlo.\n"
-	#		fi
-	#	done
-	#	unset igual password2
-	#fi
+	if [ -z $password ]; then
+		igual=false
+		while [ $igual = false ]; do
+			printf "(PASSWORD)> "
+			read -s password
+			printf "\n(Confirme PASSWORD)> "
+			read -s password2
+			printf "\n"
+			if [ $password = $password2 ]; then
+				igual=true
+			else
+				printf "ERROR: No coinciden. Vuelva a intentarlo.\n"
+			fi
+		done
+		unset igual password2
+	fi
 	#opciones=$opciones" -p $password"
 	if [ -z $shell ]; then
 		printf "Shells disponibles:\n"
@@ -167,11 +169,11 @@ function altaUsuario {
 	printf "useradd $opciones $User\n"
 	useradd $opciones $User
 	if [ $? -ne 0 ]; then
-		printf "ERROR FATAL: No se ha podido crear el usuario (codigo salida: $?).\n"
+		printf "ERROR FATAL: No se ha podido crear el usuario.\n"
 		return 1
 	fi
 	#Cambiamos usuario
-	cambiarPassword
+	printf "$password\n$password" | passwd $User >/dev/null 2>&1
 	if [ $? -ne 0 ]; then
 		printf "ERROR: al establecer contraseña (usuario creado).\n"
 		return 1
@@ -192,7 +194,6 @@ function bajaUsuario {
 		printf "\tEscribir \"usuarios\" para mostrar usuarios disponibles.\n"
 		return 1
 	fi
-	#Faltan AQUI las Opciones
 	opciones=""
 	if [ $force = true ]; then
 		opciones=$opciones" -f"
@@ -211,6 +212,7 @@ function bajaUsuario {
 			return 1
 			;;
 	esac
+	printf "userdel$opciones $User\n"
 	userdel$opciones $User
 	return 0
 }
@@ -218,6 +220,7 @@ function bajaUsuario {
 function cambiarPassword {
 #Cambiamos la contraseña del usuario ($User)
 	if [ -z $User ]; then
+		listarUsuarios
 		printf "(USUARIO)> "
 		read User
 	fi
@@ -228,7 +231,7 @@ function cambiarPassword {
 	fi
 	passwd $User
 	if [ $? -ne 0 ]; then
-		printf "ERROR FATAL: No es posible cambiar la contraseña (codigo salida: $?).\n"
+		printf "ERROR FATAL: No es posible cambiar la contraseña.\n"
 		return 1
 	fi
 	return 0
@@ -246,13 +249,13 @@ function listarUsuarios {
 
 function existeUsuario {
 	#Comprobamos si un usuario ($User) existe
-	cat /etc/passwd | cut -d: -f1 | grep $User > /dev/null 2>&1
+	cat /etc/passwd | cut -d: -f1 | grep ^$User$ > /dev/null 2>&1
 	return $?
 }
 
 function existeGrupo {
 	#Comprobamos si el grupo ($1) existe
-	cat /etc/group | cut -d: -f1 | grep $1 > /dev/null 2>&1
+	cat /etc/group | cut -d: -f1 | grep ^$1$ > /dev/null 2>&1
 	return $?
 }