#!/usr/bin/env bash

set -euo pipefail

set -x

config_repo_checkout="/etc/zoox/calibration"

cd "$config_repo_checkout"

target_config_file="param/vh6b_101.json"
patch_file="diff_rec_opt.patch"

config_as_recorded="config_as_recorded_828abcb24db16db89fa31a9ee037dffce0fcf515.pbjson"
config_calibrated="config_optimized_e5a748513774329b98271671084c188ee986b9b6.pbjson"

git checkout -- "$target_config_file"
rm "$patch_file" || true

diff --unified=5 "$config_as_recorded" "$config_calibrated" > "$patch_file" || true

cat "$patch_file" | grep -C 5 pepwave

git apply "$patch_file"

git diff "$target_config_file" | grep -C 7 pepwave
