-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
84 lines (68 loc) · 1.95 KB
/
install.sh
File metadata and controls
84 lines (68 loc) · 1.95 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
#!/bin/bash
# CacheWraith installer for a real local checkout.
set -euo pipefail
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
CYAN='\033[0;36m'
NC='\033[0m'
INSTALL_DIR="${HOME}/.cachewraith"
VENV_DIR="${INSTALL_DIR}/venv"
BIN_DIR="${HOME}/.local/bin"
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
print_info() {
echo -e "${BLUE}[INFO]${NC} $1"
}
print_success() {
echo -e "${GREEN}[SUCCESS]${NC} $1"
}
print_warning() {
echo -e "${YELLOW}[WARNING]${NC} $1"
}
print_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
check_source_checkout() {
if [[ ! -f "${SCRIPT_DIR}/pyproject.toml" ]]; then
print_error "install.sh must be run from a real CacheWraith checkout."
exit 1
fi
}
check_python() {
if command -v python3 >/dev/null 2>&1; then
PYTHON_CMD="python3"
elif command -v python >/dev/null 2>&1; then
PYTHON_CMD="python"
else
print_error "Python 3 is required."
exit 1
fi
if ! "${PYTHON_CMD}" -c "import sys; raise SystemExit(0 if sys.version_info >= (3, 8) else 1)"; then
print_error "Python 3.8 or higher is required."
exit 1
fi
}
install_cachewraith() {
mkdir -p "${INSTALL_DIR}" "${BIN_DIR}"
print_info "Creating virtual environment in ${VENV_DIR}"
"${PYTHON_CMD}" -m venv "${VENV_DIR}"
source "${VENV_DIR}/bin/activate"
print_info "Installing CacheWraith from ${SCRIPT_DIR}"
pip install --upgrade pip setuptools wheel >/dev/null
pip install "${SCRIPT_DIR}" >/dev/null
for command_name in cachewraith-cli cw; do
cat > "${BIN_DIR}/${command_name}" << EOF
#!/bin/bash
source "${VENV_DIR}/bin/activate"
exec "${VENV_DIR}/bin/${command_name}" "\$@"
EOF
chmod +x "${BIN_DIR}/${command_name}"
done
}
print_info "Installing CacheWraith"
check_source_checkout
check_python
install_cachewraith
print_success "CacheWraith installed."
print_warning "Make sure ${BIN_DIR} is in your PATH."