-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·253 lines (215 loc) · 8.07 KB
/
install.sh
File metadata and controls
executable file
·253 lines (215 loc) · 8.07 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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
#!/bin/sh
# Install script for putup — a build system using Tupfile syntax.
# Usage: curl -fsSL https://raw.githubusercontent.com/typeless/putup/main/install.sh | sh
#
# Options (environment variables):
# PUTUP_VERSION=v0.1.0 Install a specific version (default: latest)
# PUTUP_INSTALL_DIR=/usr/local/bin Install to a custom directory (default: ~/.local/bin)
set -eu
GITHUB_REPO="typeless/putup"
BASE_URL="https://github.com/${GITHUB_REPO}"
# --- Output helpers ---
if test -t 1; then
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
CYAN='\033[0;36m'
BOLD='\033[1m'
RESET='\033[0m'
else
RED='' GREEN='' YELLOW='' CYAN='' BOLD='' RESET=''
fi
info() { printf "${CYAN}info${RESET} %s\n" "$*"; }
warn() { printf "${YELLOW}warn${RESET} %s\n" "$*" >&2; }
err() { printf "${RED}error${RESET} %s\n" "$*" >&2; }
success() { printf "${GREEN}done${RESET} %s\n" "$*"; }
# --- Root check ---
check_root() {
if test "$(id -u)" -eq 0; then
warn "Running as root. putup installs to ~/.local/bin by default (no root needed)."
warn "Set PUTUP_INSTALL_DIR=/usr/local/bin if you intend a system-wide install."
fi
}
# --- Platform detection ---
detect_platform() {
OS=$(uname -s)
ARCH=$(uname -m)
case "${OS}" in
Linux)
case "${ARCH}" in
x86_64) BINARY_NAME="putup-linux-x86_64" ;;
aarch64) err "Linux arm64/aarch64 binaries are not yet available."
err "Build from source: ${BASE_URL}/blob/main/INSTALL.md"
exit 1 ;;
*) err "Unsupported Linux architecture: ${ARCH}"
exit 1 ;;
esac
;;
Darwin)
case "${ARCH}" in
arm64) BINARY_NAME="putup-macos-arm64" ;;
x86_64) err "Intel Mac (x86_64) binaries are not available."
err "Only Apple Silicon (arm64) is supported."
exit 1 ;;
*) err "Unsupported macOS architecture: ${ARCH}"
exit 1 ;;
esac
;;
MINGW*|MSYS*|CYGWIN*)
case "${ARCH}" in
x86_64) BINARY_NAME="putup-windows-x86_64.exe" ;;
*) err "Unsupported Windows architecture: ${ARCH}"
exit 1 ;;
esac
;;
*)
err "Unsupported operating system: ${OS}"
err "Build from source: ${BASE_URL}/blob/main/INSTALL.md"
exit 1
;;
esac
info "Detected platform: ${OS} ${ARCH}"
}
# --- Version resolution ---
resolve_version() {
if test -n "${PUTUP_VERSION:-}"; then
VERSION="${PUTUP_VERSION}"
case "${VERSION}" in
v*) ;;
*) VERSION="v${VERSION}" ;;
esac
info "Using specified version: ${VERSION}"
return
fi
info "Resolving latest version..."
tmpversion=$(mktemp)
if ! download "https://api.github.com/repos/${GITHUB_REPO}/releases/latest" "${tmpversion}" 2>/dev/null; then
rm -f "${tmpversion}"
err "Failed to query GitHub API for latest release."
err "Set PUTUP_VERSION=vX.Y.Z to skip the API query."
err "Or build from source: ${BASE_URL}/blob/main/INSTALL.md"
exit 1
fi
VERSION=$(sed -n 's/.*"tag_name": *"\([^"]*\)".*/\1/p' "${tmpversion}" | head -1)
rm -f "${tmpversion}"
if test -z "${VERSION}"; then
err "No releases found. The project may not have published binaries yet."
err "Build from source: ${BASE_URL}/blob/main/INSTALL.md"
exit 1
fi
info "Latest version: ${VERSION}"
}
# --- Download abstraction ---
download() {
url="$1"
output="$2"
if command -v curl >/dev/null 2>&1; then
curl -fsSL --retry 3 --retry-delay 2 -o "${output}" "${url}"
elif command -v wget >/dev/null 2>&1; then
wget -q --tries=3 -O "${output}" "${url}"
else
err "Neither curl nor wget found. Install one and try again."
exit 1
fi
}
# --- Checksum abstraction ---
compute_sha256() {
file="$1"
if command -v sha256sum >/dev/null 2>&1; then
sha256sum "${file}" | cut -d' ' -f1
elif command -v shasum >/dev/null 2>&1; then
shasum -a 256 "${file}" | cut -d' ' -f1
else
echo ""
fi
}
# --- Main ---
main() {
printf "\n${BOLD}putup installer${RESET}\n\n"
check_root
detect_platform
resolve_version
INSTALL_DIR="${PUTUP_INSTALL_DIR:-${HOME:?HOME is not set. Use PUTUP_INSTALL_DIR to specify an install location.}/.local/bin}"
mkdir -p "${INSTALL_DIR}"
RELEASE_URL="${BASE_URL}/releases/download/${VERSION}"
tmpdir=$(mktemp -d 2>/dev/null || { t="/tmp/putup-install-$$"; mkdir -p "$t"; echo "$t"; })
trap 'rm -rf "${tmpdir}"' EXIT INT TERM
# Download checksums (non-fatal if missing)
SKIP_CHECKSUM=0
if ! download "${RELEASE_URL}/sha256sums.txt" "${tmpdir}/sha256sums.txt" 2>/dev/null; then
warn "Checksums not available for this release. Skipping verification."
SKIP_CHECKSUM=1
fi
# Download binary
info "Downloading ${BINARY_NAME} ${VERSION}..."
if ! download "${RELEASE_URL}/${BINARY_NAME}" "${tmpdir}/${BINARY_NAME}"; then
err "Failed to download binary from:"
err " ${RELEASE_URL}/${BINARY_NAME}"
err ""
err "Check that version ${VERSION} exists and has binaries attached."
err "Available releases: ${BASE_URL}/releases"
exit 1
fi
# Verify checksum
if test "${SKIP_CHECKSUM}" -eq 0; then
actual=$(compute_sha256 "${tmpdir}/${BINARY_NAME}")
if test -z "${actual}"; then
warn "No sha256 tool found. Skipping checksum verification."
else
expected=$(grep " ${BINARY_NAME}\$" "${tmpdir}/sha256sums.txt" | cut -d' ' -f1)
if test -z "${expected}"; then
warn "Binary not found in checksums file. Skipping verification."
elif test "${actual}" != "${expected}"; then
err "Checksum verification FAILED!"
err " Expected: ${expected}"
err " Actual: ${actual}"
err "The download may be corrupted or tampered with."
exit 1
else
info "Checksum verified."
fi
fi
fi
# Install binary (use .exe on Windows)
case "${OS}" in
MINGW*|MSYS*|CYGWIN*)
EXE_NAME="putup.exe"
ALIAS_NAME="pup.exe"
;;
*)
EXE_NAME="putup"
ALIAS_NAME="pup"
;;
esac
install -m 755 "${tmpdir}/${BINARY_NAME}" "${INSTALL_DIR}/${EXE_NAME}"
# Create pup symlink/copy
ln -sf "${EXE_NAME}" "${INSTALL_DIR}/${ALIAS_NAME}" 2>/dev/null \
|| cp "${INSTALL_DIR}/${EXE_NAME}" "${INSTALL_DIR}/${ALIAS_NAME}"
# Verify
if "${INSTALL_DIR}/${EXE_NAME}" --version >/dev/null 2>&1; then
installed_version=$("${INSTALL_DIR}/${EXE_NAME}" --version | head -1)
success "Installed ${installed_version} to ${INSTALL_DIR}/${EXE_NAME}"
else
warn "Binary installed but failed to execute. Check platform compatibility."
fi
# PATH check
case ":${PATH}:" in
*":${INSTALL_DIR}:"*)
;;
*)
printf "\n"
warn "${INSTALL_DIR} is not in your PATH."
shell_name=$(basename "${SHELL:-/bin/sh}")
case "${shell_name}" in
zsh) printf " Add to ~/.zshrc: ${BOLD}export PATH=\"%s:\$PATH\"${RESET}\n" "${INSTALL_DIR}" ;;
bash) printf " Add to ~/.bashrc: ${BOLD}export PATH=\"%s:\$PATH\"${RESET}\n" "${INSTALL_DIR}" ;;
fish) printf " Run: ${BOLD}fish_add_path %s${RESET}\n" "${INSTALL_DIR}" ;;
*) printf " Add to your shell profile: ${BOLD}export PATH=\"%s:\$PATH\"${RESET}\n" "${INSTALL_DIR}" ;;
esac
;;
esac
printf "\n${BOLD}Get started:${RESET}\n"
printf " putup --help\n"
printf " ${CYAN}${BASE_URL}/blob/main/docs/reference.md${RESET}\n\n"
}
main