Repository navigation
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·150 lines (126 loc) · 4.67 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·150 lines (126 loc) · 4.67 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
#!/bin/sh
# Install warmbox from a GitHub release.
#
# curl -fsSL https://raw.githubusercontent.com/Daviduche03/warmbox/master/install.sh | sh
#
# That URL picks which copy of this script runs; it does NOT pick which version
# gets installed. With WARMBOX_VERSION unset the script asks GitHub for the
# newest release. To pin both, take the script from a tag and ask for the same
# tag explicitly:
#
# curl -fsSL https://raw.githubusercontent.com/Daviduche03/warmbox/v0.3.0/install.sh \
# | WARMBOX_VERSION=v0.3.0 sh
#
# The archive is verified against the release's checksums.txt *before* anything
# is written, so a corrupt or tampered download installs nothing.
#
# Environment:
# WARMBOX_VERSION tag to install (default: the latest release)
# WARMBOX_PREFIX where to put the binary (default: /usr/local/bin when
# running as root, otherwise ~/.local/bin)
# WARMBOX_REPO owner/repo to install from (default Daviduche03/warmbox)
#
# What this does NOT do: download the guest image. That is ~800 MB and warmbox
# fetches it itself, verified, on the next `warmbox setup`.
set -eu
REPO="${WARMBOX_REPO:-Daviduche03/warmbox}"
VERSION="${WARMBOX_VERSION:-}"
PREFIX="${WARMBOX_PREFIX:-}"
die() {
printf 'install: %s\n' "$1" >&2
exit 1
}
have() { command -v "$1" >/dev/null 2>&1; }
have curl || die "curl is required"
have tar || die "tar is required"
# --- what are we installing on? ---
os=$(uname -s)
arch=$(uname -m)
case "$os" in
Darwin) os=darwin ;;
Linux) os=linux ;;
*) die "unsupported OS: $os — warmbox runs on macOS (Apple Silicon) or Linux with KVM" ;;
esac
case "$arch" in
arm64 | aarch64) arch=arm64 ;;
x86_64 | amd64) arch=amd64 ;;
*) die "unsupported architecture: $arch" ;;
esac
if [ "$os" = darwin ] && [ "$arch" = amd64 ]; then
die "Intel Macs are not supported: vfkit needs Apple Silicon (guests are ARM64 only)"
fi
fetch() { # url dest
curl -fSL --progress-bar "$1" -o "$2"
}
get() { # url -> stdout
curl -fsSL "$1"
}
# --- which version? ---
if [ -z "$VERSION" ]; then
# Not /releases/latest: we also publish the guest images under a fixed
# "images" tag, and if GitHub marks that release as Latest it would resolve
# to a tag with no binary. Ask for the newest version tag instead.
VERSION=$(get "https://api.github.com/repos/${REPO}/releases?per_page=30" |
sed -n 's/.*"tag_name":[[:space:]]*"\(v[0-9][^"]*\)".*/\1/p' | head -1)
[ -n "$VERSION" ] || die "could not find a released version of ${REPO}"
fi
# Release assets drop the leading v from the tag.
bare=${VERSION#v}
asset="warmbox_${bare}_${os}_${arch}.tar.gz"
base="https://github.com/${REPO}/releases/download/${VERSION}"
tmp=$(mktemp -d)
trap 'rm -rf "$tmp"' EXIT INT TERM
echo "warmbox ${VERSION} for ${os}/${arch}"
fetch "${base}/${asset}" "${tmp}/${asset}" || die "download failed: ${base}/${asset}"
fetch "${base}/checksums.txt" "${tmp}/checksums.txt" || die "could not fetch checksums.txt"
# --- verify before touching the system ---
want=$(sed -n "s/^\([0-9a-f]\{64\}\)[[:space:]]\{1,\}[*]\{0,1\}${asset}\$/\1/p" "${tmp}/checksums.txt" | head -1)
[ -n "$want" ] || die "no checksum for ${asset} in checksums.txt"
if have sha256sum; then
got=$(sha256sum "${tmp}/${asset}" | awk '{print $1}')
else
have shasum || die "need sha256sum or shasum to verify the download"
got=$(shasum -a 256 "${tmp}/${asset}" | awk '{print $1}')
fi
if [ "$got" != "$want" ]; then
die "checksum mismatch for ${asset}
got ${got}
want ${want}
Refusing to install."
fi
echo "checksum ok"
# --- install ---
if [ -z "$PREFIX" ]; then
if [ "$(id -u)" = 0 ]; then
PREFIX=/usr/local/bin
else
PREFIX="${HOME}/.local/bin"
fi
fi
tar -xzf "${tmp}/${asset}" -C "$tmp"
[ -f "${tmp}/warmbox" ] || die "archive did not contain a warmbox binary"
mkdir -p "$PREFIX"
cp "${tmp}/warmbox" "${PREFIX}/warmbox"
chmod 0755 "${PREFIX}/warmbox"
# macOS kills an arm64 binary whose signature the copy invalidated.
if [ "$os" = darwin ] && have codesign; then
codesign --force --sign - "${PREFIX}/warmbox" >/dev/null 2>&1 ||
echo "install: warning: could not re-sign the binary; if it refuses to run, run: codesign --force --sign - ${PREFIX}/warmbox" >&2
fi
echo "installed ${PREFIX}/warmbox"
case ":${PATH}:" in
*":${PREFIX}:"*) ;;
*)
echo
echo "note: ${PREFIX} is not on your PATH. Add it:"
echo " export PATH=\"${PREFIX}:\$PATH\""
;;
esac
cat <<'EOS'
next:
warmbox setup # check the host, then noVNC + the guest image
warmbox service install --pool 1 # run the daemon in the background
The dashboard binds 127.0.0.1:7070 — it is plaintext HTTP, so keep it off the
network. On a remote machine, tunnel to it instead:
ssh -L 7070:127.0.0.1:7070 <user>@<this-host> # then open http://localhost:7070
EOS