#!/usr/bin/env bash # Put the project on a USB flash drive for deploy/update.sh: the host part of the # last commit as an archive (no venv, build, data or local configs) and the update # script, both in /radar_update/. # # deploy/pack-usb.sh [DRIVE] # # DRIVE defaults to the only mounted removable drive. set -euo pipefail PROJECT_ROOT="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")/.." && pwd)" # What runs on the Pi or Jetson; device_firmware/ and docs/ stay on this machine. HOST_PATHS=(data_acq_and_processing deploy python_app run_config_examples Makefile requirements.txt run_config.json start.sh locator_test_client.py) drive="${1:-}" if [[ -z "${drive}" ]]; then mapfile -t drives < <(lsblk -nlo HOTPLUG,MOUNTPOINT | sed -n 's|^ *1 \+\(/.*\)$|\1|p') if (( ${#drives[@]} != 1 )); then echo "Found ${#drives[@]} mounted removable drives; name one: $0 /path/to/drive" >&2 printf ' %s\n' "${drives[@]}" >&2 exit 1 fi drive="${drives[0]}" fi if [[ ! -d "${drive}" || ! -w "${drive}" ]]; then echo "Not a writable directory: ${drive}" >&2 exit 1 fi cd "${PROJECT_ROOT}" if [[ -n "$(git status --porcelain -- "${HOST_PATHS[@]}")" ]]; then echo "Note: uncommitted changes are left out, the archive holds the last commit." >&2 fi release="radar_system-$(git log -1 --format=%cd --date=format:%Y%m%d-%H%M)-$(git rev-parse --short HEAD)" out="${drive}/radar_update" mkdir -p "${out}" git archive --format=tar.gz --prefix=radar_system/ -o "${out}/${release}.tar.gz" HEAD "${HOST_PATHS[@]}" git show HEAD:deploy/update.sh > "${out}/update.sh" sync echo "Written to ${out}:" echo " ${release}.tar.gz" echo " update.sh" echo "On the device, from the drive's folder: bash radar_update/update.sh"