Skip to content

Commit

Permalink
Add run and download install options
Browse files Browse the repository at this point in the history
  • Loading branch information
ekzhang committed Jan 11, 2024
1 parent 7393800 commit 52a47a6
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 7 deletions.
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,17 @@ curl -sSf https://sshx.io/get | sh
Supports Linux and MacOS, on both x86_64 and arm64 architectures. The
precompiled Linux binaries are statically linked.

If you just want to try it out without installing, use:

```shell
curl -sSf https://sshx.io/get | sh -s run
```

Inspect the script for additional options.

### CI/CD

You can also use sshx in continuous integration workflows to help debug tricky
You can run sshx in continuous integration workflows to help debug tricky
issues, like in GitHub Actions.

```yaml
Expand All @@ -44,7 +52,7 @@ jobs:

# ... other steps ...

- run: curl -sSf https://sshx.io/get | sh && sshx
- run: curl -sSf https://sshx.io/get | sh -s run
# ^
# └ This will open a remote terminal session and print the URL. It
# should take under a second.
Expand Down
37 changes: 32 additions & 5 deletions static/get
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
# It's meant to be as simple as possible, so if you're not happy hardcoding a
# `curl | sh` pipe in your application, you can just download the binary
# directly with the appropriate URL for your architecture.
#
# If you'd like to run it without installing to /usr/local/bin, use `sh -s run`.
# To download to the current directory, use `sh -s download`.

set +e

Expand All @@ -21,7 +24,6 @@ case "$(uname -m)" in
esac

url="https://s3.amazonaws.com/sshx/sshx-${arch}${suffix}.tar.gz"
temp=$(mktemp)

if [ -z "$NO_COLOR" ]; then
ansi_reset="\033[0m"
Expand All @@ -30,6 +32,26 @@ if [ -z "$NO_COLOR" ]; then
ansi_underline="\033[4m"
fi

cmd=${1:-install}
temp=$(mktemp)

case $cmd in
"run")
path=$(mktemp -d)
will_run=1
;;
"download")
path=$(pwd)
;;
"install")
path=/usr/local/bin
;;
*)
printf "${ansi_error}Error: Invalid command. Please use 'run', 'download', or 'install'.\n"
exit 1
;;
esac

printf "${ansi_reset}${ansi_info}↯ Downloading sshx from ${ansi_underline}%s${ansi_reset}\n" "$url"
http_code=$(curl "$url" -o "$temp" -w "%{http_code}")
if [ "$http_code" -lt 200 ] || [ "$http_code" -gt 299 ]; then
Expand All @@ -39,11 +61,16 @@ if [ "$http_code" -lt 200 ] || [ "$http_code" -gt 299 ]; then
exit 1
fi

printf "\n${ansi_reset}${ansi_info}↯ Adding sshx binary to ${ansi_underline}%s${ansi_reset}\n" "/usr/local/bin"
if [ "$(id -u)" -ne 0 ]; then
sudo tar xf "$temp" -C /usr/local/bin
printf "\n${ansi_reset}${ansi_info}↯ Adding sshx binary to ${ansi_underline}%s${ansi_reset}\n" "$path"
if [ "$(id -u)" -ne 0 ] && [ "$path" = "/usr/local/bin" ]; then
sudo tar xf "$temp" -C "$path" || exit 1
else
tar xf "$temp" -C /usr/local/bin
tar xf "$temp" -C "$path" || exit 1
fi

printf "\n${ansi_reset}${ansi_info}↯ Done! You can now run sshx.${ansi_reset}\n"

if [ -n "$will_run" ]; then
"$path/sshx"
rm -f "$path/sshx"
fi

0 comments on commit 52a47a6

Please sign in to comment.