-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·138 lines (122 loc) · 2.48 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·138 lines (122 loc) · 2.48 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
#!/usr/bin/env bash
set -euo pipefail
usage() {
cat <<'EOF'
Usage:
./install.sh install [--python <exe>]
./install.sh uninstall
Options:
--python <exe> Python executable to use for launcher (default: python3)
Examples:
./install.sh install
./install.sh install --python python3
./install.sh uninstall
EOF
}
target_bin_dir() {
echo "$HOME/.local/bin"
}
target_lib_dir() {
echo "$HOME/.local/lib/zaribox"
}
install_program() {
local lib_dir
lib_dir="$(target_lib_dir)"
if [[ ! -d "$root_dir/zaribox" ]]; then
echo "Source directory not found: $root_dir/zaribox" >&2
exit 1
fi
rm -rf "$lib_dir"
mkdir -p "$lib_dir"
cp -a "$root_dir/zaribox/." "$lib_dir/"
echo "Installed program files to $lib_dir"
}
install_launcher() {
local bin_dir launcher lib_dir
bin_dir="$(target_bin_dir)"
launcher="$bin_dir/zaribox"
lib_dir="$(target_lib_dir)"
mkdir -p "$bin_dir"
cat >"$launcher" <<-EOF
#!/usr/bin/env bash
set -euo pipefail
exec "$python_exe" "$lib_dir/__main__.py" "\$@"
EOF
chmod +x "$launcher"
echo "Installed launcher at $launcher"
}
remove_launcher() {
local launcher
launcher="$(target_bin_dir)/zaribox"
if [[ -f "$launcher" ]]; then
rm -f "$launcher"
echo "Removed launcher at $launcher"
fi
}
remove_program() {
local lib_dir
lib_dir="$(target_lib_dir)"
if [[ -d "$lib_dir" ]]; then
rm -rf "$lib_dir"
echo "Removed program files at $lib_dir"
fi
}
if [[ $# -lt 1 ]]; then
usage
exit 1
fi
action="$1"
shift
python_exe="python3"
while [[ $# -gt 0 ]]; do
case "$1" in
--python)
if [[ "$action" == "uninstall" ]]; then
echo "Warning: --python is ignored for uninstall" >&2
shift 2
continue
fi
if [[ $# -lt 2 ]]; then
echo "Missing value for --python" >&2
exit 1
fi
python_exe="$2"
shift 2
;;
-h|--help)
usage
exit 0
;;
*)
echo "Unknown argument: $1" >&2
usage
exit 1
;;
esac
done
root_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$root_dir"
case "$action" in
install)
if ! command -v "$python_exe" >/dev/null 2>&1; then
echo "Python executable not found: $python_exe" >&2
exit 1
fi
install_program
install_launcher
echo "Installed. Ensure ~/.local/bin is in PATH."
if [[ ":$PATH:" != *":$HOME/.local/bin:"* ]]; then
echo "Warning: $HOME/.local/bin is not in your PATH. Add it to your shell profile to use zaribox."
fi
;;
uninstall)
remove_launcher
remove_program
echo "Uninstalled zaribox."
;;
*)
echo "Unknown action: $action" >&2
usage
exit 1
;;
esac