diff options
author | Jesus <heckyel@hyperbola.info> | 2025-05-18 18:59:19 -0500 |
---|---|---|
committer | Jesus <heckyel@hyperbola.info> | 2025-05-18 18:59:19 -0500 |
commit | 580f139ba229684c93bae006fd08863a8ecf1106 (patch) | |
tree | e6a08dfc044e965f520d66ace51af8fb1f431555 /hyperterm/core/update.sh | |
parent | 6fff4075d94a87997dba4539446ef696a36278cd (diff) | |
download | hyperterm-580f139ba229684c93bae006fd08863a8ecf1106.tar.lz hyperterm-580f139ba229684c93bae006fd08863a8ecf1106.tar.xz hyperterm-580f139ba229684c93bae006fd08863a8ecf1106.zip |
only curl
Diffstat (limited to 'hyperterm/core/update.sh')
-rw-r--r-- | hyperterm/core/update.sh | 244 |
1 files changed, 128 insertions, 116 deletions
diff --git a/hyperterm/core/update.sh b/hyperterm/core/update.sh index 578ab76..ade74e3 100644 --- a/hyperterm/core/update.sh +++ b/hyperterm/core/update.sh @@ -1,151 +1,163 @@ #!/bin/bash # shellcheck source=/dev/null -#------------------ -# Update functions -#------------------ +#---------------------------- +# Check if a command exists +#---------------------------- function _which() { command -v "$1" &> /dev/null } -# Check URL's -# --------------------- +#---------------------------- +# Check if a URL is reachable +#---------------------------- function _url_exists() { - curl --output /dev/null 2>&1 -s -w "%{http_code}\n" "$1" + curl --output /dev/null --silent --head --write-out "%{http_code}" "$1" } +#------------------ +# Set working URLs +#------------------ function _urls() { URL_1="https://git.fridu.us/heckyel/hyperterm" URL_2="https://c.fridu.us/software/hyperterm.git" + if [ "$(_url_exists "$URL_1")" -eq 200 ]; then URL="$URL_1" RAW="$URL_1/raw/branch/master" elif [ "$(_url_exists "$URL_2")" -eq 200 ]; then URL="$URL_2" RAW="$URL_2/plain" + else + msg_err "El repositorio no está disponible o no hay conexión a Internet." \ + "The repository is unavailable or there's no internet connection." + exit 1 fi } -# ---------------------- - -function ifexists_custom() { - _urls "$@" +#---------------------------- +# Download file with curl +#---------------------------- +function download_file() { + local remote_path=$1 + local local_path=$2 + mkdir -p "$(dirname "$local_path")" + curl -Ls "$RAW/$remote_path" -o "$local_path" +} - if [ ! -e "$HOME/.hyperterm/_custom.sh" ]; then - case $1 in - wget) wget "$RAW/hyperterm/_custom.sh" -O "$HOME/.hyperterm/_custom.sh" ;; - curl) curl "$RAW/hyperterm/_custom.sh" -o "$HOME/.hyperterm/_custom.sh" ;; - git) cp -v /tmp/hyperterm/hyperterm/_custom.sh "$HOME/.hyperterm/" ;; - esac +#---------------------------- +# Download _custom.sh if missing +#---------------------------- +function ifexists_custom() { + _urls + local custom_path="$HOME/.hyperterm/_custom.sh" + if [ ! -e "$custom_path" ]; then + download_file "hyperterm/_custom.sh" "$custom_path" fi } -function updbashrc() { +#---------------------------- +# Show progress bar +#---------------------------- +function show_progress() { + case $1 in + 1) printf '%s\r' "##### (33%)" ;; + 2) printf '%s\r' "############# (66%)" ;; + 3) printf '%s\n' "####################### (100%) done!" ;; + esac +} - _urls "$@" +#---------------------------- +# Update HyperTerm environment +#---------------------------- +function updbashrc() { + _urls - # data integration - if _which wget; then - wget -nv "$RAW/hyperterm/hyperterm.sha512" -O "$HOME/.hyperterm/hyperterm.sha512" &> /dev/null - ifexists_custom wget &> /dev/null - elif _which curl; then - curl "$RAW/hyperterm/hyperterm.sha512" -o "$HOME/.hyperterm/hyperterm.sha512" &> /dev/null - ifexists_custom curl &> /dev/null - fi + # Step 1: Download checksum and _custom.sh + download_file "hyperterm/hyperterm.sha512" "$HOME/.hyperterm/hyperterm.sha512" + ifexists_custom - # checksum of data verification + # Step 2: Verify checksum (cd "$HOME/.hyperterm/" && sha512sum -c hyperterm.sha512 &> /dev/null) - _interger=$? - - if _which git; then - if [[ "$_interger" -eq 0 ]]; then - # Import colors - _colors_bash "$@" - printf '%b' "${BOLD}${CYAN}" - printf '%s\n' ' __ __ ______ ' - printf '%s\n' ' / / / /_ ______ ___ ____/_ __/__ _________ ___ ' - printf '%s\n' ' / /_/ / / / / __ \/ _ \/ ___// / / _ \/ ___/ __ `__ \ ' - printf '%s\n' ' / __ / /_/ / /_/ / __/ / / / / __/ / / / / / / / ' - printf '%s\n' ' /_/ /_/\__, / .___/\___/_/ /_/ \___/_/ /_/ /_/ /_/ ' - printf '%s\n' ' /____/_/ ' - printf '%s\n' ' ' - printf '%b' "${BOLD}${GREY}" - msg "¡Hurra! HyperTerm se ha actualizado y/o está en la versión actual." \ - "Hooray! HyperTerm has been updated and/or is at the current version." - msg "Puede reportarnos errores en https://todo.sr.ht/~heckyel/hyperterm" \ - "You can report errors issues in https://todo.sr.ht/~heckyel/hyperterm" - msg "Consigue tu copia de HyperTerm en: https://c.fridu.us/software/hyperterm.git" \ - "Get your HyperTerm copy on: https://c.fridu.us/software/hyperterm.git" - printf '%b\n' "$RESET" - else - case $(_url_exists "$URL") in - 200) - # clone '--depth=1' not support cgit - msg "Usando: $URL" \ - "Using: $URL" - (git clone "$URL" /tmp/hyperterm/ --depth=1 &> /dev/null) - printf '%s\r' "##### (33%)" - sleep 1 - # core - for i in autocomplete.sh colors.sh git.sh languages.sh status.sh update.sh; do - install -m644 /tmp/hyperterm/hyperterm/core/$i "$HOME/.hyperterm/core/$i" - done - # themes - for i in default.sh joy.sh light_theme.sh minterm.sh pure.sh simple.sh special.sh; do - install -m644 /tmp/hyperterm/hyperterm/themes/$i "$HOME/.hyperterm/themes/$i" - done - # tools - (cp -f /tmp/hyperterm/hyperterm/tools/* "$HOME/.hyperterm/tools/" &> /dev/null) - - for i in hyperterm.sh hyperterm.sha512; do - install -m644 /tmp/hyperterm/hyperterm/$i "$HOME/.hyperterm/$i" - done - (cp -f /tmp/hyperterm/.bash_profile "$HOME/" &> /dev/null) - printf '%s\r' "############# (66%)" - (ifexists_custom git &> /dev/null) - sleep 1 - (rm -fr /tmp/hyperterm/) - printf '%s\n' "####################### (100%) done!" - source "$HOME/.bashrc" ;; - *) - msg_err "El repo esta deshabilitado o no hay conexión a Internet" \ - "The repo is disabled or connection failed" - return 1 ;; - esac - fi + local _interger=$? + + if [[ "$_interger" -eq 0 ]]; then + # Load colors and print banner + _colors_bash "$@" + printf '%b' "${BOLD}${CYAN}" + printf '%s\n' ' __ __ ______ ' + printf '%s\n' ' / / / /_ ______ ___ ____/_ __/__ _________ ___ ' + printf '%s\n' ' / /_/ / / / / __ \/ _ \/ ___// / / _ \/ ___/ __ `__ \ ' + printf '%s\n' ' / __ / /_/ / /_/ / __/ / / / / __/ / / / / / / / ' + printf '%s\n' ' /_/ /_/\__, / .___/\___/_/ /_/ \___/_/ /_/ /_/ /_/ ' + printf '%s\n' ' /____/_/ ' + printf '%s\n' ' ' + printf '%b' "${BOLD}${GREY}" + msg "✔️ HyperTerm se ha actualizado y/o está en la versión actual." \ + "✔️ HyperTerm has been updated and/or is at the current version." + msg "Puede reportar errores en https://todo.sr.ht/~heckyel/hyperterm" \ + "You can report issues at https://todo.sr.ht/~heckyel/hyperterm" + msg "Obtén tu copia en: https://c.fridu.us/software/hyperterm.git" \ + "Get your copy at: https://c.fridu.us/software/hyperterm.git" + printf '%b\n' "$RESET" else - msg_err "No hay curl y git. Por favor, instale los programas para actualizar HyperTerm" \ - "I couldn't find not curl and git. Please, install the programs to update HyperTerm" - return 1 + msg "Fallo de checksum. Re-descargando archivos desde: $URL" \ + "Checksum failed. Re-downloading files from: $URL" + show_progress 1 + sleep 1 + + # Step 3: Core files + for f in autocomplete.sh colors.sh git.sh languages.sh status.sh update.sh; do + download_file "hyperterm/core/$f" "$HOME/.hyperterm/core/$f" + done + + # Step 4: Themes + for f in default.sh joy.sh light_theme.sh minterm.sh pure.sh simple.sh special.sh; do + download_file "hyperterm/themes/$f" "$HOME/.hyperterm/themes/$f" + done + + show_progress 2 + sleep 1 + + # Step 5: Tools + for f in aliases.sh compress.sh export.sh listuser.sh network.sh proxy.sh rar2zip.sh ruby.sh ssh-agent.sh sysinfo.sh vconverter.sh virtualenv.sh; do + download_file "hyperterm/tools/$f" "$HOME/.hyperterm/tools/$f" + done + + # Step 6: Main files + download_file "hyperterm/hyperterm.sh" "$HOME/.hyperterm/hyperterm.sh" + download_file "hyperterm/hyperterm.sha512" "$HOME/.hyperterm/hyperterm.sha512" + download_file ".bash_profile" "$HOME/.bash_profile" + + ifexists_custom + show_progress 3 + _colors_bash "$@" + source "$HOME/.bashrc" fi } +#------------------------------------ +# Overwrite _custom.sh interactively +#------------------------------------ function updbashrc_custom() { - _urls "$@" - case $(_url_exists "$URL") in - 200) - while true - do - function _copy_c() { - if _which wget; then - wget "$RAW/hyperterm/_custom.sh" -O "$HOME/.hyperterm/_custom.sh"; source "$HOME/.bashrc" - elif _which curl; then - curl "$RAW/hyperterm/_custom.sh" -o "$HOME/.hyperterm/_custom.sh"; source "$HOME/.bashrc" - fi - } - question=$(msg "¿Estás seguro de sobre-escribir _custom.sh? [s/N]: " \ - "Are you sure to overwrite _custom.sh? [y/N]: ") - read -r -p "$question" input - case $input in - [sS]|[yY]) _copy_c "$@"; break ;; - [nN]|"") break ;; - *) msg "Por favor responde sí o no" \ - "Please answer yes or no.";; - esac - done ;; - *) - msg_err "El repo esta deshabilitado o no hay conexión a Internet" \ - "The repo is disabled or connection failed" - return 1 - ;; - esac + _urls + if [ "$(_url_exists "$URL")" -eq 200 ]; then + while true; do + question=$(msg "¿Estás seguro de sobre-escribir _custom.sh? [s/N]: " \ + "Are you sure to overwrite _custom.sh? [y/N]: ") + read -r -p "$question" input + case "$input" in + [yY]|[sS]) + download_file "hyperterm/_custom.sh" "$HOME/.hyperterm/_custom.sh" + source "$HOME/.bashrc" + break ;; + [nN]|"") break ;; + *) msg "Por favor responde sí o no." \ + "Please answer yes or no." ;; + esac + done + else + msg_err "El repositorio no está disponible o no hay conexión a Internet." \ + "The repository is unavailable or there's no internet connection." + return 1 + fi } |