-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
Β·392 lines (333 loc) Β· 9.54 KB
/
install.sh
File metadata and controls
executable file
Β·392 lines (333 loc) Β· 9.54 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
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
#!/usr/bin/env bash
set -euo pipefail
BASE_URL="https://dl.lasersell.io"
BIN_BASE="${BASE_URL}/binaries/lasersell"
METHOD="auto"
VERSION=""
PREFIX=""
NO_COLOR_FLAG=0
RESET=""
BOLD=""
DIM=""
RED=""
GREEN=""
YELLOW=""
BLUE=""
CYAN=""
ACCENT=""
init_colors() {
local use_color=1
if [ "${NO_COLOR_FLAG}" -eq 1 ]; then
use_color=0
elif [ -n "${NO_COLOR:-}" ]; then
use_color=0
elif [ "${TERM:-}" = "dumb" ]; then
use_color=0
fi
if [ "${use_color}" -eq 1 ]; then
RESET=$'\033[0m'
BOLD=$'\033[1m'
DIM=$'\033[2m'
RED=$'\033[31m'
GREEN=$'\033[32m'
YELLOW=$'\033[33m'
BLUE=$'\033[34m'
CYAN=$'\033[36m'
ACCENT="${CYAN}"
else
RESET=""
BOLD=""
DIM=""
RED=""
GREEN=""
YELLOW=""
BLUE=""
CYAN=""
ACCENT=""
fi
}
title() { printf '%b\n' "${BOLD}${ACCENT}$*${RESET}"; }
step() { printf '%b\n' "${BOLD}β${RESET} $*"; }
info() { printf '%b\n' "${BLUE}βΉοΈ ${RESET}$*"; }
warn() { printf '%b\n' "${YELLOW}β οΈ${RESET} $*"; }
ok() { printf '%b\n' "${GREEN}β
${RESET} $*"; }
success() { ok "$@"; }
err() { printf '%b\n' "${RED}β${RESET} $*" >&2; }
die() {
err "$*"
exit 1
}
banner() {
title "π LaserSell Installer"
info "Install the LaserSell CLI on πͺ Windows (WSL), π macOS, π§ Linux, π Raspberry Pi (arm64)"
printf '%b\n' "${DIM}${BASE_URL}${RESET}"
}
on_error() {
local line="${1:-unknown}"
err "Installer failed (line ${line})."
info "Try re-running with: bash -x"
}
usage() {
cat <<EOF
π LaserSell installer
Usage:
curl -fsSL ${BASE_URL}/install.sh | bash
curl -fsSL ${BASE_URL}/install.sh | bash -s -- [options]
Options:
--method auto|apt|brew|tar Installation method (default: auto)
--version X.Y.Z Install a specific version (tar mode). If omitted, uses latest.txt.
--prefix DIR Install directory for tar mode (default: /usr/local/bin if writable, else ~/.local/bin)
--no-color Disable ANSI colors
-h, --help Show help
EOF
}
need_cmd() { command -v "$1" >/dev/null 2>&1 || die "missing required command: $1"; }
sudo_prefix() {
if [ "${EUID:-$(id -u)}" -eq 0 ]; then
echo ""
else
command -v sudo >/dev/null 2>&1 || die "sudo is required for this install method"
echo "sudo"
fi
}
detect_os() {
local s
s="$(uname -s | tr '[:upper:]' '[:lower:]')"
case "$s" in
linux) echo "linux" ;;
darwin) echo "darwin" ;;
*) die "unsupported OS: $(uname -s)" ;;
esac
}
detect_arch() {
local m
m="$(uname -m)"
case "$m" in
x86_64|amd64) echo "amd64" ;;
aarch64|arm64) echo "arm64" ;;
armv7l|armv6l|armhf)
die "32-bit ARM is not supported. Please use a 64-bit OS (arm64/aarch64) on Raspberry Pi."
;;
*) die "unsupported CPU arch: $m" ;;
esac
}
is_wsl() {
[ -r /proc/version ] && grep -qiE '(microsoft|wsl)' /proc/version
}
is_raspberry_pi() {
local model=""
if [ -r /proc/device-tree/model ]; then
model="$(tr -d '\0' </proc/device-tree/model)"
elif [ -r /sys/firmware/devicetree/base/model ]; then
model="$(tr -d '\0' </sys/firmware/devicetree/base/model)"
else
return 1
fi
echo "${model}" | grep -qi "raspberry pi"
}
apt_repo_supports_arch() {
local arch="$1"
local url="${BASE_URL}/dists/stable/main/binary-${arch}/Packages.gz"
need_cmd curl
if curl -fsSLI "${url}" >/dev/null 2>&1; then
return 0
fi
curl -fsSL "${url}" -o /dev/null >/dev/null 2>&1
}
install_via_apt() {
local arch="$1"
local sudo_cmd
sudo_cmd="$(sudo_prefix)"
need_cmd curl
if ! command -v apt-get >/dev/null 2>&1; then
die "apt-get not found (use --method tar instead)"
fi
info "Installing via APT (arch=${arch})"
step "[1/5] Update apt indexβ¦"
${sudo_cmd} apt-get update -y
ok "Apt index updated"
step "[2/5] Install dependencies (curl, gnupg)β¦"
${sudo_cmd} apt-get install -y curl gnupg
ok "Dependencies installed"
step "[3/5] Add signing key π"
curl -fsSL "${BASE_URL}/lasersell.asc" | ${sudo_cmd} gpg --dearmor -o /usr/share/keyrings/lasersell-archive-keyring.gpg
ok "Signing key added"
step "[4/5] Add APT source π§Ύ"
echo "deb [arch=${arch} signed-by=/usr/share/keyrings/lasersell-archive-keyring.gpg] ${BASE_URL} stable main" | ${sudo_cmd} tee /etc/apt/sources.list.d/lasersell.list >/dev/null
ok "APT source added"
step "[5/5] Install lasersell π¦"
${sudo_cmd} apt-get update -y
${sudo_cmd} apt-get install -y lasersell
ok "Installed: $(command -v lasersell) ($(lasersell --version 2>/dev/null || true))"
}
pick_prefix() {
local os="$1"
if [ -n "${PREFIX}" ]; then
echo "${PREFIX}"
return
fi
if [ "${EUID:-$(id -u)}" -eq 0 ]; then
echo "/usr/local/bin"
return
fi
if [ -w "/usr/local/bin" ]; then
echo "/usr/local/bin"
return
fi
echo "${HOME}/.local/bin"
}
sha256_file() {
if command -v sha256sum >/dev/null 2>&1; then
sha256sum "$1" | awk '{print $1}'
elif command -v shasum >/dev/null 2>&1; then
shasum -a 256 "$1" | awk '{print $1}'
else
die "need sha256sum or shasum for checksum verification"
fi
}
install_via_tar() {
local os="$1"
local arch="$2"
local version="$3"
need_cmd curl
need_cmd tar
info "Installing via tarball"
step "[1/5] Resolve version π"
if [ -z "${version}" ]; then
version="$(curl -fsSL "${BIN_BASE}/latest.txt" | tr -d ' \r\n')"
[ -n "${version}" ] || die "could not resolve latest version"
ok "Latest version ${version}"
else
ok "Using version ${version}"
fi
local filename="lasersell_${version}_${os}_${arch}.tar.gz"
local url="${BIN_BASE}/${version}/${filename}"
local sums_url="${BIN_BASE}/${version}/SHA256SUMS"
step "[2/5] Download tarball β¬οΈ"
local tmp
tmp="$(mktemp -d)"
trap 'rm -rf "${tmp}"' EXIT
curl -fsSL "${url}" -o "${tmp}/${filename}"
ok "Tarball downloaded"
step "[3/5] Download SHA256SUMS π§Ύ"
curl -fsSL "${sums_url}" -o "${tmp}/SHA256SUMS"
ok "Checksums downloaded"
step "[4/5] Verify checksum β
"
local expected
expected="$(grep " ${filename}$" "${tmp}/SHA256SUMS" | awk '{print $1}' || true)"
[ -n "${expected}" ] || die "checksum not found for ${filename}"
local actual
actual="$(sha256_file "${tmp}/${filename}")"
[ "${actual}" = "${expected}" ] || die "checksum mismatch for ${filename}"
ok "Checksum verified"
step "[5/5] Extract & install π¦"
tar -xzf "${tmp}/${filename}" -C "${tmp}"
[ -f "${tmp}/lasersell" ] || die "tarball did not contain lasersell binary"
chmod +x "${tmp}/lasersell"
local dest
dest="$(pick_prefix "${os}")"
mkdir -p "${dest}"
if [ -w "${dest}" ]; then
install -m 0755 "${tmp}/lasersell" "${dest}/lasersell"
else
local sudo_cmd
sudo_cmd="$(sudo_prefix)"
${sudo_cmd} install -m 0755 "${tmp}/lasersell" "${dest}/lasersell"
fi
ok "Installed: ${dest}/lasersell ($("${dest}/lasersell" --version 2>/dev/null || true))"
printf '\n'
title "Next steps"
info "Run: lasersell --help"
if ! echo ":$PATH:" | grep -q ":${dest}:"; then
warn "${dest} is not on your PATH. Add this to your shell profile:"
printf ' export PATH="%s:$PATH"\n' "${dest}"
fi
}
install_via_brew() {
need_cmd brew
info "π Using Homebrew"
step "Install lasersell"
brew install lasersell/lasersell/lasersell
ok "Installed: $(command -v lasersell) ($(lasersell --version 2>/dev/null || true))"
}
init_colors
# arg parsing
while [ "${#}" -gt 0 ]; do
case "$1" in
--method) METHOD="${2:-}"; shift 2 ;;
--version) VERSION="${2:-}"; shift 2 ;;
--prefix) PREFIX="${2:-}"; shift 2 ;;
--no-color) NO_COLOR_FLAG=1; init_colors; shift ;;
-h|--help) usage; exit 0 ;;
--) shift; break ;;
*) die "unknown arg: $1" ;;
esac
done
trap 'on_error $LINENO' ERR
banner
OS="$(detect_os)"
ARCH="$(detect_arch)"
IS_WSL=0
IS_PI=0
if is_wsl; then
IS_WSL=1
fi
if is_raspberry_pi; then
IS_PI=1
fi
if [ "${IS_WSL}" -eq 1 ]; then
info "π Environment: πͺ Windows (WSL) (${ARCH})"
elif [ "${OS}" = "darwin" ]; then
info "π Environment: π macOS (${ARCH})"
elif [ "${IS_PI}" -eq 1 ]; then
info "π Environment: π Raspberry Pi (${OS}/${ARCH})"
else
info "π Environment: π§ Linux (${ARCH})"
fi
case "${METHOD}" in
auto)
if [ "${OS}" = "linux" ]; then
if command -v apt-get >/dev/null 2>&1; then
if apt_repo_supports_arch "${ARCH}"; then
step "Selecting install method: APT"
install_via_apt "${ARCH}"
else
warn "APT repo doesnβt provide packages for ${ARCH} β using tarball install instead."
step "Selecting install method: tarball"
install_via_tar "${OS}" "${ARCH}" "${VERSION}"
fi
else
step "Selecting install method: tarball"
install_via_tar "${OS}" "${ARCH}" "${VERSION}"
fi
else
if command -v brew >/dev/null 2>&1; then
step "Selecting install method: Homebrew"
install_via_brew
else
step "Selecting install method: tarball"
install_via_tar "${OS}" "${ARCH}" "${VERSION}"
fi
fi
;;
apt)
[ "${OS}" = "linux" ] || die "--method apt only supported on Linux/WSL"
if ! apt_repo_supports_arch "${ARCH}"; then
die "APT packages are not available for ${ARCH}. Re-run with --method tar."
fi
step "Selecting install method: APT"
install_via_apt "${ARCH}"
;;
brew)
[ "${OS}" = "darwin" ] || die "--method brew only supported on macOS"
step "Selecting install method: Homebrew"
install_via_brew
;;
tar)
step "Selecting install method: tarball"
install_via_tar "${OS}" "${ARCH}" "${VERSION}"
;;
*)
die "invalid --method: ${METHOD}"
;;
esac