From cfb694761f8ce5c02c6d23e5f1ee52c00de1bea2 Mon Sep 17 00:00:00 2001 From: tavo-wasd Date: Sat, 29 Jun 2024 08:46:42 -0600 Subject: [PATCH] pass env vars, shellcheck directives --- 01-utils.sh | 25 ++++++------------------- 02-language.sh | 2 ++ 03-install.sh | 2 ++ 04-main.sh | 15 ++++++++++++--- Makefile | 2 +- 5 files changed, 23 insertions(+), 23 deletions(-) diff --git a/01-utils.sh b/01-utils.sh index 908ea05..3a7cc62 100644 --- a/01-utils.sh +++ b/01-utils.sh @@ -7,6 +7,8 @@ echo_debug() { # DEBUG } # DEBUG urlencode() { + # This is a false positive + # shellcheck disable=SC1083 ENCODEDURL="$(curl -Gs -w %{url_effective} --data-urlencode @- ./ ||: )" printf '%s' "$ENCODEDURL" | sed 's/%0[aA]$//;s/^.*[?]//' } @@ -43,6 +45,8 @@ get_archive() { } set_version() { + # This is a shellcheck limitation + # shellcheck disable=SC1090 for os in /etc/os-release /usr/lib/os-release; do [ -f $os ] && . $os && break done @@ -72,25 +76,6 @@ set_version() { esac } -firmador_libre() { -FIRMADOR="https://firmador.libre.cr/firmador.jar" -DIR="$HOME/.local/share/firmador" -[ "$ID" = "macos" ] && DIR="$HOME/.local/share/firmador" - -mkdir -p "$DIR" -(cd "$DIR" && curl -O "$FIRMADOR") -FIRMADOR="$DIR/firmador.jar" - -printf '[Desktop Entry] -Name=Firmador -Comment=Herramienta para firmar documentos -Category=Utility -Exec=java -jar %s -Icon=%s/.local/share/firmador/firmador.png -Terminal=false -Type=Application' "$FIRMADOR" "$HOME" > ~/.local/share/applications/firmador.desktop -} - set_menu() { if [ -z "$MENU" ] ; then command -v zenity > /dev/null && MENU="zenity" && return 0 @@ -118,6 +103,8 @@ if [ "$MENU" = "zenity" ] ; then zenity --title "$TITLE" --password elif [ "$MENU" = "term" ] ; then + # nil (or whatever variable) must be set for portability + # shellcheck disable=SC2034 [ "$MODE" = "info" ] && printf '\n\033[1m\033[34m=== %s ===\033[0m\n%s ENTER' "$TITLE" "$PROMPT" >/dev/stdin && read -r nil diff --git a/02-language.sh b/02-language.sh index e18c84a..2e57aca 100644 --- a/02-language.sh +++ b/02-language.sh @@ -1,4 +1,6 @@ #!/bin/sh +# False positive +# shellcheck disable=SC2034 set_lang() { # See: /var/lib/AccountsService/users/ diff --git a/03-install.sh b/03-install.sh index c31d2f3..54a7dc9 100644 --- a/03-install.sh +++ b/03-install.sh @@ -25,6 +25,8 @@ PACKAGE="${PACKAGE##*/}" tsudo cp -p "$PACKAGE_DIR"/usr/lib/x64-athena/libASEP11.so /usr/lib/x86_64-linux-gnu/ echo_debug "Symlinks y componentes..." # DEBUG +# This must not be expanded +# shellcheck disable=SC2016 tsudo sh -c ' # --- Certificados --- for file in /usr/local/share/ca-certificates/*.crt ; do openssl x509 -inform DER -in "$file" -out "$file.tmp" 2> /dev/null ; done diff --git a/04-main.sh b/04-main.sh index 411debb..7412205 100644 --- a/04-main.sh +++ b/04-main.sh @@ -16,7 +16,8 @@ if ! command -v curl > /dev/null ; then exit 1 fi -SERIAL="$(menu entry "$PROMPT_SERIAL")" +SERIAL="${SERIAL:=$(menu entry "$PROMPT_SERIAL")}" + if [ -z "$SERIAL" ] ; then menu error "$PROMPT_ERR_SERIAL" exit 1 @@ -61,9 +62,12 @@ elif [ "$MENU" = "term" ] ; then fi +# This way is better in this case +# shellcheck disable=SC2009 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 @@ -71,7 +75,8 @@ if [ -n "$ACTIVE" ] ; then exit 1 fi -SUDO_PASSWORD="$(menu pass "$PROMPT_PASS_DEPS_INSTALL")" +SUDO_PASSWORD="${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 @@ -84,15 +89,19 @@ if [ "$MENU" = "zenity" ] ; then 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 # DEBUG + # Ignore as this is needed for this "workaround" + # shellcheck disable=SC2181 if [ "$?" != "0" ] ; then menu error "$PROMPT_ERR_DEPS_INSTALL" exit 1 fi + elif [ "$MENU" = "term" ] ; then menu info "$PROMPT_DEPS_INSTALL" && echo ! install_certs && menu error "$PROMPT_ERR_DEPS_INSTALL" && exit 1 + fi -menu info "$PROMPT_END_SUCCESS" +menu info "$PROMPT_END_SUCCESS\n" exit 0 diff --git a/Makefile b/Makefile index 500abb6..f152a1a 100644 --- a/Makefile +++ b/Makefile @@ -4,7 +4,7 @@ all: $(SCRIPT) $(SCRIPT): $(wildcard [0-9][0-9]-*.sh) printf '#!/bin/sh\n' > $@ - for i in $? ; do cat $$i ; done | sed '/^ *#.*$$/d;/.*# *DEBUG/d' >> $@ + for i in $? ; do cat $$i ; done | sed '/^ *# shellcheck/! s/^ *#.*$$//g;/.*# *DEBUG/d' >> $@ debug: $(wildcard [0-9][0-9]-*.sh) printf '#!/bin/sh\n' > $@-$(SCRIPT)