forked from nashsu/AutoCLI
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·120 lines (102 loc) · 3.34 KB
/
install.sh
File metadata and controls
executable file
·120 lines (102 loc) · 3.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#!/bin/sh
# autocli installer — detects OS/Arch and downloads the right binary
# Usage: curl -fsSL https://raw.githubusercontent.com/nashsu/autocli/main/scripts/install.sh | sh
set -e
REPO="nashsu/autocli"
INSTALL_DIR="/usr/local/bin"
BINARY_NAME="autocli"
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
CYAN='\033[0;36m'
NC='\033[0m'
info() { printf "${CYAN}$1${NC}\n"; }
success() { printf "${GREEN}$1${NC}\n"; }
error() { printf "${RED}Error: $1${NC}\n" >&2; exit 1; }
# Detect OS
OS=$(uname -s | tr '[:upper:]' '[:lower:]')
case "$OS" in
linux*) OS="unknown-linux-musl" ;;
darwin*) OS="apple-darwin" ;;
mingw*|msys*|cygwin*) OS="pc-windows-msvc" ;;
*) error "Unsupported OS: $OS" ;;
esac
# Detect Arch
ARCH=$(uname -m)
case "$ARCH" in
x86_64|amd64) ARCH="x86_64" ;;
aarch64|arm64) ARCH="aarch64" ;;
*) error "Unsupported architecture: $ARCH" ;;
esac
TARGET="${ARCH}-${OS}"
# Get latest version (via redirect, avoids API rate limit)
info "Detecting latest version..."
VERSION=$(curl -fsSI "https://github.com/${REPO}/releases/latest" | grep -i "location:" | sed -E 's/.*\/tag\/(.*)/\1/' | tr -d '\r\n')
if [ -z "$VERSION" ]; then
error "Could not detect latest version. Check https://github.com/${REPO}/releases"
fi
info "Latest version: ${VERSION}"
# Determine archive format
if echo "$OS" | grep -q "windows"; then
EXT="zip"
ARCHIVE="${BINARY_NAME}-${TARGET}.zip"
else
EXT="tar.gz"
ARCHIVE="${BINARY_NAME}-${TARGET}.tar.gz"
fi
URL="https://github.com/${REPO}/releases/download/${VERSION}/${ARCHIVE}"
# Download
info "Downloading ${ARCHIVE}..."
TMPDIR=$(mktemp -d)
trap 'rm -rf "$TMPDIR"' EXIT
if ! curl -fsSL "$URL" -o "${TMPDIR}/${ARCHIVE}"; then
error "Download failed. Binary may not exist for ${TARGET}.\nCheck: https://github.com/${REPO}/releases/tag/${VERSION}"
fi
# Extract
info "Extracting..."
cd "$TMPDIR"
if [ "$EXT" = "zip" ]; then
unzip -q "$ARCHIVE"
else
tar xzf "$ARCHIVE"
fi
# Install
if [ -w "$INSTALL_DIR" ]; then
mv "$BINARY_NAME" "$INSTALL_DIR/"
else
info "Installing to ${INSTALL_DIR} (requires sudo)..."
sudo mv "$BINARY_NAME" "$INSTALL_DIR/"
fi
chmod +x "${INSTALL_DIR}/${BINARY_NAME}"
# Migrate from .opencli-rs to .autocli
OLD_CONFIG="$HOME/.opencli-rs"
NEW_CONFIG="$HOME/.autocli"
if [ -d "$OLD_CONFIG" ]; then
if [ -d "$NEW_CONFIG" ]; then
info "Both ~/.opencli-rs and ~/.autocli exist, merging..."
cp -rn "$OLD_CONFIG/"* "$NEW_CONFIG/" 2>/dev/null || true
else
info "Migrating ~/.opencli-rs to ~/.autocli..."
cp -r "$OLD_CONFIG" "$NEW_CONFIG"
fi
rm -rf "$OLD_CONFIG"
success "✓ Migrated config from ~/.opencli-rs to ~/.autocli"
fi
# Remove old binary if exists
if command -v "opencli-rs" >/dev/null 2>&1; then
OLD_BIN=$(command -v "opencli-rs")
info "Removing old binary: ${OLD_BIN}"
rm -f "$OLD_BIN" 2>/dev/null || sudo rm -f "$OLD_BIN" 2>/dev/null || true
fi
# Verify
if command -v "$BINARY_NAME" >/dev/null 2>&1; then
INSTALLED_VERSION=$("$BINARY_NAME" --version 2>/dev/null || echo "unknown")
success "✓ ${BINARY_NAME} installed successfully! (${INSTALLED_VERSION})"
echo ""
echo " Get started:"
echo " ${BINARY_NAME} --help"
echo " ${BINARY_NAME} hackernews top --limit 5"
else
success "✓ Installed to ${INSTALL_DIR}/${BINARY_NAME}"
echo " Make sure ${INSTALL_DIR} is in your PATH."
fi