-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·240 lines (211 loc) · 7.49 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·240 lines (211 loc) · 7.49 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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
#!/usr/bin/env bash
# csauto installer
#
# Fresh install (curl):
# bash -c "$(curl -fsSL https://raw.githubusercontent.com/simvia-tech/csauto/main/install.sh)"
#
# Fresh install (from a local clone):
# ./install.sh
#
# Update (re-run the same command — the script detects the existing install):
# bash -c "$(curl -fsSL https://raw.githubusercontent.com/simvia-tech/csauto/main/install.sh)"
#
# Options:
# --no-venv Install into the current Python environment instead of a venv
# --no-telemetry Disable anonymous usage telemetry
set -euo pipefail
REPO_URL="https://github.com/simvia-tech/csauto.git"
DEFAULT_INSTALL_DIR="$HOME/.local/share/csauto"
USE_VENV=true
NO_TELEMETRY=false
info() { printf "[info] %s\n" "$*"; }
success() { printf "[ok] %s\n" "$*"; }
warn() { printf "[warn] %s\n" "$*"; }
error() { printf "[error] %s\n" "$*" >&2; }
usage() {
echo "Usage: ./install.sh [--no-venv] [--no-telemetry]"
echo ""
echo "Install or update csauto and its web dashboard dependencies."
echo ""
echo "Options:"
echo " --no-venv Install into the current Python environment instead of a venv"
echo " --no-telemetry Disable anonymous usage telemetry"
exit 0
}
for arg in "$@"; do
case "$arg" in
--no-venv) USE_VENV=false ;;
--no-telemetry) NO_TELEMETRY=true ;;
-h|--help) usage ;;
*) echo "Unknown option: $arg"; usage ;;
esac
done
# -- Determine install mode --
# If we're inside an existing clone (contributor), use that directory.
# Otherwise, use the default install location (end-user curl install).
detect_repo_dir() {
# Check if this script is being run from inside a git clone of csauto
SCRIPT_DIR=""
if [ -n "${BASH_SOURCE[0]+x}" ] && [ -f "${BASH_SOURCE[0]}" ]; then
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
fi
if [ -n "$SCRIPT_DIR" ] && [ -f "$SCRIPT_DIR/pyproject.toml" ] && grep -q "csauto" "$SCRIPT_DIR/pyproject.toml" 2>/dev/null; then
# Running from inside an existing clone (./install.sh)
REPO_DIR="$SCRIPT_DIR"
MODE="local"
elif [ -d "$DEFAULT_INSTALL_DIR/.git" ] && [ -f "$DEFAULT_INSTALL_DIR/pyproject.toml" ]; then
# Existing curl install found — update mode
REPO_DIR="$DEFAULT_INSTALL_DIR"
MODE="update"
else
# Fresh curl install
REPO_DIR="$DEFAULT_INSTALL_DIR"
MODE="fresh"
fi
}
detect_repo_dir
printf "\n"
printf " csauto installer\n"
printf " ─────────────────\n"
printf "\n"
# -- Check dependencies --
PYTHON=python3
if ! command -v "$PYTHON" &>/dev/null; then
error "python3 not found. Please install Python 3.11 or later."
exit 1
fi
PY_VERSION=$("$PYTHON" -c "import sys; print(f'{sys.version_info.major}.{sys.version_info.minor}')")
PY_MAJOR=$("$PYTHON" -c "import sys; print(sys.version_info.major)")
PY_MINOR=$("$PYTHON" -c "import sys; print(sys.version_info.minor)")
if [ "$PY_MAJOR" -lt 3 ] || { [ "$PY_MAJOR" -eq 3 ] && [ "$PY_MINOR" -lt 11 ]; }; then
error "Python 3.11+ is required (found $PY_VERSION)."
exit 1
fi
info "Found Python $PY_VERSION"
# -- Clone or update the repository --
case "$MODE" in
fresh)
if ! command -v git &>/dev/null; then
error "git is required but was not found."
exit 1
fi
info "Cloning csauto to $REPO_DIR ..."
mkdir -p "$(dirname "$REPO_DIR")"
if [ -d "$REPO_DIR" ] && [ "$(ls -A "$REPO_DIR" 2>/dev/null)" ]; then
# Directory exists and is non-empty but not a git clone
# (e.g., leftover telemetry.json from a previous failed install).
# Clone in place so existing files are preserved.
info "Existing non-repo directory found; initializing csauto in place ..."
git -C "$REPO_DIR" init -q
git -C "$REPO_DIR" remote add origin "$REPO_URL" 2>/dev/null \
|| git -C "$REPO_DIR" remote set-url origin "$REPO_URL"
git -C "$REPO_DIR" fetch -q --depth=1 origin main
git -C "$REPO_DIR" checkout -q -f -B main FETCH_HEAD
else
git clone "$REPO_URL" "$REPO_DIR"
fi
success "Repository cloned"
;;
update)
info "Existing installation found at $REPO_DIR"
info "Pulling latest changes ..."
git -C "$REPO_DIR" pull --ff-only origin main
success "Repository updated"
;;
local)
info "Running from local clone at $REPO_DIR"
;;
esac
VENV_DIR="$REPO_DIR/.venv"
# -- Create venv if requested --
if $USE_VENV; then
if [ ! -d "$VENV_DIR" ]; then
info "Creating virtual environment in $VENV_DIR ..."
"$PYTHON" -m venv "$VENV_DIR"
else
info "Virtual environment already exists at $VENV_DIR"
fi
# shellcheck disable=SC1091
source "$VENV_DIR/bin/activate"
PIP="$VENV_DIR/bin/pip"
else
PIP=pip
fi
# -- Install csauto with web dependencies --
info "Installing csauto with web dashboard dependencies ..."
"$PIP" install --quiet -e "$REPO_DIR[web]"
# -- Verify installation --
CSAUTO_BIN=""
if $USE_VENV; then
CSAUTO_BIN="$VENV_DIR/bin/csauto"
else
CSAUTO_BIN="$(command -v csauto 2>/dev/null || true)"
fi
if [ -z "$CSAUTO_BIN" ] || [ ! -x "$CSAUTO_BIN" ]; then
error "csauto binary not found after installation."
exit 1
fi
VERSION=$("$CSAUTO_BIN" --version 2>&1)
success "Installed: $VERSION"
# -- Telemetry --
case "$MODE" in
fresh|update)
if $NO_TELEMETRY; then
info "Telemetry disabled by --no-telemetry flag"
"$PYTHON" -c "
import json, uuid, pathlib
d = pathlib.Path.home() / '.local' / 'share' / 'csauto'
d.mkdir(parents=True, exist_ok=True)
f = d / 'telemetry.json'
f.write_text(json.dumps({'user_id': str(uuid.uuid4()), 'enabled': False}, indent=2))
" 2>/dev/null || true
else
PING_TAG="install"
[ "$MODE" = "update" ] && PING_TAG="update"
"$CSAUTO_BIN" _telemetry-ping 3 "$PING_TAG" 2>/dev/null || true
fi
;;
esac
# -- Set up shell alias (venv mode only) --
if $USE_VENV; then
ALIAS_LINE="alias csauto='$CSAUTO_BIN'"
_PARENT_CMD="$(ps -o comm= -p "$PPID" 2>/dev/null || true)"
case "$_PARENT_CMD" in
zsh|bash) SHELL_NAME="$_PARENT_CMD" ;;
*) SHELL_NAME="$(basename "${SHELL:-/bin/bash}")" ;;
esac
case "$SHELL_NAME" in
zsh) RC_FILE="$HOME/.zshrc" ;;
*) RC_FILE="$HOME/.bashrc" ;;
esac
COMPLETION_LINE="eval \"\$($CSAUTO_BIN completion $SHELL_NAME)\""
# Always clean stale entries and rewrite, so updates pick up new paths
if [ -f "$RC_FILE" ]; then
sed -i '/^# csauto CLI$/d; /^alias csauto=/d; /^# csauto completion$/d; /csauto completion/d' "$RC_FILE"
fi
{
echo ""
echo "# csauto CLI"
echo "$ALIAS_LINE"
echo "# csauto completion"
echo "$COMPLETION_LINE"
} >> "$RC_FILE"
success "Shell alias and completion configured in $RC_FILE"
fi
# -- Done --
printf "\n"
case "$MODE" in
fresh) success "Installation complete!" ;;
update) success "Update complete!" ;;
local) success "Installation complete!" ;;
esac
printf "\n"
if $USE_VENV && [ "$MODE" != "update" ]; then
echo "To start using csauto, reload your shell:"
echo " source $RC_FILE"
echo ""
fi
echo "Quick start:"
echo " csauto --help # show available commands"
echo " csauto prepare doe.csv TEMPLATE RUNS # generate cases"
echo " csauto serve RUNS # launch web dashboard"