one menu
This commit is contained in:
parent
357dded961
commit
3c714486e1
1 changed files with 71 additions and 83 deletions
154
04-main.sh
154
04-main.sh
|
@ -4,107 +4,95 @@
|
||||||
# - Check if already installed
|
# - Check if already installed
|
||||||
# - Uninstall
|
# - Uninstall
|
||||||
# - Allow to use already set variables
|
# - Allow to use already set variables
|
||||||
|
|
||||||
# main
|
# main
|
||||||
set_lang
|
set_lang
|
||||||
set_version
|
set_version
|
||||||
set_menu
|
set_menu
|
||||||
|
|
||||||
|
menu info "$PROMPT_WELCOME"
|
||||||
|
|
||||||
|
if ! command -v curl > /dev/null ; then
|
||||||
|
menu error "$PROMPT_ERR_DEPS curl"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
SERIAL="$(menu entry "$PROMPT_SERIAL")"
|
||||||
|
if [ -z "$SERIAL" ] ; then
|
||||||
|
menu error "$PROMPT_ERR_SERIAL"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
ARCHIVE="$(get_archive)"
|
||||||
|
TEMPKEY="${ARCHIVE##* }"
|
||||||
|
FILE="${ARCHIVE%% *}"
|
||||||
|
|
||||||
|
DOWNLOAD_URL="$(
|
||||||
|
printf 'https://soportefirmadigital.com/sfdj/getiso.aspx?tempkey=%s' \
|
||||||
|
"$TEMPKEY"
|
||||||
|
)"
|
||||||
|
|
||||||
|
SIZE="$(curl -sI "$DOWNLOAD_URL" |
|
||||||
|
sed '/[Cc]ontent-[Ll]ength/!d;s/^.*: //g' |
|
||||||
|
awk '{$1/=1024;printf "%d",$1}'
|
||||||
|
)"
|
||||||
|
|
||||||
|
if [ "$SIZE" -lt 500 ] || [ -z "$FILE" ] ; then
|
||||||
|
menu error "$PROMPT_ERR_DOWNLOAD"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
SAVE_DIR="/tmp/soportefirmadigital"
|
||||||
|
SAVE_FILE="$SAVE_DIR/$FILE"
|
||||||
|
mkdir -p "$SAVE_DIR"
|
||||||
|
|
||||||
if [ "$MENU" = "zenity" ] ; then
|
if [ "$MENU" = "zenity" ] ; then
|
||||||
echo_debug "Iniciando zenity" # DEBUG
|
|
||||||
MENU="zenity"
|
|
||||||
zenity --title "$TITLE" --text "$PROMPT_WELCOME" --info
|
|
||||||
! command -v curl > /dev/null && zenity --title "$TITLE" --text "$PROMPT_ERR_DEPS curl" --error && exit 1
|
|
||||||
|
|
||||||
echo_debug "Pregunta serial" # DEBUG
|
|
||||||
SERIAL="$(zenity --title "$TITLE" --text "$PROMPT_SERIAL" --entry)"
|
|
||||||
[ -z "$SERIAL" ] && zenity --title "$TITLE" --text "$PROMPT_ERR_SERIAL" --error && exit 1
|
|
||||||
|
|
||||||
echo_debug "Generar tempkey y obtener URL de descarga" # DEBUG
|
|
||||||
ARCHIVE="$(get_archive)"
|
|
||||||
TEMPKEY="${ARCHIVE##* }"
|
|
||||||
FILE="${ARCHIVE%% *}"
|
|
||||||
DOWNLOAD_URL="$(printf 'https://soportefirmadigital.com/sfdj/getiso.aspx?tempkey=%s' "$TEMPKEY")"
|
|
||||||
[ -z "$DOWNLOAD_URL" ] && zenity --title "$TITLE" --text "$PROMPT_ERR_DOWNLOAD" --error && exit 1
|
|
||||||
[ -z "$FILE" ] && zenity --title "$TITLE" --text "$PROMPT_ERR_DOWNLOAD" --error && exit 1
|
|
||||||
SAVE_DIR="/tmp/soportefirmadigital"
|
|
||||||
SAVE_FILE="$SAVE_DIR/$FILE"
|
|
||||||
mkdir -p "$SAVE_DIR"
|
|
||||||
SIZE="$(curl -sI "$DOWNLOAD_URL" | sed '/[Cc]ontent-[Ll]ength/!d;s/^.*: //g' | awk '{$1/=1024;printf "%d",$1}')"
|
|
||||||
|
|
||||||
echo_debug "Descargar y mostrar progreso" # DEBUG
|
|
||||||
(curl -sL "$DOWNLOAD_URL" -o "$SAVE_FILE") &
|
(curl -sL "$DOWNLOAD_URL" -o "$SAVE_FILE") &
|
||||||
while true ; do
|
while true ; do
|
||||||
sleep 0.5
|
sleep 0.5
|
||||||
DOWN="$(du "$SAVE_FILE" 2>/dev/null | awk '{print $1}')" ; [ -z "$DOWN" ] && DOWN=0
|
DOWN="$(du "$SAVE_FILE" 2>/dev/null | awk '{print $1}')"
|
||||||
|
[ -z "$DOWN" ] && DOWN=0
|
||||||
r=$(((DOWN*10000)/SIZE))
|
r=$(((DOWN*10000)/SIZE))
|
||||||
printf '%d\n' ${r%??}
|
printf '%d\n' ${r%??}
|
||||||
done | zenity --title "$TITLE" --text "$PROMPT_DOWNLOAD" --progress --auto-close
|
done | zenity --title "$TITLE" --text "$PROMPT_DOWNLOAD" --progress --auto-close
|
||||||
while true ; do
|
|
||||||
ACTIVE="$(ps aux | grep 'curl.*soportefirmadigital' | sed '/grep/d')"
|
|
||||||
[ -z "$ACTIVE" ] && break
|
|
||||||
sleep 0.5
|
|
||||||
done | zenity --title "$TITLE" --text "$PROMPT_DOWNLOAD" --progress --pulsate --auto-close
|
|
||||||
ACTIVE="$(ps aux | grep 'curl.*soportefirmadigital' | sed '/grep/d')"
|
|
||||||
[ -n "$ACTIVE" ] && zenity --title "$TITLE" --text "$PROMPT_ERR_DOWNLOAD" --error && exit 1
|
|
||||||
|
|
||||||
echo_debug "Consultar sudo pass" # DEBUG
|
elif [ "$MENU" = "term" ] ; then
|
||||||
SUDO_PASSWORD="$(zenity --title "$TITLE" --password)"
|
menu info "$PROMPT_DOWNLOAD" && echo
|
||||||
[ -z "$SUDO_PASSWORD" ] && zenity --title "$TITLE" --text "$PROMPT_ERR_DEPS_INSTALL" --error && exit 1
|
curl "$DOWNLOAD_URL" -o "$SAVE_FILE" --progress-bar
|
||||||
CORRECT_SUDO_PASSWORD="$(printf '%s' "$SUDO_PASSWORD" | sudo -Skp '' whoami >/dev/null 2>&1 || printf 'no')"
|
|
||||||
[ "$CORRECT_SUDO_PASSWORD" = "no" ] && zenity --title "$TITLE" --text "$PROMPT_ERR_DEPS_INSTALL" --error && exit 1
|
|
||||||
|
|
||||||
# Attempt to install, forward output to zenity
|
fi
|
||||||
|
|
||||||
|
ACTIVE="$(ps -t | grep 'curl.*soportefirmadigital' | sed '/grep/d')"
|
||||||
|
ACTIVE="${ACTIVE# }"
|
||||||
|
ACTIVEID="${ACTIVE%% *}"
|
||||||
|
if [ -n "$ACTIVE" ] ; then
|
||||||
|
menu error "$PROMPT_ERR_DOWNLOAD"
|
||||||
|
echo_debug "Killing process ID: $ACTIVEID from: $ACTIVE" # DEBUG
|
||||||
|
kill "$ACTIVEID"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
SUDO_PASSWORD="$(menu pass "$PROMPT_PASS_DEPS_INSTALL")"
|
||||||
|
if [ -z "$SUDO_PASSWORD" ] || ! tsudo whoami >/dev/null 2>&1 ; then
|
||||||
|
menu error "$PROMPT_ERR_DEPS_INSTALL"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "$MENU" = "zenity" ] ; then
|
||||||
|
# Attempt to install, forward output to program
|
||||||
# but keep exit code of install function
|
# but keep exit code of install function
|
||||||
echo_debug "Funcion install_certs, corre de acuerdo al OS" # DEBUG
|
|
||||||
( ( ( (install_certs; echo $? >&3) |
|
( ( ( (install_certs; echo $? >&3) |
|
||||||
zenity --title "$TITLE" --text "$PROMPT_DEPS_INSTALL" --progress --pulsate --auto-close >&4) 3>&1 ) |
|
zenity --title "$TITLE" --text "$PROMPT_DEPS_INSTALL" --progress --pulsate --auto-close >&4) 3>&1 ) |
|
||||||
(read -r xs; exit "$xs") ) 4>&1
|
(read -r xs; exit "$xs") ) 4>&1
|
||||||
#install_certs # Just run this instead to see debug info # DEBUG
|
#install_certs # Just run this instead to see debug info # DEBUG
|
||||||
|
if [ "$?" != "0" ] ; then
|
||||||
# install_certs fails (exit code != 0)
|
menu error "$PROMPT_ERR_DEPS_INSTALL"
|
||||||
[ "$?" != "0" ] && zenity --title "$TITLE" --text "$PROMPT_ERR_DEPS_INSTALL" --error && exit 1
|
exit 1
|
||||||
|
fi
|
||||||
echo_debug "Termina correctamente" # DEBUG
|
|
||||||
zenity --title "$TITLE" --text "$PROMPT_END_SUCCESS" --info
|
|
||||||
|
|
||||||
elif [ "$MENU" = "term" ] ; then
|
elif [ "$MENU" = "term" ] ; then
|
||||||
term_prompt info "$PROMPT_WELCOME"
|
menu info "$PROMPT_DEPS_INSTALL" && echo
|
||||||
read -r nil
|
! install_certs && menu error "$PROMPT_ERR_DEPS_INSTALL" && exit 1
|
||||||
! command -v curl >/dev/null 2>&1 && term_prompt error "$PROMPT_ERR_DEPS curl" && exit 1
|
|
||||||
|
|
||||||
# Serial number is required for download
|
|
||||||
term_prompt entry "$PROMPT_SERIAL"
|
|
||||||
read -r SERIAL
|
|
||||||
[ -z "$SERIAL" ] && term_prompt error "$PROMPT_ERR_SERIAL" && exit 1
|
|
||||||
|
|
||||||
echo_debug "Generar tempkey y obtener URL de descarga" # DEBUG
|
|
||||||
ARCHIVE="$(get_archive)"
|
|
||||||
TEMPKEY="${ARCHIVE##* }"
|
|
||||||
FILE="${ARCHIVE%% *}"
|
|
||||||
DOWNLOAD_URL="$(printf 'https://soportefirmadigital.com/sfdj/getiso.aspx?tempkey=%s' "$TEMPKEY")"
|
|
||||||
[ -z "$DOWNLOAD_URL" ] && term_prompt error "$PROMPT_ERR_DOWNLOAD" && exit 1
|
|
||||||
[ -z "$FILE" ] && term_prompt error "$PROMPT_ERR_DOWNLOAD" && exit 1
|
|
||||||
SAVE_DIR="/tmp/soportefirmadigital"
|
|
||||||
SAVE_FILE="$SAVE_DIR/$FILE"
|
|
||||||
mkdir -p "$SAVE_DIR"
|
|
||||||
SIZE="$(curl -sI "$DOWNLOAD_URL" | sed '/[Cc]ontent-[Ll]ength/!d;s/^.*: //g' | awk '{$1/=1024;printf "%d",$1}')"
|
|
||||||
|
|
||||||
term_prompt info "$PROMPT_DOWNLOAD" && echo
|
|
||||||
curl "$DOWNLOAD_URL" -o "$SAVE_FILE" --progress-bar
|
|
||||||
|
|
||||||
echo_debug "Consultar sudo pass" # DEBUG
|
|
||||||
term_prompt entry "$PROMPT_PASS_DEPS_INSTALL"
|
|
||||||
IFS= read -r SUDO_PASSWORD
|
|
||||||
[ -z "$SUDO_PASSWORD" ] && term_prompt error "$PROMPT_ERR_DEPS_INSTALL" && exit 1
|
|
||||||
CORRECT_SUDO_PASSWORD="$(tsudo whoami >/dev/null 2>&1 || printf 'no')"
|
|
||||||
[ "$CORRECT_SUDO_PASSWORD" = "no" ] && term_prompt error "$PROMPT_ERR_DEPS_INSTALL" && exit 1
|
|
||||||
|
|
||||||
# Install dependencies, components and
|
|
||||||
# certificates according to OS
|
|
||||||
term_prompt info "$PROMPT_DEPS_INSTALL" && echo
|
|
||||||
! install_certs "$SAVE_FILE" && term_prompt error "$PROMPT_ERR_DEPS_INSTALL" && exit 1
|
|
||||||
|
|
||||||
term_prompt info "$PROMPT_END_SUCCESS" && echo
|
|
||||||
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
menu info "$PROMPT_END_SUCCESS"
|
||||||
|
|
||||||
|
exit 0
|
||||||
|
|
Loading…
Reference in a new issue