Repository navigation
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·144 lines (125 loc) · 4.01 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·144 lines (125 loc) · 4.01 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
#!/bin/sh
# Install create-erxes-plugin as a standalone binary (no Node.js required).
#
# curl -fsSL https://raw.githubusercontent.com/erxes/create-erxes-plugin/main/install.sh | sh
# curl -fsSL https://raw.githubusercontent.com/erxes/create-erxes-plugin/main/install.sh | sh -s -- --version 0.2.0 --dir ~/bin
set -eu
REPO="erxes/create-erxes-plugin"
BIN="create-erxes-plugin"
say() { printf '%s\n' "$*"; }
fail() { printf 'install.sh: %s\n' "$*" >&2; exit 1; }
need() { command -v "$1" >/dev/null 2>&1; }
usage() {
cat <<EOF
Usage: install.sh [--version <v>] [--dir <path>]
--version <v> release to install (default: latest)
--dir <path> install directory (default: /usr/local/bin, else ~/.local/bin)
Environment overrides: CREATE_ERXES_PLUGIN_VERSION, CREATE_ERXES_PLUGIN_INSTALL_DIR
EOF
}
fetch() {
if need curl; then
curl -fsSL "$1" -o "$2"
elif need wget; then
wget -qO "$2" "$1"
else
fail "curl or wget is required"
fi
}
main() {
version="${CREATE_ERXES_PLUGIN_VERSION:-}"
dir="${CREATE_ERXES_PLUGIN_INSTALL_DIR:-}"
base_url="${CREATE_ERXES_PLUGIN_BASE_URL:-https://github.com/$REPO/releases}"
while [ $# -gt 0 ]; do
case "$1" in
--version)
[ $# -ge 2 ] || fail "--version requires a value"
version="$2"; shift 2 ;;
--version=*) version="${1#*=}"; shift ;;
--dir)
[ $# -ge 2 ] || fail "--dir requires a value"
dir="$2"; shift 2 ;;
--dir=*) dir="${1#*=}"; shift ;;
-h | --help) usage; exit 0 ;;
*) usage >&2; fail "unknown argument: $1" ;;
esac
done
case "$(uname -s)" in
Linux)
os=linux
if ldd --version 2>&1 | grep -qi musl; then libc=-musl; else libc=; fi ;;
Darwin) os=darwin; libc= ;;
MINGW* | MSYS* | CYGWIN*) os=windows; libc= ;;
*) fail "unsupported OS $(uname -s) — use npx $BIN instead" ;;
esac
case "$(uname -m)" in
x86_64 | amd64) arch=x64 ;;
aarch64 | arm64) arch=arm64 ;;
*) fail "unsupported architecture $(uname -m) — use npx $BIN instead" ;;
esac
if [ "$os" = windows ] && [ "$arch" != x64 ]; then
fail "only x64 Windows builds are published — use npx $BIN instead"
fi
target="$os-$arch$libc"
if [ "$os" = windows ]; then
asset="$BIN-$target.zip"
exe="$BIN.exe"
need unzip || fail "unzip is required on Windows — install it or use npx $BIN"
else
asset="$BIN-$target.tar.gz"
exe="$BIN"
fi
if [ -z "$dir" ]; then
if [ -d /usr/local/bin ] && [ -w /usr/local/bin ]; then
dir=/usr/local/bin
else
dir="$HOME/.local/bin"
fi
fi
mkdir -p "$dir"
version="${version#v}"
if [ -n "$version" ]; then
release="$base_url/download/v$version"
else
release="$base_url/latest/download"
fi
tmp=$(mktemp -d)
trap 'rm -rf "$tmp"' EXIT
say "Downloading $BIN $target..."
fetch "$release/$asset" "$tmp/$asset" || fail "download failed: $release/$asset"
if fetch "$release/SHA256SUMS" "$tmp/SHA256SUMS" 2>/dev/null; then
if need sha256sum; then
actual=$(sha256sum "$tmp/$asset" | cut -d' ' -f1)
elif need shasum; then
actual=$(shasum -a 256 "$tmp/$asset" | cut -d' ' -f1)
else
actual=
say "warning: neither sha256sum nor shasum found; skipping checksum verification"
fi
if [ -n "$actual" ]; then
expected=$(awk -v f="$asset" '$NF == f {print $1}' "$tmp/SHA256SUMS")
[ -n "$expected" ] || fail "SHA256SUMS has no entry for $asset"
[ "$actual" = "$expected" ] || fail "checksum mismatch for $asset"
say "Checksum verified."
fi
else
say "warning: could not download SHA256SUMS; skipping checksum verification"
fi
mkdir -p "$tmp/x"
if [ "$os" = windows ]; then
unzip -q "$tmp/$asset" -d "$tmp/x"
else
tar -xzf "$tmp/$asset" -C "$tmp/x"
fi
chmod +x "$tmp/x/$exe"
mv -f "$tmp/x/$exe" "$dir/$exe"
say "Installed $dir/$exe"
say "version: $("$dir/$exe" --version)"
case ":$PATH:" in
*":$dir:"*) ;;
*)
say "Note: $dir is not in your PATH. Add it with:"
say " export PATH=\"$dir:\$PATH\"" ;;
esac
}
main "$@"