diff --git a/install.sh b/install.sh index 918e7f1..e94d1a7 100755 --- a/install.sh +++ b/install.sh @@ -1,57 +1,55 @@ #!/bin/bash -function scr_install -{ - set -e +install() { + set -e - # Set variables + # Set variables + + local destination_path="/tmp" + local bin_path="/usr/local/bin" + local stitchocker_stable_release="1.2.1" + local stitchoker_uri="https://raw.githubusercontent.com/alexaandrov/stitchocker/$stitchocker_stable_release/stitchocker.sh" + local stitchocker_name="stitchocker" + local stitchocker_tmp_path="$destination_path/$stitchocker_name.sh" + local stitchocker_bin_path="$bin_path/$stitchocker_name" - local destination_path="/tmp" - local bin_path="/usr/local/bin" - local stitchocker_stable_release="1.2.0" - local stitchoker_uri="https://raw.githubusercontent.com/alexaandrov/stitchocker/$stitchocker_stable_release/stitchocker.sh" - local stitchocker_name="stitchocker" - local stitchocker_tmp_path="$destination_path/$stitchocker_name.sh" - local stitchocker_bin_path="$bin_path/$stitchocker_name" + info "Downloading $stitchocker_name $stitchocker_stable_release" - scr_info "Downloading $stitchocker_name $stitchocker_stable_release" + local http_code=$(curl -H 'Cache-Control: no-cache' --url $stitchoker_uri --output $stitchocker_tmp_path --write-out "%{http_code}") + echo - echo - local http_code=$(curl -H 'Cache-Control: no-cache' --url $stitchoker_uri --output $stitchocker_tmp_path --write-out "%{http_code}") + if [[ $http_code != 200 ]]; then + error "An error occurred while downloading the $stitchocker_name. Try again later or manually download the $stitchocker_name." + fi - if [[ $http_code != 200 ]]; then - scr_error "An error occurred while downloading the $stitchocker_name. Try again later or manually download the $stitchocker_name." - fi - echo + info "Installing $stitchocker_name" - scr_info "Installing $stitchocker_name" + if [[ -f $stitchocker_bin_path ]]; then + info "Removing previous version" + rm -f $stitchocker_bin_path + fi - if [[ -f $stitchocker_bin_path ]]; then - scr_info "Removing previous version" - rm -f $stitchocker_bin_path - fi + mv $stitchocker_tmp_path $stitchocker_bin_path - mv $stitchocker_tmp_path $stitchocker_bin_path + chmod +x $stitchocker_bin_path - chmod +x $stitchocker_bin_path - - scr_info "Installation complete!" - scr_info "Run $stitchocker_name -h to see the help" - echo - scr_info "Your $($stitchocker_name --version)" + info "Installation complete!" + info "Run $stitchocker_name -h to see the help" + info "Your $($stitchocker_name --version)" } -function scr_info { +info() { local green=$(tput setaf 2) local reset=$(tput sgr0) echo -e "${green}$@${reset}" + echo } -function scr_error { +error() { local red=$(tput setaf 1) local reset=$(tput sgr0) echo >&2 -e "${red}$@${reset}" exit 1 } -scr_install "$@" +install "$@" diff --git a/stitchocker.sh b/stitchocker.sh index c4fc82f..2ba3fcb 100755 --- a/stitchocker.sh +++ b/stitchocker.sh @@ -10,7 +10,7 @@ stitchocker() { local self="stitchocker" - local version="1.2.0" + local version="1.2.1" local version_info="Stitchocker version $version" local help=" Usage: