Files
clearpilot/system/clearpilot/provision.sh
Brian Hanson 5e7911e599
Some checks failed
prebuilt / build prebuilt (push) Has been cancelled
badges / create badges (push) Has been cancelled
move SSH key decryption from provision.sh to on_start.sh
Keys now install to /root/.ssh/ (for root git operations) instead of
/data/ssh/.ssh/. Runs every boot via on_start.sh so keys are available
even without a full provision cycle.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-15 02:59:34 +00:00

78 lines
2.2 KiB
Bash

#!/bin/bash
# ClearPilot provision script
# Runs on first boot (no /data/quick_boot) when internet is available.
# Installs packages, pulls latest code, and builds.
# SSH is handled by on_start.sh before this runs.
# Output is displayed on screen via qt_shell.
mount -o rw,remount /
# 1. Wait for internet connectivity
echo "Waiting for internet connectivity (up to 30s)..."
ONLINE=0
for i in $(seq 1 30); do
if nmcli networking connectivity check 2>/dev/null | grep -q "full"; then
echo "Online after ${i}s"
ONLINE=1
break
fi
sleep 1
done
if [ "$ONLINE" -eq 0 ]; then
echo "No internet after 30s, skipping packages and updates"
sleep 3
exit 0
fi
# 3. Install packages
echo "Remounting / read-write..."
sudo mount -o remount,rw /
echo "Installing packages..."
sudo apt-get update -qq
sudo apt-get install -y openvpn curl ccrypt
#echo "Installing Node.js 20..."
#curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
sudo apt-get install -y nodejs
mount -o rw,remount /
echo "Installing Claude Code..."
curl -fsSL https://claude.ai/install.sh | bash
cat > /usr/local/bin/claude <<'WRAPPER'
#!/bin/bash
sudo mount -o rw,remount /
exec /root/.local/bin/claude "$@"
WRAPPER
chmod +x /usr/local/bin/claude
echo "Packages installed"
# 4. Ensure git remote uses SSH (not HTTPS)
cd /data/openpilot
EXPECTED_REMOTE="git@git.hanson.xyz:brianhansonxyz/clearpilot.git"
CURRENT_REMOTE=$(git remote get-url origin 2>/dev/null)
if [ "$CURRENT_REMOTE" != "$EXPECTED_REMOTE" ]; then
echo "Fixing git remote: $CURRENT_REMOTE -> $EXPECTED_REMOTE"
git remote set-url origin "$EXPECTED_REMOTE"
fi
# 5. Pull latest from remote (remote always wins)
echo "Checking for updates..."
git fetch origin clearpilot
LOCAL=$(git rev-parse HEAD)
REMOTE=$(git rev-parse origin/clearpilot)
if [ "$LOCAL" != "$REMOTE" ]; then
echo "Updating: $(git log --oneline -1 HEAD) -> $(git log --oneline -1 origin/clearpilot)"
git reset --hard origin/clearpilot
sudo chown -R comma:comma /data/openpilot
echo "Update complete"
else
echo "Already up to date"
fi
# 5. Build
echo ""
sudo chown -R comma:comma /data/openpilot
touch /data/quick_boot
echo "Provision complete"
sleep 2