Skip to content

Commit 5fe627b

Browse files
committed
Install script using uv tool install for Linux/macOS/WSL
1 parent c9a8f78 commit 5fe627b

1 file changed

Lines changed: 129 additions & 0 deletions

File tree

scripts/install_seiscat_uv.sh

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
#!/usr/bin/env bash
2+
# Copyright (c) 2021-2026 Claudio Satriano <satriano@ipgp.fr>
3+
# SPDX-License-Identifier: GPL-3.0-or-later
4+
5+
set -euo pipefail
6+
7+
if [ -t 1 ]; then
8+
C_RESET='\033[0m'
9+
C_BLUE='\033[1;34m'
10+
C_GREEN='\033[1;32m'
11+
C_YELLOW='\033[1;33m'
12+
C_RED='\033[1;31m'
13+
else
14+
C_RESET=''
15+
C_BLUE=''
16+
C_GREEN=''
17+
C_YELLOW=''
18+
C_RED=''
19+
fi
20+
21+
info() {
22+
printf '%b[INFO]%b %s\n' "$C_BLUE" "$C_RESET" "$1"
23+
}
24+
25+
ok() {
26+
printf '%b[OK]%b %s\n' "$C_GREEN" "$C_RESET" "$1"
27+
}
28+
29+
warn() {
30+
printf '%b[WARN]%b %s\n' "$C_YELLOW" "$C_RESET" "$1"
31+
}
32+
33+
fail() {
34+
printf '%b[ERROR]%b %s\n' "$C_RED" "$C_RESET" "$1" >&2
35+
exit 1
36+
}
37+
38+
activate_argcomplete() {
39+
local shell_name
40+
local zsh_marker='# >>> seiscat argcomplete >>>'
41+
local zsh_end_marker='# <<< seiscat argcomplete <<<'
42+
43+
shell_name="$(basename "${SHELL:-}")"
44+
45+
if activate-global-python-argcomplete --user; then
46+
ok 'Legacy global argcomplete activation completed (--user mode).'
47+
else
48+
warn 'activate-global-python-argcomplete --user failed.'
49+
warn 'Retrying without --user (may require elevated permissions)...'
50+
activate-global-python-argcomplete
51+
ok 'Legacy global argcomplete activation completed.'
52+
fi
53+
54+
if [ "$shell_name" = 'zsh' ]; then
55+
info 'Applying zsh-specific completion snippet for seiscat...'
56+
touch "$HOME/.zshrc"
57+
if grep -Fq "$zsh_marker" "$HOME/.zshrc"; then
58+
awk -v start="$zsh_marker" -v end="$zsh_end_marker" '
59+
$0 == start { in_block = 1; next }
60+
$0 == end { in_block = 0; next }
61+
!in_block { print }
62+
' "$HOME/.zshrc" > "$HOME/.zshrc.tmp"
63+
mv "$HOME/.zshrc.tmp" "$HOME/.zshrc"
64+
info 'Updated existing managed zsh completion snippet in ~/.zshrc.'
65+
fi
66+
67+
{
68+
printf '\n%s\n' "$zsh_marker"
69+
printf 'autoload -U compinit\n'
70+
printf 'if ! typeset -f compdef >/dev/null 2>&1; then\n'
71+
printf ' compinit\n'
72+
printf 'fi\n'
73+
printf 'autoload -U +X bashcompinit && bashcompinit\n'
74+
printf "eval \"\$(register-python-argcomplete seiscat)\"\n"
75+
printf '%s\n' "$zsh_end_marker"
76+
} >> "$HOME/.zshrc"
77+
ok 'Installed zsh completion snippet in ~/.zshrc.'
78+
info 'Open a new terminal or run: source ~/.zshrc'
79+
fi
80+
}
81+
82+
install_uv() {
83+
info 'uv is not installed. Installing uv...'
84+
85+
if command -v curl >/dev/null 2>&1; then
86+
curl -LsSf https://astral.sh/uv/install.sh | sh
87+
elif command -v wget >/dev/null 2>&1; then
88+
wget -qO- https://astral.sh/uv/install.sh | sh
89+
else
90+
fail 'Neither curl nor wget is available. Install one of them, then re-run this script.'
91+
fi
92+
93+
export PATH="$HOME/.local/bin:$PATH"
94+
95+
if ! command -v uv >/dev/null 2>&1; then
96+
fail 'uv installation did not complete successfully. Add ~/.local/bin to PATH and retry.'
97+
fi
98+
99+
ok 'uv installed successfully.'
100+
}
101+
102+
main() {
103+
info 'Starting SeisCat installation with uv for Linux/macOS/WSL...'
104+
105+
info 'Step 1/4: Checking if uv is installed...'
106+
if command -v uv >/dev/null 2>&1; then
107+
ok "uv is already installed: $(uv --version)"
108+
else
109+
install_uv
110+
fi
111+
112+
info 'Step 2/4: Installing/updating seiscat with plotly, cartopy, and folium support using uv tool install...'
113+
info 'Running: uv tool install seiscat --with plotly --with cartopy --with folium --upgrade --force'
114+
uv tool install seiscat --with plotly --with cartopy --with folium --upgrade --force
115+
ok 'seiscat installed/updated with plotly, cartopy, and folium support.'
116+
117+
info 'Step 3/4: Installing argcomplete using uv tool install...'
118+
info 'Running: uv tool install argcomplete'
119+
uv tool install argcomplete
120+
ok 'argcomplete installed successfully.'
121+
122+
info 'Step 4/4: Running activate-global-python-argcomplete...'
123+
activate_argcomplete
124+
125+
ok 'All steps completed.'
126+
info 'If seiscat is not found in your shell, restart your terminal or ensure ~/.local/bin is in PATH.'
127+
}
128+
129+
main "$@"

0 commit comments

Comments
 (0)