Repository navigation
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·134 lines (105 loc) · 4.42 KB
/
Copy pathsetup.sh
File metadata and controls
executable file
·134 lines (105 loc) · 4.42 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
#!/usr/bin/env bash
# setup.sh - build cuckoo_loader inside a 32-bit container and safely flash using load_firmware.sh
set -euo pipefail
IMAGE_NAME="cuckoo-loader-build:latest"
CONTAINER_NAME="cuckoo-loader-build-container"
PLATFORM="linux/386"
WORKDIR="/src"
info(){ printf "\n\033[1;34m[INFO]\033[0m %s\n" "$*"; }
warn(){ printf "\n\033[1;33m[WARN]\033[0m %s\n" "$*"; }
err(){ printf "\n\033[1;31m[ERROR]\033[0m %s\n" "$*"; }
die(){ err "$*"; exit 1; }
cat <<'WARNING'
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
ATTENTION — IMPORTANT SAFETY WARNING
This script will build code and then run the repository's load_firmware.sh to flash
firmware to a Nest Thermostat (Gen2). Flashing is destructive if the wrong image,
address, or process is used. This may permanently brick the device.
You are responsible for verifying the firmware and ensuring correct device version.
Proceed only if you understand and accept the risks.
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
WARNING
# read -rp "Do you want to continue? Type YES to proceed: " proceed
# if [[ "$proceed" != "YES" ]]; then
# echo "Aborted by user."
# exit 0
# fi
# 1) prerequisites
info "Checking prerequisites..."
if ! command -v docker >/dev/null 2>&1; then
die "Docker not found. Install Docker Desktop and re-run."
fi
if ! command -v dfu-util >/dev/null 2>&1; then
warn "dfu-util not found on host. Installing via Homebrew (if available)..."
if command -v brew >/dev/null 2>&1; then
brew install dfu-util || warn "brew install dfu-util failed; continue if you plan to flash via load_firmware.sh another way."
else
warn "Homebrew not found — please install dfu-util manually if you plan to flash from host."
fi
fi
info "Enabling binfmt/qemu for cross-arch Docker (if on Apple Silicon)..."
docker run --privileged --rm tonistiigi/binfmt --install all >/dev/null 2>&1 || warn "binfmt registration may already be present or failed; continuing."
# 2) build docker image
info "Building Docker image '$IMAGE_NAME' (32-bit base)..."
docker build --pull --platform="$PLATFORM" -t "$IMAGE_NAME" .
#--no-cache
# 3) remove old container
if [[ -n "$(docker ps -aq -f name="$CONTAINER_NAME")" ]]; then
info "Removing old container instance..."
docker rm -f "$CONTAINER_NAME" >/dev/null 2>&1 || true
fi
# 4) run build inside container
info "Running build.sh inside container..."
docker run --platform="$PLATFORM" -it --name "$CONTAINER_NAME" \
-v "$(pwd)":$WORKDIR \
--cpus=4 \
"$IMAGE_NAME" bash -c "cd $WORKDIR && chmod +x build.sh && ./build.sh"
info "Build complete. Artifacts should be available in the repository directory."
# 5) fix ownership (macOS/host)
info "Fixing ownership on produced files (sudo may be required)..."
sudo chown -R "$(id -u):$(id -g)" "$(pwd)" || warn "chown failed; adjust manually if needed."
# 6) DFU scan and confirmation
info "Preparing to flash. Please plug the Nest Thermostat into USB and put it into DFU mode now."
echo
echo "We'll scan for DFU devices via 'dfu-util -l'."
while true; do
echo
info "Listing DFU devices:"
dfu-util -l || true
echo
read -rp "Is the Nest DFU device listed? (y = yes, r = retry, n = abort) " yn
case "$yn" in
[Yy]) break ;;
[Rr]) info "Retrying scan in 2s..."; sleep 2 ;;
[Nn]) info "User aborted flash step."; exit 0 ;;
*) echo "Please answer y, r or n." ;;
esac
done
cat <<'CONFIRM'
!!! FINAL CONFIRMATION !!!
THIS WILL RUN the repository's load_firmware.sh script and attempt to flash the thermostat.
This is destructive if the wrong firmware/address is used.
To proceed type exactly: FLASH
To abort type anything else.
CONFIRM
read -rp "Type FLASH to proceed: " final
if [[ "$final" != "FLASH" ]]; then
info "Final confirmation not received. Aborting."
exit 0
fi
FLASH_SCRIPT="$(pwd)/load_firmware.sh"
if [[ ! -f "$FLASH_SCRIPT" ]]; then
die "load_firmware.sh not found at $FLASH_SCRIPT. Aborting."
fi
chmod +x "$FLASH_SCRIPT" || warn "Could not chmod +x $FLASH_SCRIPT; proceeding anyway."
warn "About to execute load_firmware.sh with sudo (flashing step)."
read -rp "Type YES to run the flasher with sudo, or anything else to abort: " run_ok
if [[ "$run_ok" != "YES" ]]; then
info "User aborted before running flasher."
exit 0
fi
sudo "$FLASH_SCRIPT"
info "Flashing step completed. Check the output for success/failure details."
info "If flashing failed, DO NOT unplug power; collect logs and investigate."
info "All done."
exit 0