Files
at-container-registry/pkg/appview/public/static/install.sh

161 lines
4.2 KiB
Bash
Executable File

#!/bin/bash
# ATCR Credential Helper Installation Script
# Usage: curl -fsSL https://atcr.io/install.sh | bash
set -e
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Configuration
BINARY_NAME="docker-credential-atcr"
INSTALL_DIR="${INSTALL_DIR:-/usr/local/bin}"
TANGLED_REPO="${ATCR_TANGLED_REPO:-https://tangled.org/did:plc:e3kzdezk5gsirzh7eoqplc64}"
# Detect OS and architecture
detect_platform() {
local os=$(uname -s | tr '[:upper:]' '[:lower:]')
local arch=$(uname -m)
case "$os" in
linux*)
OS="Linux"
;;
darwin*)
OS="Darwin"
;;
*)
echo -e "${RED}Unsupported OS: $os${NC}"
exit 1
;;
esac
case "$arch" in
x86_64|amd64)
ARCH="x86_64"
;;
aarch64|arm64)
ARCH="arm64"
;;
*)
echo -e "${RED}Unsupported architecture: $arch${NC}"
exit 1
;;
esac
}
# Resolve the latest version by reading the tangled /tags/latest redirect
fetch_latest_version() {
echo -e "${YELLOW}Resolving latest version...${NC}"
local redirect
redirect=$(curl -s --max-time 10 -o /dev/null -D - "${TANGLED_REPO}/tags/latest" | awk 'tolower($1) == "location:" { print $2 }' | tr -d '\r\n')
if [ -z "$redirect" ]; then
echo -e "${RED}Failed to resolve latest version from ${TANGLED_REPO}/tags/latest${NC}"
exit 1
fi
VERSION="${redirect##*/}"
if [ -z "$VERSION" ] || [ "${VERSION#v}" = "$VERSION" ]; then
echo -e "${RED}Unexpected redirect location: ${redirect}${NC}"
exit 1
fi
echo -e "${GREEN}Found latest version: ${VERSION}${NC}"
}
# Build the download URL from version and platform
build_download_url() {
local version_without_v="${VERSION#v}"
DOWNLOAD_URL="${TANGLED_REPO}/tags/${VERSION}/download/docker-credential-atcr_${version_without_v}_${OS}_${ARCH}.tar.gz"
}
# Download and install binary
install_binary() {
echo -e "${YELLOW}Downloading from: ${DOWNLOAD_URL}${NC}"
local tmp_dir=$(mktemp -d)
trap "rm -rf $tmp_dir" EXIT
if ! curl -fsSL "$DOWNLOAD_URL" -o "$tmp_dir/docker-credential-atcr.tar.gz"; then
echo -e "${RED}Failed to download release${NC}"
exit 1
fi
echo -e "${YELLOW}Extracting...${NC}"
tar -xzf "$tmp_dir/docker-credential-atcr.tar.gz" -C "$tmp_dir"
# Check if we need sudo
if [ -w "$INSTALL_DIR" ]; then
SUDO=""
else
SUDO="sudo"
echo -e "${YELLOW}Installing to ${INSTALL_DIR} (requires sudo)${NC}"
fi
$SUDO mkdir -p "$INSTALL_DIR"
$SUDO install -m 755 "$tmp_dir/$BINARY_NAME" "$INSTALL_DIR/$BINARY_NAME"
echo -e "${GREEN}Installed ${BINARY_NAME} to ${INSTALL_DIR}${NC}"
}
# Verify installation
verify_installation() {
if ! command -v "$BINARY_NAME" &> /dev/null; then
echo -e "${RED}${BINARY_NAME} not found in PATH${NC}"
echo -e "${YELLOW}You may need to add ${INSTALL_DIR} to your PATH${NC}"
echo -e "${YELLOW}Add this to your ~/.bashrc or ~/.zshrc:${NC}"
echo -e " export PATH=\"${INSTALL_DIR}:\$PATH\""
return 1
fi
echo -e "${GREEN}Verification successful!${NC}"
"$BINARY_NAME" version
}
# Configure Docker
configure_docker() {
echo ""
echo -e "${GREEN}Installation complete!${NC}"
echo ""
echo -e "${YELLOW}To use ATCR with Docker, configure Docker to use this credential helper:${NC}"
echo -e ' echo '\''{"credHelpers": {"atcr.io": "atcr"}}'\'' > ~/.docker/config.json'
echo ""
echo -e "${YELLOW}Or add to existing config.json:${NC}"
echo -e ' {
"credHelpers": {
"atcr.io": "atcr"
}
}'
}
# Main
main() {
echo -e "${GREEN}ATCR Credential Helper Installer${NC}"
echo ""
detect_platform
echo -e "Detected: ${GREEN}${OS} ${ARCH}${NC}"
if [ -n "$ATCR_VERSION" ]; then
VERSION="$ATCR_VERSION"
echo -e "Using specified version: ${GREEN}${VERSION}${NC}"
else
fetch_latest_version
fi
build_download_url
echo -e "Installing version: ${GREEN}${VERSION}${NC}"
install_binary
verify_installation
configure_docker
}
main "$@"