-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·131 lines (117 loc) · 4.47 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·131 lines (117 loc) · 4.47 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
#!/usr/bin/env bash
#
# esrun installer for Linux and macOS.
#
# curl -fsSL https://raw.githubusercontent.com/Open-Tech-Foundation/ES-Runtime/main/install.sh | bash
#
# Downloads the latest released `esrun` binary for your platform, verifies its
# SHA-256 checksum, and installs it to ~/.esrun/bin. Override the version with
# ESRUN_VERSION=v0.1.0 and the install dir with ESRUN_INSTALL=/custom/path.
set -euo pipefail
REPO="Open-Tech-Foundation/ES-Runtime"
INSTALL_DIR="${ESRUN_INSTALL:-$HOME/.esrun}"
BIN_DIR="$INSTALL_DIR/bin"
red() { printf '\033[31m%s\033[0m\n' "$*"; }
bold() { printf '\033[1m%s\033[0m\n' "$*"; }
dim() { printf '\033[2m%s\033[0m\n' "$*"; }
err() {
red "error: $*" >&2
exit 1
}
command -v curl >/dev/null 2>&1 || err "curl is required"
command -v tar >/dev/null 2>&1 || err "tar is required"
# --- detect platform --------------------------------------------------------
os="$(uname -s)"
arch="$(uname -m)"
case "$os" in
Linux) os_part="unknown-linux-gnu" ;;
Darwin) os_part="apple-darwin" ;;
*) err "unsupported OS: $os (use install.ps1 on Windows)" ;;
esac
case "$arch" in
x86_64 | amd64) arch_part="x86_64" ;;
arm64 | aarch64) arch_part="aarch64" ;;
*) err "unsupported architecture: $arch" ;;
esac
target="${arch_part}-${os_part}"
# --- resolve version --------------------------------------------------------
version="${ESRUN_VERSION:-}"
if [ -z "$version" ]; then
version="$(curl -fsSL "https://api.github.com/repos/$REPO/releases/latest" |
grep -oE '"tag_name": *"[^"]+"' | head -1 | cut -d'"' -f4)"
[ -n "$version" ] || err "could not determine the latest release (set ESRUN_VERSION)"
fi
ver_no_v="${version#v}"
name="esrun-${ver_no_v}-${target}"
url="https://github.com/$REPO/releases/download/${version}/${name}.tar.gz"
bold "Installing esrun ${version} (${target})"
dim " from $url"
# --- download + verify ------------------------------------------------------
tmp="$(mktemp -d)"
trap 'rm -rf "$tmp"' EXIT
curl -fSL --progress-bar "$url" -o "$tmp/$name.tar.gz" ||
err "download failed — is there a release asset for $target?"
# Checksums live in one `checksums.txt` per release (`<hash> <archive>` lines);
# pull out the line for our archive and verify it.
sums_url="https://github.com/$REPO/releases/download/${version}/checksums.txt"
if curl -fsSL "$sums_url" -o "$tmp/checksums.txt" 2>/dev/null &&
grep " ${name}.tar.gz\$" "$tmp/checksums.txt" > "$tmp/$name.tar.gz.sha256"; then
if command -v shasum >/dev/null 2>&1; then
(cd "$tmp" && shasum -a 256 -c "$name.tar.gz.sha256" >/dev/null) ||
err "checksum verification failed"
elif command -v sha256sum >/dev/null 2>&1; then
(cd "$tmp" && sha256sum -c "$name.tar.gz.sha256" >/dev/null) ||
err "checksum verification failed"
fi
dim " checksum verified"
fi
# --- install ----------------------------------------------------------------
tar -xzf "$tmp/$name.tar.gz" -C "$tmp"
mkdir -p "$BIN_DIR"
install -m 0755 "$tmp/$name/esrun" "$BIN_DIR/esrun"
bold ""
bold "esrun was installed to $BIN_DIR/esrun"
# Suggest a PATH entry if it isn't already there.
case ":$PATH:" in
*":$BIN_DIR:"*) ;;
*)
if [ -t 0 ] || [ -c /dev/tty ]; then
echo
printf "Would you like to add esrun to your shell profile automatically? [y/N] "
if read -r ans < /dev/tty && { [ "$ans" = "y" ] || [ "$ans" = "Y" ]; }; then
shell_profile=""
case "${SHELL:-}" in
*/zsh) shell_profile="$HOME/.zshrc" ;;
*/bash) shell_profile="$HOME/.bashrc" ;;
*)
if [ -f "$HOME/.bashrc" ]; then shell_profile="$HOME/.bashrc"
elif [ -f "$HOME/.zshrc" ]; then shell_profile="$HOME/.zshrc"
elif [ -f "$HOME/.profile" ]; then shell_profile="$HOME/.profile"
fi
;;
esac
if [ -n "$shell_profile" ]; then
echo "" >> "$shell_profile"
echo "# esrun" >> "$shell_profile"
echo "export PATH=\"$BIN_DIR:\$PATH\"" >> "$shell_profile"
echo
bold "Added PATH to $shell_profile"
dim "Restart your terminal or run: source $shell_profile"
else
echo
echo "Could not determine shell profile. Please add it manually:"
bold " export PATH=\"$BIN_DIR:\$PATH\""
fi
else
echo
echo "Please add it manually:"
bold " export PATH=\"$BIN_DIR:\$PATH\""
fi
else
echo "Please add it manually:"
bold " export PATH=\"$BIN_DIR:\$PATH\""
fi
;;
esac
echo
dim "Run 'esrun --version' to verify."