Repository navigation
Expand file tree
/
Copy pathinstall.sh
More file actions
265 lines (225 loc) · 8.36 KB
/
Copy pathinstall.sh
File metadata and controls
265 lines (225 loc) · 8.36 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
254
255
256
257
258
259
260
261
262
263
264
265
#!/usr/bin/env bash
set -euo pipefail
###############################################
# Optional arguments: --new-install / --upgrade / --cli
###############################################
INSTALL_FLAG="--install" # default mode
CLI_FLAG=""
while [[ $# -gt 0 ]]; do
case "$1" in
--new-install)
INSTALL_FLAG="--new-install"
;;
--install)
INSTALL_FLAG="--install"
;;
--upgrade)
# Swap in the freshly downloaded binary, then let THAT binary finalize the
# upgrade (--localfile skips the release check and download this script has
# already done). The plain `proxsave --upgrade` finalizes with the OLD binary,
# so any fix to the upgrade flow lands one release late; this route does not.
INSTALL_FLAG="--upgrade"
;;
--cli)
CLI_FLAG="--cli"
;;
*)
echo "❌ Unknown argument: $1"
exit 1
;;
esac
shift
done
###############################################
# 1) Ensure running as root
###############################################
if [ "$EUID" -ne 0 ]; then
echo "❌ Please run as root"
exit 1
fi
###############################################
# 2) Config
###############################################
REPO="tis24dev/proxsave"
TARGET_DIR="/opt/proxsave"
BUILD_DIR="${TARGET_DIR}/build"
TARGET_BIN="${BUILD_DIR}/proxsave"
# Pinned release-signing public key (ECDSA P-256). The matching private key lives
# only in the project's GitHub Actions secret, so an archive whose SHA256SUMS does
# not verify against this key is rejected. Fingerprint (sha256 of DER):
# fdbbba66cdb770b85a728c8aee0b920b4cd244c84f4fc5a0065188fbe9a5eddb
PUBKEY_PEM='-----BEGIN PUBLIC KEY-----
MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAElks05mPtm1vm0YtHlSGX1HlgdXjn
liDJEnB+RgiWOQR+6xLWeX7PyauuMxUh/HNnvBQAokK91fLWes4r9Xlwzw==
-----END PUBLIC KEY-----'
###############################################
# 3) OS/ARCH detection
###############################################
OS="$(uname -s | tr '[:upper:]' '[:lower:]')"
ARCH_RAW="$(uname -m)"
if [ "${OS}" != "linux" ]; then
echo "❌ Only Linux systems are supported"
exit 1
fi
case "$ARCH_RAW" in
x86_64) ARCH="amd64" ;;
*)
echo "❌ Unsupported architecture: ${ARCH_RAW} (only linux/amd64 is published; build from source for other architectures)"
exit 1
;;
esac
echo "--------------------------------------------"
echo " ProxSave Installer"
echo " Mode: ${INSTALL_FLAG}"
echo " OS: ${OS}"
echo " Arch: ${ARCH}"
echo " Dir: ${TARGET_DIR}"
echo "--------------------------------------------"
###############################################
# 4) HTTP helper (curl/wget)
###############################################
fetch() {
local url="$1"
if command -v curl >/dev/null 2>&1; then
curl -fsSL "${url}"
elif command -v wget >/dev/null 2>&1; then
wget -q -O - "${url}"
else
echo "❌ Neither curl nor wget is installed" >&2
exit 1
fi
}
download() {
local url="$1"
local out="$2"
fetch "${url}" > "${out}"
}
###############################################
# 5) Fetch latest release tag
###############################################
LATEST_JSON="$(fetch "https://api.github.com/repos/${REPO}/releases/latest")"
LATEST_TAG=""
if command -v jq >/dev/null 2>&1; then
LATEST_TAG="$(jq -r '.tag_name // empty' <<<"${LATEST_JSON}" 2>/dev/null || true)"
fi
if [ -z "${LATEST_TAG}" ] && [[ ${LATEST_JSON} =~ \"tag_name\"[[:space:]]*:[[:space:]]*\"([^\"]+)\" ]]; then
LATEST_TAG="${BASH_REMATCH[1]}"
fi
if [ -z "${LATEST_TAG}" ]; then
echo "❌ Could not detect latest release tag"
exit 1
fi
echo "📦 Latest tag: ${LATEST_TAG}"
VERSION="${LATEST_TAG#v}"
###############################################
# 6) Build correct filename (ARCHIVE)
###############################################
FILENAME="proxsave_${VERSION}_${OS}_${ARCH}.tar.gz"
BINARY_URL="https://github.com/${REPO}/releases/download/${LATEST_TAG}/${FILENAME}"
CHECKSUM_URL="https://github.com/${REPO}/releases/download/${LATEST_TAG}/SHA256SUMS"
SIG_URL="https://github.com/${REPO}/releases/download/${LATEST_TAG}/SHA256SUMS.sig"
echo "➡ Archive URL: ${BINARY_URL}"
echo "➡ Checksum URL: ${CHECKSUM_URL}"
echo "➡ Signature URL: ${SIG_URL}"
###############################################
# 7) Prepare directories
###############################################
mkdir -p "${BUILD_DIR}"
TMP_DIR="$(mktemp -d)"
trap 'rm -rf "${TMP_DIR}"' EXIT
cd "${TMP_DIR}"
###############################################
# 8) Download archive, checksum and signature
###############################################
echo "[+] Downloading archive..."
download "${BINARY_URL}" "${FILENAME}"
echo "[+] Downloading SHA256SUMS..."
download "${CHECKSUM_URL}" "SHA256SUMS"
echo "[+] Downloading SHA256SUMS.sig..."
if ! download "${SIG_URL}" "SHA256SUMS.sig"; then
echo "❌ Could not download SHA256SUMS.sig for ${LATEST_TAG}"
echo " Refusing to install without a verifiable release signature."
exit 1
fi
###############################################
# 9) Verify SHA256SUMS signature (authenticity)
###############################################
echo "[+] Verifying SHA256SUMS signature..."
if ! command -v openssl >/dev/null 2>&1; then
echo "❌ openssl is required to verify the release signature"
exit 1
fi
printf '%s\n' "${PUBKEY_PEM}" > pubkey.pem
if ! openssl dgst -sha256 -verify pubkey.pem -signature SHA256SUMS.sig SHA256SUMS >/dev/null 2>&1; then
echo "❌ SHA256SUMS signature verification FAILED, refusing to install"
exit 1
fi
echo "✔ Signature OK (release authenticity verified)"
###############################################
# 10) Verify checksum (integrity)
###############################################
echo "[+] Verifying checksum..."
# Match the filename exactly, normalizing sha256sum's optional binary-mode '*'
# marker on the name (mirrors the Go verifyChecksum). The original line is printed
# unchanged so "sha256sum -c" still understands the marker.
awk -v f="${FILENAME}" '{n=$2; sub(/^\*/,"",n)} n==f' SHA256SUMS > CHECK
if [ ! -s CHECK ]; then
echo "❌ Checksum entry not found for ${FILENAME}"
exit 1
fi
sha256sum -c CHECK
echo "✔ Checksum OK"
###############################################
# 11) Extract ONLY the binary
###############################################
echo "[+] Extracting binary from tar.gz..."
tar -xzf "${FILENAME}" proxsave
if [ ! -f proxsave ]; then
echo "❌ Binary 'proxsave' not found inside archive"
exit 1
fi
###############################################
# 12) Install binary
###############################################
echo "[+] Installing binary -> ${TARGET_BIN}"
mv proxsave "${TARGET_BIN}"
# Conventional executable mode 0755 (owner rwx, group/other r-x). The binary runs as
# root and only root can replace it; the security check verifies it is root-owned and
# not group/other-writable, not an exact mode, so 0755 is the right standard here.
chmod 755 "${TARGET_BIN}"
###############################################
# 12b) HA-LXC host-backup hint (issue #255)
###############################################
# When the Proxmox host root is bind-mounted read-only into this container, offer
# the SYSTEM_ROOT_PREFIX + HOST_BACKUP_MODE configuration. Informational only: it
# never writes config, so it is safe and idempotent.
if grep -qE '[[:space:]]/host[[:space:]]' /proc/mounts 2>/dev/null; then
echo "--------------------------------------------"
echo "Detected a /host mount: this looks like an HA-LXC backup appliance."
echo "To back up the Proxmox host, set in backup.env:"
echo " SYSTEM_ROOT_PREFIX=/host"
echo " HOST_BACKUP_MODE=true"
echo "The host is expected to be mounted read-only, for example:"
echo " pct set <CTID> -mp0 /,mp=/host,ro=1"
echo " pct set <CTID> -mp1 /etc/pve,mp=/host/etc/pve,ro=1"
echo "--------------------------------------------"
fi
###############################################
# 13) Run internal installer (--install or --new-install)
###############################################
cd "${TARGET_DIR}"
BINARY_ARGS=("${INSTALL_FLAG}")
if [[ "${INSTALL_FLAG}" == "--upgrade" ]]; then
BINARY_ARGS+=("--localfile")
fi
if [[ -n "${CLI_FLAG}" ]]; then
BINARY_ARGS+=("${CLI_FLAG}")
fi
echo "[+] Running: ${TARGET_BIN} ${BINARY_ARGS[*]}"
"${TARGET_BIN}" "${BINARY_ARGS[@]}"
echo "--------------------------------------------"
echo "✔ Installation completed successfully!"
echo " Directory: ${TARGET_DIR}"
echo " Binary: ${TARGET_BIN}"
echo " Mode: ${INSTALL_FLAG}"
echo "--------------------------------------------"