Files
at-container-registry/pkg/appview/static/install.sh
2025-10-13 17:07:08 -05:00

137 lines
3.4 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}"
VERSION="v0.0.1"
TAG_HASH="c6cfbaf1723123907f9d23e300f6f72081e65006"
TANGLED_REPO="https://tangled.org/@evan.jarrett.net/at-container-registry"
# 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
}
# Download and install binary
install_binary() {
local version="${1:-$VERSION}"
local download_url="${TANGLED_REPO}/tags/${TAG_HASH}/download/docker-credential-atcr_${version#v}_${OS}_${ARCH}.tar.gz"
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}"
# Allow specifying version via environment variable
if [ -z "$ATCR_VERSION" ]; then
echo -e "Using version: ${GREEN}${VERSION}${NC}"
else
VERSION="$ATCR_VERSION"
echo -e "Using specified version: ${GREEN}${VERSION}${NC}"
fi
install_binary
verify_installation
configure_docker
}
main "$@"