-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathalpha_setup.sh
More file actions
executable file
·160 lines (135 loc) · 4.3 KB
/
alpha_setup.sh
File metadata and controls
executable file
·160 lines (135 loc) · 4.3 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
#!/usr/bin/env sh
set -euo pipefail
INSTALL_DIR="${WARP_PARSE_INSTALL_DIR:-$HOME/bin}"
REQUESTED_TAG="${WARP_PARSE_VERSION:-latest}"
MANIFEST_URL="${WARP_PARSE_MANIFEST_URL:-https://raw.githubusercontent.com/wp-labs/wp-install/main/updates/alpha/manifest.json}"
need_cmd() {
command -v "$1" >/dev/null 2>&1 || {
echo "[warp-parse] missing required command: $1" >&2
exit 1
}
}
need_cmd curl
need_cmd uname
need_cmd mktemp
need_cmd tar
need_cmd install
need_cmd find
need_cmd python3
need_cmd sed
sha256_check() {
expected="$1"
file="$2"
if command -v sha256sum >/dev/null 2>&1; then
printf '%s %s\n' "$expected" "$file" | sha256sum -c - >/dev/null
elif command -v shasum >/dev/null 2>&1; then
printf '%s %s\n' "$expected" "$file" | shasum -a 256 -c - >/dev/null
else
echo "[warp-parse:alpha] missing required command: sha256sum or shasum" >&2
exit 1
fi
}
OS=$(uname -s | tr '[:upper:]' '[:lower:]')
case "$OS" in
linux|darwin) : ;;
*)
echo "[warp-parse] unsupported OS: $OS" >&2
exit 1
;;
esac
ARCH=$(uname -m)
case "$ARCH" in
x86_64|amd64) ARCH="x86_64" ;;
arm64|aarch64) ARCH="arm64" ;;
*)
echo "[warp-parse] unsupported architecture: $ARCH" >&2
exit 1
;;
esac
TMP_DIR=$(mktemp -d)
MANIFEST_FILE=$(mktemp)
cleanup() {
rm -rf "$TMP_DIR"
rm -f "$MANIFEST_FILE"
}
trap cleanup EXIT
printf '[warp-parse:alpha] fetching manifest %s\n' "$MANIFEST_URL"
if ! curl -fsSL "$MANIFEST_URL" -o "$MANIFEST_FILE"; then
echo "[warp-parse:alpha] failed to download manifest" >&2
exit 1
fi
PY_OUT=$(python3 - "$REQUESTED_TAG" "$OS" "$ARCH" "$MANIFEST_FILE" <<'PY'
import json
import sys
requested = sys.argv[1]
os_key = sys.argv[2]
arch_key = sys.argv[3]
manifest_path = sys.argv[4]
with open(manifest_path, "r", encoding="utf-8") as fh:
data = json.load(fh)
version = data.get("version", "")
if not version:
sys.exit("manifest missing version")
def normalize(ver: str) -> str:
return ver if ver.startswith("v") else f"v{ver}"
resolved = normalize(version)
if requested != "latest" and normalize(requested) != resolved:
sys.exit(f"version '{requested}' not found in manifest (current: {resolved})")
target_map = {
("darwin", "arm64"): "aarch64-apple-darwin",
("darwin", "x86_64"): "x86_64-apple-darwin",
("linux", "arm64"): "aarch64-unknown-linux-gnu",
("linux", "x86_64"): "x86_64-unknown-linux-gnu",
}
target = target_map.get((os_key, arch_key))
if not target:
sys.exit(f"unsupported target combination: {os_key}-{arch_key}")
asset = data.get("assets", {}).get(target, {})
url = asset.get("url", "")
if not url:
sys.exit(f"no asset url entry for {target}")
sha256 = asset.get("sha256", "")
if not sha256:
sys.exit(f"no asset sha256 entry for {target}")
print(resolved)
print(url)
print(sha256)
PY
)
TAG=$(printf '%s' "$PY_OUT" | sed -n '1p')
DOWNLOAD_URL=$(printf '%s' "$PY_OUT" | sed -n '2p')
EXPECTED_SHA256=$(printf '%s' "$PY_OUT" | sed -n '3p')
if [ -z "$TAG" ] || [ -z "$DOWNLOAD_URL" ] || [ -z "$EXPECTED_SHA256" ]; then
echo "[warp-parse:alpha] failed to resolve download artifact" >&2
exit 1
fi
ASSET_NAME="${DOWNLOAD_URL##*/}"
ARCHIVE_PATH="$TMP_DIR/$ASSET_NAME"
printf '[warp-parse:alpha] downloading %s\n' "$DOWNLOAD_URL"
if ! curl -fL "$DOWNLOAD_URL" -o "$ARCHIVE_PATH"; then
echo "[warp-parse:alpha] download failed" >&2
exit 1
fi
printf '[warp-parse:alpha] verifying sha256 %s\n' "$ASSET_NAME"
if ! sha256_check "$EXPECTED_SHA256" "$ARCHIVE_PATH"; then
echo "[warp-parse:alpha] sha256 verification failed for $ASSET_NAME" >&2
exit 1
fi
tar -xzf "$ARCHIVE_PATH" -C "$TMP_DIR"
mkdir -p "$INSTALL_DIR"
BINARIES="wparse wpgen wprescue wproj"
INSTALLED=""
for bin in $BINARIES; do
BIN_PATH=$(find "$TMP_DIR" -maxdepth 3 -type f -name "$bin" | head -n 1)
if [ -n "$BIN_PATH" ]; then
install -m 755 "$BIN_PATH" "$INSTALL_DIR/$bin"
INSTALLED="$INSTALLED $bin"
fi
done
if [ -z "$INSTALLED" ]; then
echo "[warp-parse:alpha] no binaries were installed (archive layout unexpected)" >&2
exit 1
fi
printf '[warp-parse:alpha] installed binaries:%s\n' "$INSTALLED"
printf '[warp-parse:alpha] location: %s\n' "$INSTALL_DIR"
printf '\nEnsure %s is on your PATH, e.g.:\n export PATH="%s":$PATH\n\n' "$INSTALL_DIR" "$INSTALL_DIR"