Repository navigation
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·218 lines (183 loc) · 5.99 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·218 lines (183 loc) · 5.99 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
#!/bin/sh
# evp installer — downloads a prebuilt evp binary from the latest GitHub
# release.
#
# Usage:
# curl -sSfL https://github.com/HalFrgrd/evp/releases/latest/download/install.sh | sh
#
# Override the version (default `latest`):
# curl -sSfL .../install.sh | EVP_VERSION=v0.2.0 sh
#
# Override the default install dir:
# curl -sSfL .../install.sh | EVP_INSTALL_DIR=~/.local/bin sh
set -eu
expand_path() {
case "$1" in
'~/'*) echo "${HOME}/${1#~/}" ;;
'~') echo "${HOME}" ;;
*) echo "$1" ;;
esac
}
REPO="HalFrgrd/evp"
find_writable_path_dir() {
(
IFS=':'
for dir in $PATH; do
dir="${dir%/}"
if [ -n "$dir" ] && [ -d "$dir" ] && [ -w "$dir" ]; then
case "$dir" in
/bin|/sbin|/usr/bin|/usr/sbin|/lib*|/opt|/usr/lib*)
continue
;;
*)
echo "$dir"
exit 0
;;
esac
fi
done
exit 1
)
}
is_in_path() {
(
IFS=':'
for dir in $PATH; do
dir_abs="$(cd "$dir" 2>/dev/null && pwd || true)"
if [ -n "$dir_abs" ] && [ "$dir_abs" = "$1" ]; then
exit 0
fi
done
exit 1
)
}
if [ -n "${EVP_INSTALL_DIR:-}" ]; then
INSTALL_DIR="$(expand_path "$EVP_INSTALL_DIR")"
else
if W_DIR="$(find_writable_path_dir)"; then
INSTALL_DIR="$W_DIR"
else
if [ -w "/usr/local/bin" ]; then
INSTALL_DIR="/usr/local/bin"
else
INSTALL_DIR="${HOME}/.local/bin"
fi
fi
fi
VERSION_OVERRIDE="${EVP_VERSION:-}"
say() { printf '\033[1;34m==>\033[0m %s\n' "$*"; }
warn() { printf '\033[1;33mwarning:\033[0m %s\n' "$*" >&2; }
err() { printf '\033[1;31merror:\033[0m %s\n' "$*" >&2; exit 1; }
download() {
url="$1"; dest="$2"
if command -v curl >/dev/null 2>&1; then
curl -fsSL -o "$dest" "$url"
elif command -v wget >/dev/null 2>&1; then
wget -qO "$dest" "$url"
else
err "Neither curl nor wget is available."
fi
}
get_latest_version() {
url="https://github.com/${REPO}/releases/latest"
if command -v curl >/dev/null 2>&1; then
tag_url="$(curl -sI "$url" | grep -i '^location:' | head -1)"
elif command -v wget >/dev/null 2>&1; then
tag_url="$(wget --max-redirect=0 --server-response -O /dev/null "$url" 2>&1 | grep -i 'location:' | head -1)"
else
err "Neither curl nor wget is available. Please install one and retry."
fi
version="$(printf '%s' "$tag_url" | sed 's|.*/||' | cut -d' ' -f1 | tr -d '\r\n')"
[ -n "$version" ] || err "Could not determine latest version from GitHub Release redirect."
echo "$version"
}
verify_sha256() {
sha256_file="$1"
if command -v sha256sum >/dev/null 2>&1; then
sha256sum -c "$sha256_file"
elif command -v shasum >/dev/null 2>&1; then
shasum -a 256 -c "$sha256_file"
else
err "No checksum tool found (sha256sum or shasum). Cannot verify download."
fi
}
# --- Platform detection ----------------------------------------------------
OS="$(uname -s)"
ARCH="$(uname -m)"
case "$OS" in
Linux) os_tag="unknown-linux-musl" ;;
Darwin) os_tag="apple-darwin" ;;
FreeBSD) os_tag="unknown-freebsd" ;;
*)
err "Unsupported OS: $OS. Only Linux, macOS, and FreeBSD prebuilt binaries are published today.
Build from source instead: https://github.com/${REPO}#build-from-source"
;;
esac
case "$ARCH" in
x86_64|amd64) arch_tag="x86_64" ;;
arm64|aarch64) arch_tag="aarch64" ;;
*)
err "Unsupported architecture: $ARCH. Only x86_64 and aarch64 prebuilt binaries are published today.
Build from source instead: https://github.com/${REPO}#build-from-source"
;;
esac
# Validate supported combinations
case "${arch_tag}-${os_tag}" in
x86_64-unknown-linux-musl|aarch64-unknown-linux-musl|x86_64-apple-darwin|aarch64-apple-darwin|x86_64-unknown-freebsd)
;;
*)
err "Unsupported target platform: ${arch_tag}-${os_tag}.
Build from source instead: https://github.com/${REPO}#build-from-source"
;;
esac
TARGET="${arch_tag}-${os_tag}"
say "Detected target: ${TARGET}"
# --- Resolve release tag ---------------------------------------------------
if [ -n "$VERSION_OVERRIDE" ]; then
TAG="$VERSION_OVERRIDE"
say "Using specified release version: ${TAG}"
else
say "Fetching latest release info from github.com/${REPO}..."
TAG="$(get_latest_version)"
say "Latest version: ${TAG}"
fi
VERSION_NO_V="${TAG#v}"
STAGE="evp-${VERSION_NO_V}-${TARGET}"
ARCHIVE="${STAGE}.tar.gz"
URL="https://github.com/${REPO}/releases/download/${TAG}/${ARCHIVE}"
SHA_URL="${URL}.sha256"
# --- Download + verify -----------------------------------------------------
TMPDIR="$(mktemp -d)"
# shellcheck disable=SC2064
trap "rm -rf '$TMPDIR'" EXIT
say "Downloading ${ARCHIVE}..."
download "$URL" "${TMPDIR}/${ARCHIVE}"
if download "$SHA_URL" "${TMPDIR}/${ARCHIVE}.sha256" 2>/dev/null; then
say "Verifying checksum..."
(cd "$TMPDIR" && verify_sha256 "${ARCHIVE}.sha256") \
|| err "Checksum verification failed."
else
warn "No .sha256 published for ${TAG}; skipping verification."
fi
# --- Extract + install -----------------------------------------------------
tar -xzf "${TMPDIR}/${ARCHIVE}" -C "${TMPDIR}"
mkdir -p "$INSTALL_DIR"
install -m 755 "${TMPDIR}/${STAGE}/evp" "${INSTALL_DIR}/evp"
ABS_INSTALL_DIR=$(cd "$INSTALL_DIR" && pwd)
ABS_PWD=$(pwd)
if is_in_path "$ABS_INSTALL_DIR"; then
RUN_CMD="evp"
elif [ "$ABS_INSTALL_DIR" = "$ABS_PWD" ]; then
RUN_CMD="./evp"
else
RUN_CMD="${INSTALL_DIR}/evp"
fi
say "Installed: ${INSTALL_DIR}/evp"
"${INSTALL_DIR}/evp" --version | head -n1
cat <<EOF
Try it out:
${RUN_CMD} print-ref-script > demo.tape && ${RUN_CMD} demo.tape
# → writes ./evp-test.gif (a small built-in demo)
Or record your own terminal session:
${RUN_CMD} record --output demo.tape
EOF