#!/bin/sh # ClearKey CLI installer # Usage: curl -sSL https://verifylinkinfra.com/install.sh | bash # # Environment variables: # CLEARKEY_VERSION - specific version to install (default: latest) # CLEARKEY_DIR - install directory (default: /usr/local/bin) set -e REPO="VerifyLinkInfra-cloud/clearkey" INSTALL_DIR="${CLEARKEY_DIR:-/usr/local/bin}" BINARY="clearkey" # Detect OS detect_os() { case "$(uname -s)" in Linux*) echo "linux" ;; Darwin*) echo "darwin" ;; MINGW*|MSYS*|CYGWIN*) echo "windows" ;; *) echo "unsupported" ;; esac } # Detect architecture detect_arch() { case "$(uname -m)" in x86_64|amd64) echo "amd64" ;; aarch64|arm64) echo "arm64" ;; armv7l) echo "armv7" ;; *) echo "unsupported" ;; esac } # Get latest version from GitHub releases get_latest_version() { if command -v curl > /dev/null 2>&1; then curl -sSL "https://api.github.com/repos/${REPO}/releases/latest" | grep '"tag_name"' | sed -E 's/.*"v?([^"]+)".*/\1/' elif command -v wget > /dev/null 2>&1; then wget -qO- "https://api.github.com/repos/${REPO}/releases/latest" | grep '"tag_name"' | sed -E 's/.*"v?([^"]+)".*/\1/' else echo "Error: curl or wget required" >&2 exit 1 fi } # Download file download() { if command -v curl > /dev/null 2>&1; then curl -sSL -o "$2" "$1" elif command -v wget > /dev/null 2>&1; then wget -qO "$2" "$1" fi } main() { echo "ClearKey CLI Installer" echo "=====================" echo "" OS=$(detect_os) ARCH=$(detect_arch) if [ "$OS" = "unsupported" ] || [ "$ARCH" = "unsupported" ]; then echo "Error: unsupported platform $(uname -s)/$(uname -m)" echo "Build from source: go install github.com/${REPO}/cmd/clearkey@latest" exit 1 fi VERSION="${CLEARKEY_VERSION:-$(get_latest_version)}" if [ -z "$VERSION" ]; then echo "Error: could not determine latest version." echo "Set CLEARKEY_VERSION manually or install via Go:" echo " go install github.com/${REPO}/cmd/clearkey@latest" exit 1 fi echo " Platform: ${OS}/${ARCH}" echo " Version: v${VERSION}" echo " Directory: ${INSTALL_DIR}" echo "" # Build download URL EXT="" if [ "$OS" = "windows" ]; then EXT=".exe" fi ARCHIVE="clearkey_${VERSION}_${OS}_${ARCH}.tar.gz" URL="https://github.com/${REPO}/releases/download/v${VERSION}/${ARCHIVE}" echo "Downloading ${ARCHIVE}..." TMPDIR=$(mktemp -d) download "$URL" "${TMPDIR}/${ARCHIVE}" echo "Extracting..." tar -xzf "${TMPDIR}/${ARCHIVE}" -C "${TMPDIR}" echo "Installing to ${INSTALL_DIR}..." if [ -w "$INSTALL_DIR" ]; then mv "${TMPDIR}/${BINARY}${EXT}" "${INSTALL_DIR}/${BINARY}${EXT}" else echo " (requires sudo)" sudo mv "${TMPDIR}/${BINARY}${EXT}" "${INSTALL_DIR}/${BINARY}${EXT}" fi chmod +x "${INSTALL_DIR}/${BINARY}${EXT}" # Cleanup rm -rf "$TMPDIR" echo "" echo "ClearKey CLI v${VERSION} installed successfully!" echo "" echo " Run 'clearkey version' to verify." echo " Run 'clearkey --help' to get started." echo "" } main