diff --git a/01-utils.sh b/01-utils.sh index d3f126f..4b78c0b 100644 --- a/01-utils.sh +++ b/01-utils.sh @@ -1,5 +1,11 @@ #!/bin/sh +alias tsudo='printf "%s" "$SUDO_PASSWORD" | sudo -Skp ""' + +echo_debug() { # DEBUG + printf '\033[1mDEBUG:\033[0m \033[2m%s...\033[0m\n' "$1" # DEBUG +} # DEBUG + urlencode() { ENCODEDURL="$(curl -Gs -w %{url_effective} --data-urlencode @- ./ ||: )" printf '%s' "$ENCODEDURL" | sed 's/%0[aA]$//;s/^.*[?]//' diff --git a/03-install.sh b/03-install.sh index a0f27d7..d764e7b 100644 --- a/03-install.sh +++ b/03-install.sh @@ -1,11 +1,6 @@ #!/bin/sh # TODO: # - Check all variables to avoid root execution on unspecified places -echo_debug() { # DEBUG - printf '\033[1mDEBUG:\033[0m \033[2m%s...\033[0m\n' "$1" # DEBUG -} # DEBUG - -alias tsudo='printf "%s" "$SUDO_PASSWORD" | sudo -Skp ""' debian_install_certs() { # Source: https://fran.cr/instalar-firma-digital-costa-rica-gnu-linux-ubuntu-debian/ diff --git a/04-main.sh b/04-main.sh index ee5f2e0..5bb03c4 100644 --- a/04-main.sh +++ b/04-main.sh @@ -18,7 +18,7 @@ if [ "$MENU" = "zenity" ] ; then 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##* }" @@ -67,42 +67,41 @@ if [ "$MENU" = "zenity" ] ; then echo_debug "Termina correctamente" # DEBUG zenity --title "$TITLE" --text "$PROMPT_END_SUCCESS" --info -else - MENU="term" - term_prompt "$TITLE" "$PROMPT_WELCOME" info && read -r NULL - ! command -v curl && term_prompt "$TITLE" "$PROMPT_ERR_DEPS curl" error && exit 1 +elif [ "$MENU" = "term" ] ; then + term_prompt info "$PROMPT_WELCOME" && read -r NULL + ! command -v curl && term_prompt error "$TITLE" "$PROMPT_ERR_DEPS curl" && exit 1 # Serial number is required for download - term_prompt "$TITLE" "$PROMPT_SERIAL" entry && read -r SERIAL - [ -z "$SERIAL" ] && term_prompt "$TITLE" "$PROMPT_ERR_SERIAL" error && exit 1 + term_prompt entry "$PROMPT_SERIAL" && read -r SERIAL + [ -z "$SERIAL" ] && term_prompt error "$TITLE" "$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 "$TITLE" "$PROMPT_ERR_DOWNLOAD" error && exit 1 - [ -z "$FILE" ] && term_prompt "$TITLE" "$PROMPT_ERR_DOWNLOAD" error && exit 1 + [ -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 "$TITLE" "$PROMPT_DOWNLOAD" info && echo + term_prompt info "$PROMPT_DOWNLOAD" && echo curl "$DOWNLOAD_URL" -o "$SAVE_FILE" --progress-bar echo_debug "Consultar sudo pass" # DEBUG - term_prompt "$TITLE" "$PROMPT_SUDO_PASSWORD" entry && IFS= read -r SUDO_PASSWORD - [ -z "$SUDO_PASSWORD" ] && term_prompt "$TITLE" "$PROMPT_ERR_DEPS_INSTALL" error && exit 1 - CORRECT_SUDO_PASSWORD="$(printf '%s' "$SUDO_PASSWORD" | sudo -Skp '' whoami >/dev/null 2>&1 || printf 'no')" - [ "$CORRECT_SUDO_PASSWORD" = "no" ] && term_prompt "$TITLE" "$PROMPT_ERR_DEPS_INSTALL" error && exit 1 + term_prompt entry "$PROMPT_SUDO_PASSWORD" && 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 "$TITLE" "$PROMPT_DEPS_INSTALL" info && echo + term_prompt info "$PROMPT_DEPS_INSTALL" && echo install_certs "$SAVE_FILE" - [ "$?" != "0" ] && term_prompt "$TITLE" "$PROMPT_ERR_DEPS_INSTALL" error && exit 1 + [ "$?" != "0" ] && term_prompt error "$PROMPT_ERR_DEPS_INSTALL" && exit 1 - term_prompt "$TITLE" "$PROMPT_END_SUCCESS" info && echo + term_prompt info "$PROMPT_END_SUCCESS" && echo fi