From dda1ca2c8b3ff567d8171def50ffb00b85fc6f09 Mon Sep 17 00:00:00 2001 From: Ade Thompson Date: Mon, 25 Aug 2025 09:56:44 +0100 Subject: [PATCH] added SKM installer SKM is a simple and powerful SSH Keys Manager. It helps you to manage your multiple SSH keys easily! https://github.com/TimothyYe/skm --- skm.sh | 104 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 skm.sh diff --git a/skm.sh b/skm.sh new file mode 100644 index 0000000..8be96e2 --- /dev/null +++ b/skm.sh @@ -0,0 +1,104 @@ +#!/usr/bin/env bash +set -euo pipefail + +# ── Config ────────────────────────────────────────────── +REPO="TimothyYe/skm" +VERSION="${VERSION:-latest}" # set VERSION=v0.8.7 to pin +PREFIX="$HOME/.local/bin" # non-sudo install path + +# ── Helpers ───────────────────────────────────────────── +need() { command -v "$1" >/dev/null 2>&1 || { echo "Missing dependency: $1"; exit 1; }; } +tmpdir() { mktemp -d 2>/dev/null || mktemp -d -t skm; } +cleanup() { [[ -n "${WORKDIR:-}" && -d "$WORKDIR" ]] && rm -rf "$WORKDIR"; } +trap cleanup EXIT + +detect_platform() { + local uos uarch + uos="$(uname -s | tr '[:upper:]' '[:lower:]')" + uarch="$(uname -m)" + + case "$uos" in + linux) OS="linux" ;; + darwin) OS="darwin" ;; + *) echo "Unsupported OS: $uos"; exit 1 ;; + esac + + case "$uarch" in + x86_64|amd64) ARCH="amd64" ;; + aarch64|arm64) ARCH="arm64" ;; + i386|i686) ARCH="386" ;; + armv7l|armv7|armv6l|armv6|armv5l|arm) ARCH="arm" ;; + *) echo "Unsupported architecture: $uarch"; exit 1 ;; + esac +} + +get_latest_tag() { + need curl + curl -fsSL "https://api.github.com/repos/${REPO}/releases/latest" \ + | grep -m1 '"tag_name":' \ + | sed -E 's/.*"tag_name": *"([^"]+)".*/\1/' +} + +build_url() { + local tag="$1" os="$2" arch="$3" ver="${tag#v}" + echo "https://github.com/${REPO}/releases/download/${tag}/skm_${ver}_${os}_${arch}.tar.gz" +} + +resolve_url() { + local tag="$1" os="$2" arch="$3" + local url alt + url="$(build_url "$tag" "$os" "$arch")" + if curl -fsI "$url" >/dev/null 2>&1; then + echo "$url"; return 0 + fi + if [[ "$os" == "linux" && "$arch" == "arm64" ]]; then + alt="$(build_url "$tag" "$os" "arm")" + if curl -fsI "$alt" >/dev/null 2>&1; then + echo "$alt"; return 0 + fi + fi + echo "No release asset found for ${os}/${arch} (tag ${tag})." >&2 + exit 1 +} + +# ── Main ──────────────────────────────────────────────── +echo "→ Detecting platform..." +detect_platform +echo " OS=${OS} ARCH=${ARCH}" + +if [[ "$VERSION" == "latest" ]]; then + echo "→ Fetching latest SKM release..." + TAG="$(get_latest_tag)" +else + TAG="$VERSION" +fi +echo " Using release: $TAG" + +URL="$(resolve_url "$TAG" "$OS" "$ARCH")" +echo "→ Downloading: $URL" + +WORKDIR="$(tmpdir)" +cd "$WORKDIR" +FILENAME="${URL##*/}" +curl -fL --progress-bar -o "$FILENAME" "$URL" + +echo "→ Extracting..." +tar -xzf "$FILENAME" + +BIN="$(find . -maxdepth 2 -type f -name skm | head -n1 || true)" +[[ -n "$BIN" && -f "$BIN" ]] || { echo "Could not find skm binary"; exit 1; } + +mkdir -p "$PREFIX" +mv "$BIN" "$PREFIX/skm" +chmod +x "$PREFIX/skm" + +echo "→ Installed at $PREFIX/skm" + +# Add to PATH if not already +if ! echo "$PATH" | grep -q "$HOME/.local/bin"; then + echo "⚠️ $HOME/.local/bin is not in your PATH." + echo " Add this to your shell config (e.g. ~/.bashrc or ~/.zshrc):" + echo " export PATH=\"\$HOME/.local/bin:\$PATH\"" +fi + +echo "✅ Done. Version: $($PREFIX/skm --version)" \ No newline at end of file