-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·58 lines (49 loc) · 1.79 KB
/
install.sh
File metadata and controls
executable file
·58 lines (49 loc) · 1.79 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
#!/usr/bin/env bash
set -euo pipefail
REPO="https://github.com/FZ2000/apc-cli.git"
INSTALL_DIR="${APC_INSTALL_DIR:-$HOME/.apc-cli}"
BIN_DIR="${APC_BIN_DIR:-$HOME/.local/bin}"
info() { printf '\033[1;34m==>\033[0m %s\n' "$*"; }
error() { printf '\033[1;31merror:\033[0m %s\n' "$*" >&2; exit 1; }
# Check Python >= 3.12
check_python() {
for cmd in python3 python; do
if command -v "$cmd" &>/dev/null; then
version=$("$cmd" -c "import sys; print(f'{sys.version_info.major}.{sys.version_info.minor}')")
major=$("$cmd" -c "import sys; print(sys.version_info.major)")
minor=$("$cmd" -c "import sys; print(sys.version_info.minor)")
if [ "$major" -ge 3 ] && [ "$minor" -ge 12 ]; then
PYTHON="$cmd"
return
fi
fi
done
error "Python 3.12+ is required. Found: ${version:-none}"
}
check_python
info "Using $PYTHON ($($PYTHON --version))"
# Clone or update
if [ -d "$INSTALL_DIR" ]; then
info "Updating existing installation..."
git -C "$INSTALL_DIR" pull --ff-only
else
info "Cloning apc-cli..."
git clone "$REPO" "$INSTALL_DIR"
fi
# Create venv and install
info "Setting up virtual environment..."
"$PYTHON" -m venv "$INSTALL_DIR/.venv"
"$INSTALL_DIR/.venv/bin/pip" install --quiet --upgrade pip
"$INSTALL_DIR/.venv/bin/pip" install --quiet "$INSTALL_DIR"
# Create bin directory and symlink
mkdir -p "$BIN_DIR"
ln -sf "$INSTALL_DIR/.venv/bin/apc" "$BIN_DIR/apc"
# Check if BIN_DIR is in PATH
if ! echo "$PATH" | tr ':' '\n' | grep -qx "$BIN_DIR"; then
info "Add this to your shell profile:"
echo ""
echo " export PATH=\"$BIN_DIR:\$PATH\""
echo ""
fi
info "Installed apc $("$INSTALL_DIR/.venv/bin/apc" --version 2>&1 | awk '{print $NF}')"
info "Run 'apc --help' to get started"