-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·73 lines (58 loc) · 1.62 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·73 lines (58 loc) · 1.62 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
#!/usr/bin/env bash
set -euo pipefail
XPM_PKG_URL_DEFAULT="https://xscriptor.github.io/x-repo/x/x86_64/xpm-0.1.0-3-x86_64.xp"
XPM_PKG_URL="${XPM_PKG_URL:-$XPM_PKG_URL_DEFAULT}"
INSTALL_PREFIX="${INSTALL_PREFIX:-/usr/local}"
BIN_DEST="$INSTALL_PREFIX/bin/xpm"
need_cmd() {
if ! command -v "$1" >/dev/null 2>&1; then
echo "error: required command '$1' not found" >&2
exit 1
fi
}
download_file() {
local url="$1"
local out="$2"
if command -v curl >/dev/null 2>&1; then
curl -fsSL "$url" -o "$out"
return
fi
if command -v wget >/dev/null 2>&1; then
wget -qO "$out" "$url"
return
fi
echo "error: neither curl nor wget is available" >&2
exit 1
}
main() {
need_cmd tar
need_cmd install
local tmp
tmp="$(mktemp -d)"
trap 'rm -rf "$tmp"' EXIT
local pkg="$tmp/xpm.xp"
local rootfs="$tmp/rootfs"
mkdir -p "$rootfs"
echo "==> Downloading $XPM_PKG_URL"
download_file "$XPM_PKG_URL" "$pkg"
echo "==> Extracting package"
tar --zstd -xpf "$pkg" -C "$rootfs"
if [[ ! -f "$rootfs/usr/bin/xpm" ]]; then
echo "error: package does not contain usr/bin/xpm" >&2
exit 1
fi
echo "==> Installing to $BIN_DEST"
if [[ "$(id -u)" -eq 0 ]]; then
install -Dm755 "$rootfs/usr/bin/xpm" "$BIN_DEST"
elif command -v sudo >/dev/null 2>&1; then
sudo install -Dm755 "$rootfs/usr/bin/xpm" "$BIN_DEST"
else
echo "error: root privileges required (run as root or install sudo)" >&2
exit 1
fi
echo "==> xpm installed successfully"
echo " version: $("$BIN_DEST" --version 2>/dev/null || echo unknown)"
echo
echo "Tip: set XPM_PKG_URL to install another build."
}
main "$@"