#!/bin/bash

set -euxo pipefail

REPO_PATH="/home/zoox/driving"
UPDATE_BRANCH="zchurch/optop-os-build-fixes"
export PYTHONPATH="$REPO_PATH"

# CoreDash installed a new python version without some dependencies on an old OS image. Putting the PATH for the old system-provided python image at the front.
export PATH=/usr/local/python3.6.8/bin:$PATH

builtin cd "$REPO_PATH"

git stash save --include-untracked

git fetch -p origin "$UPDATE_BRANCH"

COMMIT_SHA="$(git rev-parse "remotes/origin/$UPDATE_BRANCH")"

git checkout "$COMMIT_SHA"

vehicle/deploy/lib/driving_os/update_standalone_machine.py

sudo reboot
