Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
alexaandrov committed Oct 17, 2023
1 parent 2d707d9 commit db6c8a4
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 34 deletions.
64 changes: 31 additions & 33 deletions install.sh
Original file line number Diff line number Diff line change
@@ -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 "$@"
2 changes: 1 addition & 1 deletion stitchocker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit db6c8a4

Please sign in to comment.