-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·82 lines (71 loc) · 2.5 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·82 lines (71 loc) · 2.5 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
#!/bin/sh
set -eu
REPOSITORY="${POLYLAYER_CLI_REPOSITORY:-polylayer/polylayer-cli}"
INSTALL_DIR="${POLYLAYER_INSTALL_DIR:-${HOME}/.local/bin}"
LIB_DIR="${POLYLAYER_LIB_DIR:-${HOME}/.local/lib/polylayer-cli}"
VERSION="${POLYLAYER_VERSION:-latest}"
ARCHIVE="polylayer-cli.tar.gz"
CHECKSUMS="SHA256SUMS"
if ! command -v node >/dev/null 2>&1; then
printf '%s\n' "error: Polylayer CLI requires Node.js 18 or newer" >&2
exit 1
fi
NODE_MAJOR="$(node -p 'Number(process.versions.node.split(".")[0])')"
if [ "${NODE_MAJOR}" -lt 18 ]; then
printf '%s\n' "error: Polylayer CLI requires Node.js 18 or newer" >&2
exit 1
fi
if ! command -v curl >/dev/null 2>&1; then
printf '%s\n' "error: curl is required" >&2
exit 1
fi
if ! command -v sha256sum >/dev/null 2>&1 &&
! command -v shasum >/dev/null 2>&1; then
printf '%s\n' "error: sha256sum or shasum is required to verify the release" >&2
exit 1
fi
case "${VERSION}" in
latest)
RELEASE_URL="https://github.com/${REPOSITORY}/releases/latest/download"
;;
v*)
RELEASE_URL="https://github.com/${REPOSITORY}/releases/download/${VERSION}"
;;
*)
RELEASE_URL="https://github.com/${REPOSITORY}/releases/download/v${VERSION}"
;;
esac
TEMP_DIR="$(mktemp -d)"
trap 'rm -rf "${TEMP_DIR}"' EXIT INT TERM
curl -fsSL "${RELEASE_URL}/${ARCHIVE}" -o "${TEMP_DIR}/${ARCHIVE}"
curl -fsSL "${RELEASE_URL}/${CHECKSUMS}" -o "${TEMP_DIR}/${CHECKSUMS}"
(
cd "${TEMP_DIR}"
if command -v sha256sum >/dev/null 2>&1; then
sha256sum -c "${CHECKSUMS}"
else
shasum -a 256 -c "${CHECKSUMS}"
fi
)
tar -xzf "${TEMP_DIR}/${ARCHIVE}" -C "${TEMP_DIR}"
test -f "${TEMP_DIR}/polylayer.mjs"
test -f "${TEMP_DIR}/openapi.json"
mkdir -p "${INSTALL_DIR}"
mkdir -p "${LIB_DIR}"
if [ -e "${INSTALL_DIR}/polylayer" ] && [ ! -L "${INSTALL_DIR}/polylayer" ]; then
printf '%s\n' "error: ${INSTALL_DIR}/polylayer exists and is not a symlink; remove it explicitly first" >&2
exit 1
fi
if [ -e "${INSTALL_DIR}/plyr" ] && [ ! -L "${INSTALL_DIR}/plyr" ]; then
printf '%s\n' "error: ${INSTALL_DIR}/plyr exists and is not a symlink; remove it explicitly first" >&2
exit 1
fi
install -m 0755 "${TEMP_DIR}/polylayer.mjs" "${LIB_DIR}/polylayer.mjs"
install -m 0644 "${TEMP_DIR}/openapi.json" "${LIB_DIR}/openapi.json"
ln -sfn "${LIB_DIR}/polylayer.mjs" "${INSTALL_DIR}/polylayer"
ln -sfn "polylayer" "${INSTALL_DIR}/plyr"
printf '%s\n' "Installed polylayer and plyr to ${INSTALL_DIR}"
case ":${PATH}:" in
*":${INSTALL_DIR}:"*) ;;
*) printf '%s\n' "Add ${INSTALL_DIR} to PATH to run the CLI." ;;
esac