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
This commit is contained in:
2025-08-25 09:56:44 +01:00
parent 0f91b9ccb9
commit dda1ca2c8b

104
skm.sh Normal file
View File

@@ -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)"