-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·154 lines (133 loc) · 4.47 KB
/
install.sh
File metadata and controls
executable file
·154 lines (133 loc) · 4.47 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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#!/usr/bin/env bash
# optimize-anything installer / uninstaller
#
# Install:
# curl -fsSL https://raw.githubusercontent.com/ASRagab/optimize-anything/main/install.sh | bash
#
# Uninstall:
# curl -fsSL https://raw.githubusercontent.com/ASRagab/optimize-anything/main/install.sh | bash -s -- --uninstall
#
# What install does:
# 1. Installs uv (if not already installed)
# 2. Installs optimize-anything as a global CLI tool via uv tool install
# 3. Verifies the installation
#
# Environment variables:
# OPTIMIZE_ANYTHING_REPO - Git URL or local path to install from (default: GitHub repo)
# OPTIMIZE_ANYTHING_REF - Git ref to install (default: main)
set -euo pipefail
# --- Configuration ---
REPO="${OPTIMIZE_ANYTHING_REPO:-git+https://github.com/ASRagab/optimize-anything}"
REF="${OPTIMIZE_ANYTHING_REF:-main}"
# Local paths don't use @ref syntax
if [[ "${REPO}" == /* ]] || [[ "${REPO}" == ./* ]]; then
INSTALL_SOURCE="${REPO}"
else
INSTALL_SOURCE="${REPO}@${REF}"
fi
# --- Colors (if terminal supports them) ---
if [ -t 1 ]; then
BOLD="\033[1m"
GREEN="\033[32m"
YELLOW="\033[33m"
RED="\033[31m"
RESET="\033[0m"
else
BOLD="" GREEN="" YELLOW="" RED="" RESET=""
fi
info() { echo -e "${BOLD}${GREEN}==>${RESET} ${BOLD}$1${RESET}"; }
warn() { echo -e "${BOLD}${YELLOW}warning:${RESET} $1"; }
error() { echo -e "${BOLD}${RED}error:${RESET} $1" >&2; }
# --- Uninstall ---
uninstall() {
echo ""
echo -e "${BOLD}optimize-anything uninstaller${RESET}"
echo ""
if ! command -v uv &>/dev/null; then
error "uv is not installed — nothing to uninstall"
exit 1
fi
if uv tool uninstall optimize-anything 2>&1; then
info "optimize-anything has been uninstalled"
echo ""
echo "The isolated environment and CLI executable have been removed."
echo "uv itself was NOT removed. To remove uv: uv self uninstall"
else
warn "optimize-anything may not be installed via uv tool"
echo ""
echo "If installed from source, just delete the cloned directory."
fi
}
# --- Install: Step 1 ---
install_uv() {
if command -v uv &>/dev/null; then
info "uv is already installed ($(uv --version))"
return 0
fi
info "Installing uv..."
curl -LsSf https://astral.sh/uv/install.sh | sh
# Source the env so uv is available in this session
export PATH="$HOME/.local/bin:$HOME/.cargo/bin:$PATH"
if ! command -v uv &>/dev/null; then
error "uv installation failed. Install manually: https://docs.astral.sh/uv/"
exit 1
fi
info "uv installed ($(uv --version))"
}
# --- Install: Step 2 ---
install_tool() {
info "Installing optimize-anything from ${INSTALL_SOURCE}..."
if uv tool install "${INSTALL_SOURCE}" --force 2>&1; then
info "optimize-anything installed successfully"
else
error "Installation failed"
echo ""
echo "Troubleshooting:"
echo " - Check the repo URL: ${REPO}"
echo " - Try installing manually: uv tool install '${INSTALL_SOURCE}'"
echo " - For local installs: uv tool install /path/to/optimize-anything"
exit 1
fi
}
# --- Install: Step 3 ---
verify() {
export PATH="$HOME/.local/bin:$PATH"
if command -v optimize-anything &>/dev/null; then
info "Verification passed"
echo ""
echo -e "${BOLD}optimize-anything is ready!${RESET}"
echo ""
echo " optimize-anything optimize --help # See CLI options"
echo " optimize-anything explain seed.txt # Preview optimization"
echo " optimize-anything budget seed.txt # Get budget recommendation"
echo ""
echo "To uninstall: uv tool uninstall optimize-anything"
echo ""
echo "If the command is not found, add this to your shell profile:"
echo ' export PATH="$HOME/.local/bin:$PATH"'
else
warn "optimize-anything was installed but is not on your PATH"
echo ""
echo "Add this to your ~/.bashrc or ~/.zshrc:"
echo ' export PATH="$HOME/.local/bin:$PATH"'
echo ""
echo "Then restart your shell or run: source ~/.bashrc"
fi
}
# --- Main ---
main() {
# Check for --uninstall flag
for arg in "$@"; do
if [ "$arg" = "--uninstall" ] || [ "$arg" = "uninstall" ]; then
uninstall
exit 0
fi
done
echo ""
echo -e "${BOLD}optimize-anything installer${RESET}"
echo ""
install_uv
install_tool
verify
}
main "$@"