diff --git a/installer/install.sh b/installer/install.sh index aab910e3..e943b7d6 100644 --- a/installer/install.sh +++ b/installer/install.sh @@ -9,7 +9,7 @@ ###################################################### set -o errexit -# set -o xtrace +set -o xtrace ################################################ # CONSTANTS ################################################ @@ -17,7 +17,7 @@ set -o errexit REPO="arturo" VERSION="full" -for cmd in $@; do +for cmd in "$@"; do case $cmd in --nightly|-n) REPO="nightly";; --mini|-m) VERSION="mini";; @@ -30,8 +30,10 @@ API_URL="https://api.github.com/repos/arturo-lang/${REPO}/releases" # HELPERS ################################################ +# shellcheck disable=SC2034 RED='\e[0;31m' GREEN='\e[1;32m' +# shellcheck disable=SC2034 BLUE='\e[0;34m' MAGENTA='\e[1;35m' CYAN='\e[1;36m' @@ -39,8 +41,7 @@ GRAY='\e[0;90m' CLEAR='\e[0m' printColorized() { - NC='\e[0m' - printf "${1}${2}${NC}" + printf "${1}${2}${CLEAR}" } panic() { @@ -126,7 +127,7 @@ cleanup_tmp_directory() { } command_exists(){ - type "$1" &> /dev/null + type "$1" > /dev/null 2>&1 } animate_progress(){ @@ -152,18 +153,18 @@ verifyOS(){ case "$OSTYPE" in linux*) currentOS="linux" ;; darwin*) currentOS="macos" ;; - cygwin*) currentOS="windows-msys2" ;; - msys*) currentOS="windows-msys2" ;; + cygwin*) currentOS="windows" ;; + msys*) currentOS="windows" ;; solaris*) currentOS="solaris" ;; freebsd*) currentOS="freebsd" ;; bsd*) currentOS="bsd" ;; *) - if [ `uname` = "Linux" ]; then + if [ "$(uname)" = "Linux" ]; then currentOS="linux" - elif [ `uname` = "FreeBSD" ]; then + elif [ "$(uname)" = "FreeBSD" ]; then currentOS="freebsd" else - currentOS="Unknown ($OSTYPE / `uname`)" + currentOS="Unknown ($OSTYPE / $(uname))" fi ;; esac @@ -174,15 +175,19 @@ verifyShell(){ case "$SHELL" in */bin/zsh) currentShell="zsh" ; + # shellcheck disable=SC2088 shellRcFile="~/.zshrc" ;; */bin/bash) currentShell="bash" ; + # shellcheck disable=SC2088 shellRcFile="~/.bashrc or ~/.profile" ;; */bin/sh) currentShell="sh" ; + # shellcheck disable=SC2088 shellRcFile="~/.profile" ;; *) currentShell="unrecognized" ; + # shellcheck disable=SC2088 shellRcFile="~/.profile" ;; esac @@ -223,7 +228,9 @@ download_arturo() { --output "$ARTURO_TMP_DIR/arturo.tar.gz" \ --silent \ --show-error +} +unpack_tar() { # This piece of code is using traditional option style due # to compatibility issues between `tar`'s versions. # Long versions are accepted for `GNU's tar`, and for others ones @@ -237,6 +244,13 @@ download_arturo() { tar -zxf "$ARTURO_TMP_DIR/arturo.tar.gz" -C $ARTURO_TMP_DIR } +unpack_zip() { + # It seems that `unzip` doesn't provide a long version of its options. + # + # -d: directory to which to extract files. + unzip "$ARTURO_TMP_DIR/arturo.zip" -d "$ARTURO_TMP_DIR" +} + install_arturo() { create_directory $HOME/.arturo/bin create_directory $HOME/.arturo/lib @@ -259,7 +273,7 @@ main() { verifyOS verifyShell - if [ "$currentOS" = "linux" ] || [ "$currentOS" = "macos" ] || [ "$currentOS" = "windows-msys2" ]; then + if [ "$currentOS" = "linux" ] || [ "$currentOS" = "macos" ]; then section "Checking prerequisites..." install_prerequisites @@ -267,6 +281,12 @@ main() { download_arturo section "Installing..." + if [ "$currentOS" = "linux" ]; then + unpack_tar + else + unpack_zip + fi + install_arturo section "Cleaning up..." @@ -277,6 +297,8 @@ main() { section "Done!" eecho "" showFooter + elif [ "$currentOS" = "windows" ]; then + panic "Cannot continue. Try to install via install.ps1"; else panic "Cannot continue. Unfortunately your OS is not supported by this auto-installer."; fi