diff --git a/README.md b/README.md index 411639a..98b7e11 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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. diff --git a/static/get b/static/get index 825907f..c556ea2 100644 --- a/static/get +++ b/static/get @@ -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 @@ -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" @@ -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 @@ -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