Repository navigation
Expand file tree
/
Copy pathupdate.sh
More file actions
68 lines (56 loc) · 2.09 KB
/
Copy pathupdate.sh
File metadata and controls
68 lines (56 loc) · 2.09 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
#!/bin/bash
set -euo pipefail
OWNER="${OWNER:-KavataK}"
REPO="${REPO:-qubic-node-setup}"
BRANCH="${BRANCH:-main}"
RAW_BASE="https://raw.githubusercontent.com/$OWNER/$REPO/$BRANCH"
info() { echo -e "\n[INFO] $1\n"; }
err() { echo "[ERROR] $1" >&2; exit 1; }
FORCE=0
if [[ ${1:-} == "--force" ]]; then
FORCE=1
fi
[[ -d /root/qubic ]] || err "/root/qubic not found. This updater targets hosts installed by install.sh"
[[ -d /root/qubic/qubic_docker ]] || err "/root/qubic/qubic_docker not found"
[[ -d /root/qubic/qubic-efi-cross-build ]] || err "/root/qubic/qubic-efi-cross-build not found"
TMP_DIR="$(mktemp -d)"
BACKUP_DIR="/root/qubic/update_backup_$(date +%Y%m%d_%H%M%S)"
mkdir -p "$BACKUP_DIR"
fetch() {
local src_path="$1"; local dst_path="$2"
curl -fsSL "$RAW_BASE/$src_path" -o "$TMP_DIR/$(basename "$src_path")" || err "Failed to download $src_path"
install -m 0644 "$TMP_DIR/$(basename "$src_path")" "$dst_path"
}
info "Checking remote version"
REMOTE_VERSION="$(curl -fsSL "$RAW_BASE/VERSION" || echo)"
LOCAL_VERSION="$(cat /root/qubic/VERSION 2>/dev/null || echo)"
if [[ $FORCE -ne 1 && -n "$REMOTE_VERSION" && "$REMOTE_VERSION" == "$LOCAL_VERSION" ]]; then
echo "Already up to date (version $LOCAL_VERSION). Use --force to reapply."
exit 0
fi
info "Fetching manifest"
MANIFEST_CONTENT="$(curl -fsSL "$RAW_BASE/update_manifest.txt")" || err "Failed to download update_manifest.txt"
info "Applying manifest entries"
while IFS= read -r line; do
[[ -z "$line" || "$line" =~ ^# ]] && continue
kind="${line%%|*}"; rest="${line#*|}"
if [[ "$kind" == "dir" ]]; then
dst="$rest"
mkdir -p "$dst"
continue
fi
if [[ "$kind" == "file" ]]; then
src_rel="${rest%%|*}"; rest2="${rest#*|}"
dst_path="${rest2%%|*}"; mode="${rest2##*|}"
[[ -f "$dst_path" ]] && cp -f "$dst_path" "$BACKUP_DIR/" || true
fetch "$src_rel" "$dst_path"
chmod "$mode" "$dst_path"
continue
fi
done <<< "$MANIFEST_CONTENT"
if [[ -n "$REMOTE_VERSION" ]]; then
echo "$REMOTE_VERSION" > /root/qubic/VERSION
fi
if [[ -f /root/qubic/VERSION ]]; then
echo "Installed version: $(cat /root/qubic/VERSION)"
fi