#!/bin/sh # TODO: # - Check if installation is successful # - Check if already installed # - Uninstall # main set_lang set_version set_menu 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") & while true ; do sleep 0.5 DOWN="$(du "$SAVE_FILE" 2>/dev/null | awk '{print $1}')" ; [ -z "$DOWN" ] && DOWN=0 r=$(((DOWN*10000)/SIZE)) printf '%d\n' ${r%??} 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 SUDO_PASSWORD="$(zenity --title "$TITLE" --password)" [ -z "$SUDO_PASSWORD" ] && zenity --title "$TITLE" --text "$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" ] && zenity --title "$TITLE" --text "$PROMPT_ERR_DEPS_INSTALL" --error && exit 1 # Attempt to install, forward output to zenity # but keep exit code of install function echo_debug "Funcion install_certs, corre de acuerdo al OS" # DEBUG ( ( ( (install_certs; echo $? >&3) | zenity --title "$TITLE" --text "$PROMPT_DEPS_INSTALL" --progress --pulsate --auto-close >&4) 3>&1 ) | (read -r xs; exit "$xs") ) 4>&1 #install_certs # Just run this instead to see debug info # install_certs fails (exit code != 0) [ "$?" != "0" ] && zenity --title "$TITLE" --text "$PROMPT_ERR_DEPS_INSTALL" --error && exit 1 echo_debug "Termina correctamente" # DEBUG zenity --title "$TITLE" --text "$PROMPT_END_SUCCESS" --info elif [ "$MENU" = "term" ] ; then term_prompt info "$PROMPT_WELCOME" read -r NULL ! 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_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 info "$PROMPT_DEPS_INSTALL" && echo install_certs "$SAVE_FILE" [ "$?" != "0" ] && term_prompt error "$PROMPT_ERR_DEPS_INSTALL" && exit 1 term_prompt info "$PROMPT_END_SUCCESS" && echo fi