[FIXED] Utilizar correctamente console.lib en script versadm_token.sh
🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
bbd0cb2de0
commit
65da5c525b
1 changed files with 50 additions and 53 deletions
|
@ -109,63 +109,58 @@ show_token_help() {
|
||||||
dialog --backtitle "${title}" --title "Ayuda sobre tokens de $vcs_name" --msgbox "$help_text" 22 75
|
dialog --backtitle "${title}" --title "Ayuda sobre tokens de $vcs_name" --msgbox "$help_text" 22 75
|
||||||
}
|
}
|
||||||
|
|
||||||
# Diálogo personalizado para solicitar token con botón de ayuda
|
# Diálogo para solicitar token utilizando console.lib
|
||||||
request_token_with_help() {
|
request_token_with_help() {
|
||||||
local vcs_index=$1
|
local vcs_index=$1
|
||||||
local vcs_name=${VCS_TYPES[$vcs_index]}
|
local vcs_name=${VCS_TYPES[$vcs_index]}
|
||||||
local prompt="Ingrese su token personal de $vcs_name:"
|
local prompt="Ingrese su token personal de $vcs_name:"
|
||||||
local helper="Puede generar un nuevo token en: ${VCS_TOKEN_URLS[$vcs_index]}"
|
local helper="Puede generar un nuevo token en: ${VCS_TOKEN_URLS[$vcs_index]}"
|
||||||
local button=0
|
|
||||||
local token=""
|
local token=""
|
||||||
|
local continue_loop=true
|
||||||
|
|
||||||
while [ $button -ne 1 ]; do
|
while $continue_loop; do
|
||||||
# Crear diálogo temporal
|
# Mostrar diálogo de contraseña usando console.lib
|
||||||
tempfile=$(mktemp)
|
dialog_input_pass "$prompt" "$helper"
|
||||||
|
|
||||||
# Mostrar diálogo con 3 botones (Cancelar, OK, Ayuda)
|
# Verificar resultado
|
||||||
dialog --backtitle "${title}" --title "${apps_title}" \
|
if [ $codex -ne 0 ]; then
|
||||||
--passwordbox "\n$prompt\n\n$helper" 12 70 \
|
# Usuario canceló
|
||||||
--extra-button --extra-label "Ayuda" 2>"$tempfile"
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
button=$?
|
token="$value"
|
||||||
|
|
||||||
# Procesar resultado según el botón presionado
|
# Validar el token
|
||||||
case $button in
|
if [ -z "$token" ]; then
|
||||||
0) # OK
|
dialog --keep-window --begin ${CX} ${CY} --backtitle "${title}" --title "${head_error}" --msgbox "El token no puede estar vacío. Por favor ingrese un token válido." 7 60
|
||||||
token=$(cat "$tempfile")
|
continue
|
||||||
rm -f "$tempfile"
|
fi
|
||||||
|
|
||||||
# Validar el token
|
if [ ${#token} -lt 20 ]; then
|
||||||
if [ -z "$token" ]; then
|
dialog_yesno "El token parece ser demasiado corto. Verifique que haya copiado el token completo.\n\n¿Desea continuar de todas formas?" 10 70
|
||||||
dialog --backtitle "${title}" --title "${head_error}" --msgbox "El token no puede estar vacío. Por favor ingrese un token válido." 7 60
|
if [ $? -ne 0 ]; then
|
||||||
button=3 # Mantener el bucle activo
|
continue
|
||||||
continue
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ ${#token} -lt 20 ]; then
|
# Mostrar opción de ayuda
|
||||||
dialog_yesno "El token parece ser demasiado corto. Verifique que haya copiado el token completo.\n\n¿Desea continuar de todas formas?" 10 70
|
dialog_yesno "¿Necesita ayuda para obtener un token de $vcs_name?\n\nSeleccione 'Sí' para ver instrucciones detalladas o 'No' para continuar." 10 70
|
||||||
if [ $? -ne 0 ]; then
|
if [ $? -eq 0 ]; then
|
||||||
button=3 # Mantener el bucle activo
|
show_token_help "$vcs_index"
|
||||||
continue
|
# Preguntar si desea intentar nuevamente
|
||||||
fi
|
dialog_yesno "¿Desea ingresar un token diferente?" 7 60
|
||||||
fi
|
if [ $? -eq 0 ]; then
|
||||||
|
continue
|
||||||
# Devolver el token si es válido
|
fi
|
||||||
echo "$token"
|
fi
|
||||||
return 0
|
|
||||||
;;
|
# Token válido, salir del bucle
|
||||||
1) # Cancelar
|
continue_loop=false
|
||||||
rm -f "$tempfile"
|
|
||||||
return 1
|
|
||||||
;;
|
|
||||||
3) # Botón extra (Ayuda)
|
|
||||||
rm -f "$tempfile"
|
|
||||||
show_token_help "$vcs_index"
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
done
|
done
|
||||||
|
|
||||||
return 1
|
# Devolver el token
|
||||||
|
echo "$token"
|
||||||
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
# Verificar e instalar CLI si es necesario
|
# Verificar e instalar CLI si es necesario
|
||||||
|
@ -187,11 +182,11 @@ check_and_install_cli() {
|
||||||
read
|
read
|
||||||
return $result
|
return $result
|
||||||
else
|
else
|
||||||
dialog --backtitle "${title}" --title "${head_error}" --msgbox "No se encontró el script de instalación para $vcs_name:\n$installer" 8 70
|
dialog --keep-window --begin ${CX} ${CY} --backtitle "${title}" --title "${head_error}" --msgbox "No se encontró el script de instalación para $vcs_name:\n$installer" 8 70
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
dialog --backtitle "${title}" --title "${head_info}" \
|
dialog --keep-window --begin ${CX} ${CY} --backtitle "${title}" --title "${head_info}" \
|
||||||
--msgbox "El CLI es necesario para interactuar completamente con $vcs_name.\nEl token se guardará de todas formas, pero no podrá verificar la conexión automáticamente." 9 70
|
--msgbox "El CLI es necesario para interactuar completamente con $vcs_name.\nEl token se guardará de todas formas, pero no podrá verificar la conexión automáticamente." 9 70
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
@ -219,11 +214,11 @@ save_encrypted_token() {
|
||||||
# Establecer permisos adecuados
|
# Establecer permisos adecuados
|
||||||
chmod 600 "$token_file"
|
chmod 600 "$token_file"
|
||||||
|
|
||||||
dialog --backtitle "${title}" --title "Encriptación Exitosa" \
|
dialog --keep-window --begin ${CX} ${CY} --backtitle "${title}" --title "Encriptación Exitosa" \
|
||||||
--msgbox "El token de $vcs_name ha sido encriptado exitosamente en:\n$token_file" 8 70
|
--msgbox "El token de $vcs_name ha sido encriptado exitosamente en:\n$token_file" 8 70
|
||||||
return 0
|
return 0
|
||||||
else
|
else
|
||||||
dialog --backtitle "${title}" --title "${head_error}" \
|
dialog --keep-window --begin ${CX} ${CY} --backtitle "${title}" --title "${head_error}" \
|
||||||
--msgbox "Falló la encriptación del token de $vcs_name." 7 50
|
--msgbox "Falló la encriptación del token de $vcs_name." 7 50
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
@ -238,7 +233,8 @@ test_connection() {
|
||||||
local connection_status=""
|
local connection_status=""
|
||||||
local connection_message=""
|
local connection_message=""
|
||||||
|
|
||||||
dialog --backtitle "${title}" --title "Prueba de conexión" --infobox "Probando conexión con $vcs_name..." 5 60
|
# Usar dialog en modo compatible con console.lib
|
||||||
|
dialog --keep-window --begin ${CX} ${CY} --backtitle "${title}" --title "Prueba de conexión" --infobox "Probando conexión con $vcs_name..." 5 60
|
||||||
|
|
||||||
case "$vcs_index" in
|
case "$vcs_index" in
|
||||||
0) # GitHub
|
0) # GitHub
|
||||||
|
@ -292,7 +288,8 @@ test_connection() {
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
dialog --backtitle "${title}" --title "Resultado de la prueba" --msgbox "$connection_message" 15 70
|
# Usar dialog en modo compatible con console.lib
|
||||||
|
dialog --keep-window --begin ${CX} ${CY} --backtitle "${title}" --title "Resultado de la prueba" --msgbox "$connection_message" 15 70
|
||||||
}
|
}
|
||||||
|
|
||||||
# Función principal para gestionar tokens
|
# Función principal para gestionar tokens
|
||||||
|
@ -318,7 +315,7 @@ manage_vcs_token() {
|
||||||
|
|
||||||
# Verificar índice válido
|
# Verificar índice válido
|
||||||
if [ $selection -lt 0 ] || [ $selection -ge ${#VCS_TYPES[@]} ]; then
|
if [ $selection -lt 0 ] || [ $selection -ge ${#VCS_TYPES[@]} ]; then
|
||||||
dialog --backtitle "${title}" --title "${head_error}" --msgbox "Selección inválida." 7 50
|
dialog --keep-window --begin ${CX} ${CY} --backtitle "${title}" --title "${head_error}" --msgbox "Selección inválida." 7 50
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -379,7 +376,7 @@ manage_vcs_token() {
|
||||||
dialog_yesno "¿Está seguro de que desea eliminar el token de $vcs_name?\nEsta acción no se puede deshacer." 8 60
|
dialog_yesno "¿Está seguro de que desea eliminar el token de $vcs_name?\nEsta acción no se puede deshacer." 8 60
|
||||||
if [ $? -eq 0 ]; then
|
if [ $? -eq 0 ]; then
|
||||||
rm -f "$token_file"
|
rm -f "$token_file"
|
||||||
dialog --backtitle "${title}" --title "Token eliminado" --msgbox "El token de $vcs_name ha sido eliminado." 7 50
|
dialog --keep-window --begin ${CX} ${CY} --backtitle "${title}" --title "Token eliminado" --msgbox "El token de $vcs_name ha sido eliminado." 7 50
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
Loading…
Reference in a new issue