Skip to content

Commit

Permalink
Update installation and readme
Browse files Browse the repository at this point in the history
  • Loading branch information
jklaiber committed Feb 20, 2024
1 parent ed50b4f commit e2fe363
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 93 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,22 @@ Jumper is a simple and fast cli ssh manager. The goal was to reuse some ideas li

## Installation

### With Homebrew
You can use the following command to install Jumper to your system:
```
brew install jklaiber/tap/jumper
```

### With curl

You can use the following command to install Jumper to your system:
```
sh -c "$(curl -fsSL https://raw.githubusercontent.com/jklaiber/jumper/main/install/install.sh)"
```

### Manually
You can also download the latest release from the [release page](https://github.com/jklaiber/jumper/releases) and install it manually.

## Usage
The tool can be used to connect over ssh to the saved hosts in the inventory.

Expand Down
174 changes: 81 additions & 93 deletions install/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,8 @@
# -f, -y, --force, --yes
# Skip the confirmation prompt during installation
#
# -c, --configuration-dir
# Override the bin installation directory
#
# Example:
# sh install.sh -i ens2 -y
# sh install.sh -y

set -eu
printf '\n'
Expand Down Expand Up @@ -77,125 +74,116 @@ confirm() {
fi
}

detect_platform() {
if has uname; then
PLATFORM="$(uname -s | tr '[:upper:]' '[:lower:]')"
elif has os; then
PLATFORM="$(os | tr '[:upper:]' '[:lower:]')"
detect_platform_package_manager() {
if [ -f /etc/os-release ]; then
. /etc/os-release
case $ID in
debian|ubuntu) PACKAGE_MANAGER="apt";;
fedora|centos|rhel) PACKAGE_MANAGER="rpm";;
alpine) PACKAGE_MANAGER="apk";;
*) error "Unsupported OS for this installation script"; exit 1;;
esac
else
error 'Unable to detect platform'
error 'Unable to detect OS or package manager'
exit 1
fi
}

detect_arch() {
if has uname; then
ARCH="$(uname -m | tr '[:upper:]' '[:lower:]')"
elif has arch; then
ARCH="$(arch | tr '[:upper:]' '[:lower:]')"
else
error 'Unable to detect architecture'
exit 1
fi
if [ "$ARCH" = "x86_64" ]; then
ARCH='amd64'
fi
ARCH=$(uname -m)
case $ARCH in
x86_64) ARCH="amd64";;
armv7l|armv6l) ARCH="arm";;
aarch64) ARCH="arm64";;
*) error "Unsupported architecture: $ARCH"; exit 1;;
esac
}

remove_old_binary() {
local path="${HOME}/.local/bin/jumper"
if test -f ${path}
then
info "Removing old jumper binary..."
rm ${path}
completed "Old jumper binary is removed"
fetch_latest_version() {
VERSION=$(curl -s https://api.github.com/repos/jklaiber/jumper/releases/latest | grep 'tag_name' | cut -d\" -f4)
if [ -z "$VERSION" ]; then
error "Unable to fetch latest version"
exit 1
fi
# Strip the 'v' prefix from version tag if present
VERSION=${VERSION#v}
}

install_binary () {
info "Install jumper binary..."
printf '\n'
download_and_install() {
local base_url="https://github.com/jklaiber/jumper/releases/download/v${VERSION}"
local package_format
local package_name="jumper_${VERSION}_linux_${ARCH}"

$(curl -s -H "Accept: application/vnd.github.v3+json" https://api.github.com/repos/jklaiber/jumper/releases \
| grep "browser_download_url" \
| grep "$PLATFORM-$ARCH.tar.gz" \
| head -n 1 \
| cut -d : -f 2,3 \
| tr -d \" \
| wget -O ${HOME}/.local/bin/jumper.tar.gz -qi -)
cd ${HOME}/.local/bin
tar xfvz jumper.tar.gz
rm -f jumper.tar.gz
printf '\n'
completed "Jumper binary installed"
}
case $PACKAGE_MANAGER in
apt) package_format=".deb";;
rpm) package_format=".rpm";;
apk) package_format=".apk";;
esac

install() {
printf '\n'
install_binary
}
local url="${base_url}/${package_name}${package_format}"

print_banner() {
printf '%s\n' \
' _ '\
' (_) '\
' _ _ _ _ __ ___ _ __ ___ _ __ '\
' | | | | | _ _ \| _ \ / _ \ __|'\
' | | |_| | | | | | | |_) | __/ | '\
' | |\__ _|_| |_| |_| __/ \___|_| '\
' _/ | | | '\
' |__/ |_| '
printf '\n'
}
temp_dir=$(mktemp -d)
cd "$temp_dir"

start_message() {
detect_platform
detect_arch
info "${BOLD}Detected platform${NO_COLOR}: ${GREEN}${PLATFORM}${NO_COLOR}"
info "${BOLD}Detected architecture${NO_COLOR}: ${GREEN}${ARCH}${NO_COLOR}"
printf '\n'
confirm "Install Jumper SSH CLI Manager?"
if has jumper; then
info "Jumper is already installed, upgrading..."
remove_old_binary
install_binary
printf '\n'
completed "Jumper is upgraded"
else
install
printf '\n'
completed "Jumper is installed"
info "Downloading ${package_name}${package_format}..."
if ! curl -LO "$url"; then
error "Failed to download ${package_name}${package_format}"
exit 1
fi
}

finish_message() {
URL="https://github.com/jklaiber/jumper"
info "Installing ${package_name}${package_format}..."
case $PACKAGE_MANAGER in
apt)
sudo apt install "./${package_name}${package_format}" -y
;;
rpm)
sudo rpm -i "${package_name}${package_format}"
;;
apk)
sudo apk add --allow-untrusted "${package_name}${package_format}"
;;
esac

cd - > /dev/null
rm -rf "$temp_dir"

printf '\n'
info "Please follow the steps to use Jumper on your machine:
${BOLD}${UNDERLINE}Setup${NO_COLOR}
Jumper will force to setup the application before the first use.
Please follow the instructions to setup the application.
${BOLD}${UNDERLINE}Documentation${NO_COLOR}
To check out the documentation go to:
${UNDERLINE}${BLUE}${URL}${NO_COLOR}
"
completed "Jumper installed successfully."
}

while getopts "hf" option; do
while getopts "hfyV" option; do
case $option in
h)
help
exit;;
f)
f|y)
FORCE=1
;;
V)
VERBOSE=1
;;
?)
error "Invalid option: -$OPTARG"
exit;;
esac
done

print_banner() {
printf '%s\n' \
' _ '\
' (_) '\
' _ _ _ _ __ ___ _ __ ___ _ __ '\
' | | | | | _ _ \| _ \ / _ \ __|'\
' | | |_| | | | | | | |_) | __/ | '\
' | |\__ _|_| |_| |_| __/ \___|_| '\
' _/ | | | '\
' |__/ |_| '
printf '\n'
}

print_banner
start_message
finish_message
detect_platform_package_manager
detect_arch
fetch_latest_version
confirm "Install Jumper SSH CLI Manager?"
download_and_install
finish_message

0 comments on commit e2fe363

Please sign in to comment.