forked from RhysSullivan/executor
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·287 lines (253 loc) · 8.63 KB
/
install.sh
File metadata and controls
executable file
·287 lines (253 loc) · 8.63 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
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
#!/usr/bin/env bash
set -euo pipefail
APP=executor
REPO=RhysSullivan/executor
MUTED='\033[0;2m'
RED='\033[0;31m'
ORANGE='\033[38;5;214m'
NC='\033[0m'
usage() {
cat <<EOF
Executor installer
Usage: install.sh [options]
Options:
-h, --help Display this help message
-v, --version <version> Install a specific version (e.g. 1.4.12)
-b, --binary <path> Install from a local binary instead of downloading
--no-modify-path Don't modify shell config files (.zshrc, .bashrc, etc.)
Examples:
curl -fsSL https://raw.githubusercontent.com/${REPO}/main/scripts/install.sh | bash
curl -fsSL https://raw.githubusercontent.com/${REPO}/main/scripts/install.sh | bash -s -- --version 1.4.12
./install.sh --binary /path/to/executor
EOF
}
requested_version=${VERSION:-}
no_modify_path=false
binary_path=""
while [[ $# -gt 0 ]]; do
case "$1" in
-h|--help)
usage
exit 0
;;
-v|--version)
if [[ -n "${2:-}" ]]; then
requested_version="$2"
shift 2
else
echo -e "${RED}Error: --version requires a version argument${NC}" >&2
exit 1
fi
;;
-b|--binary)
if [[ -n "${2:-}" ]]; then
binary_path="$2"
shift 2
else
echo -e "${RED}Error: --binary requires a path argument${NC}" >&2
exit 1
fi
;;
--no-modify-path)
no_modify_path=true
shift
;;
*)
echo -e "${ORANGE}Warning: Unknown option '$1'${NC}" >&2
shift
;;
esac
done
INSTALL_DIR="${EXECUTOR_INSTALL_DIR:-$HOME/.executor/bin}"
mkdir -p "$INSTALL_DIR"
print_message() {
local level=$1 message=$2 color=""
case "$level" in
info) color="${NC}" ;;
warning) color="${ORANGE}" ;;
error) color="${RED}" ;;
esac
echo -e "${color}${message}${NC}"
}
if [[ -n "$binary_path" ]]; then
if [[ ! -f "$binary_path" ]]; then
print_message error "Error: binary not found at $binary_path"
exit 1
fi
specific_version="local"
else
raw_os=$(uname -s)
case "$raw_os" in
Darwin*) os="darwin" ;;
Linux*) os="linux" ;;
MINGW*|MSYS*|CYGWIN*) os="windows" ;;
*)
print_message error "Unsupported OS: $raw_os"
exit 1
;;
esac
arch=$(uname -m)
case "$arch" in
aarch64|arm64) arch="arm64" ;;
x86_64|amd64) arch="x64" ;;
*)
print_message error "Unsupported architecture: $arch"
exit 1
;;
esac
# Apple Silicon under Rosetta reports x64 — install the native arm64 build.
if [[ "$os" == "darwin" && "$arch" == "x64" ]]; then
if [[ "$(sysctl -n sysctl.proc_translated 2>/dev/null || echo 0)" == "1" ]]; then
arch="arm64"
fi
fi
is_musl=false
if [[ "$os" == "linux" ]]; then
if [[ -f /etc/alpine-release ]]; then
is_musl=true
elif command -v ldd >/dev/null 2>&1 && ldd --version 2>&1 | grep -qi musl; then
is_musl=true
fi
fi
target="${os}-${arch}"
if [[ "$is_musl" == "true" ]]; then
target="${target}-musl"
fi
archive_ext=".zip"
if [[ "$os" == "linux" ]]; then
archive_ext=".tar.gz"
fi
filename="${APP}-${target}${archive_ext}"
if [[ "$os" == "linux" ]]; then
if ! command -v tar >/dev/null 2>&1; then
print_message error "Error: 'tar' is required but not installed."
exit 1
fi
else
if ! command -v unzip >/dev/null 2>&1; then
print_message error "Error: 'unzip' is required but not installed."
exit 1
fi
fi
if [[ -z "$requested_version" ]]; then
url="https://github.com/${REPO}/releases/latest/download/${filename}"
specific_version=$(
curl -s "https://api.github.com/repos/${REPO}/releases/latest" \
| sed -n 's/.*"tag_name": *"v\([^"]*\)".*/\1/p'
)
if [[ -z "$specific_version" ]]; then
print_message error "Failed to fetch latest version metadata"
exit 1
fi
else
requested_version="${requested_version#v}"
url="https://github.com/${REPO}/releases/download/v${requested_version}/${filename}"
specific_version="$requested_version"
http_status=$(curl -sI -o /dev/null -w "%{http_code}" \
"https://github.com/${REPO}/releases/tag/v${requested_version}")
if [[ "$http_status" == "404" ]]; then
print_message error "Error: release v${requested_version} not found"
print_message info "${MUTED}Available releases: https://github.com/${REPO}/releases${NC}"
exit 1
fi
fi
fi
check_existing_version() {
if command -v executor >/dev/null 2>&1; then
local installed
installed=$(executor --version 2>/dev/null || echo "")
if [[ "$installed" == "$specific_version" ]]; then
print_message info "${MUTED}Version ${NC}${specific_version}${MUTED} already installed${NC}"
exit 0
fi
print_message info "${MUTED}Replacing installed version ${NC}${installed}"
fi
}
download_and_install() {
print_message info "\n${MUTED}Installing ${NC}${APP} ${MUTED}version: ${NC}${specific_version}"
local tmp_dir
tmp_dir=$(mktemp -d "${TMPDIR:-/tmp}/${APP}_install_XXXXXXXXXX")
trap 'rm -rf "$tmp_dir"' RETURN
curl -# -L -o "${tmp_dir}/${filename}" "$url"
if [[ "$os" == "linux" ]]; then
tar -xzf "${tmp_dir}/${filename}" -C "$tmp_dir"
else
unzip -q "${tmp_dir}/${filename}" -d "$tmp_dir"
fi
# The archive is flat — the binary plus sidecars (emscripten-module.wasm,
# keyring.node) sit at the root. Copy them all into INSTALL_DIR so the
# binary's relative-path lookups still resolve.
rm -f "${tmp_dir}/${filename}"
cp -R "${tmp_dir}/." "${INSTALL_DIR}/"
chmod 755 "${INSTALL_DIR}/${APP}"
rm -rf "$tmp_dir"
trap - RETURN
}
install_from_binary() {
print_message info "\n${MUTED}Installing ${NC}${APP} ${MUTED}from: ${NC}${binary_path}"
cp "$binary_path" "${INSTALL_DIR}/${APP}"
chmod 755 "${INSTALL_DIR}/${APP}"
}
if [[ -n "$binary_path" ]]; then
install_from_binary
else
check_existing_version
download_and_install
fi
add_to_path() {
local config_file=$1 command=$2
if grep -Fxq "$command" "$config_file"; then
print_message info "${MUTED}Already in ${NC}${config_file}"
elif [[ -w "$config_file" ]]; then
echo -e "\n# executor" >> "$config_file"
echo "$command" >> "$config_file"
print_message info "${MUTED}Added ${NC}${APP} ${MUTED}to \$PATH in ${NC}${config_file}"
else
print_message warning "Manually add to ${config_file}:"
print_message info " $command"
fi
}
XDG_CONFIG_HOME="${XDG_CONFIG_HOME:-$HOME/.config}"
current_shell=$(basename "${SHELL:-bash}")
case "$current_shell" in
fish)
config_files="$HOME/.config/fish/config.fish"
;;
zsh)
config_files="${ZDOTDIR:-$HOME}/.zshrc ${ZDOTDIR:-$HOME}/.zshenv $XDG_CONFIG_HOME/zsh/.zshrc $XDG_CONFIG_HOME/zsh/.zshenv"
;;
bash)
config_files="$HOME/.bashrc $HOME/.bash_profile $HOME/.profile $XDG_CONFIG_HOME/bash/.bashrc $XDG_CONFIG_HOME/bash/.bash_profile"
;;
*)
config_files="$HOME/.bashrc $HOME/.bash_profile $XDG_CONFIG_HOME/bash/.bashrc $XDG_CONFIG_HOME/bash/.bash_profile"
;;
esac
if [[ "$no_modify_path" != "true" ]]; then
config_file=""
for file in $config_files; do
if [[ -f "$file" ]]; then
config_file=$file
break
fi
done
if [[ -z "$config_file" ]]; then
print_message warning "No config file found for ${current_shell}. Add manually:"
print_message info " export PATH=${INSTALL_DIR}:\$PATH"
elif [[ ":$PATH:" != *":$INSTALL_DIR:"* ]]; then
case "$current_shell" in
fish) add_to_path "$config_file" "fish_add_path $INSTALL_DIR" ;;
*) add_to_path "$config_file" "export PATH=$INSTALL_DIR:\$PATH" ;;
esac
fi
fi
if [[ -n "${GITHUB_ACTIONS-}" && "${GITHUB_ACTIONS}" == "true" ]]; then
echo "$INSTALL_DIR" >> "$GITHUB_PATH"
print_message info "${MUTED}Added ${NC}${INSTALL_DIR}${MUTED} to \$GITHUB_PATH${NC}"
fi
print_message info ""
print_message info "${MUTED}Installed ${NC}${APP} ${MUTED}to ${NC}${INSTALL_DIR}/${APP}"
print_message info ""
print_message info "${MUTED}Get started:${NC}"
print_message info " ${APP} web"
print_message info ""