|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +set -e |
| 4 | + |
| 5 | +CHECKOUT="/opt/camera-streamer-stack" |
| 6 | +CONFIG="/boot/firmware/camera-streamer" |
| 7 | +if [ ! -d "$CONFIG" ]; then |
| 8 | + CONFIG="/boot/camera-streamer" |
| 9 | +fi |
| 10 | + |
| 11 | +if [ ! -d "$CHECKOUT" ]; then |
| 12 | + echo "Checkout folder at /opt/camera-streamer-stack does not exist" |
| 13 | + exit 1 |
| 14 | +fi |
| 15 | + |
| 16 | +if [ ! -d "$CONFIG" ]; then |
| 17 | + echo "Can't locate config folder, it's neither in /boot/firmware nor in /boot." |
| 18 | + exit 1 |
| 19 | +fi |
| 20 | + |
| 21 | +pushd $CHECKOUT |
| 22 | + git fetch |
| 23 | + if [ $(git rev-parse HEAD) == $(git rev-parse @{u}) ]; then |
| 24 | + echo "Already up to date!" |
| 25 | + exit 0 |
| 26 | + fi |
| 27 | + |
| 28 | + git pull |
| 29 | + |
| 30 | + # update systemd files & scripts |
| 31 | + sudo make systemd scripts |
| 32 | + |
| 33 | + # update default configs |
| 34 | + echo "Updating configs..." |
| 35 | + for config in configs/*.conf; do |
| 36 | + name=$(basename $config) |
| 37 | + target="$CONFIG/$name" |
| 38 | + |
| 39 | + if [ ! -e "$target" ]; then |
| 40 | + sudo install --mode=0644 "$config" "$target" |
| 41 | + continue |
| 42 | + fi |
| 43 | + |
| 44 | + changes=$(diff "$config" "$target" || true) |
| 45 | + if [ "$changes" != "" ]; then |
| 46 | + echo "$config and $target differ:" |
| 47 | + echo -n "$changes" |
| 48 | + echo "" |
| 49 | + read -n1 -p "Overwrite your local copy? (y)es or (n)o: " overwrite |
| 50 | + echo |
| 51 | + if [ "$overwrite" == "y" -o "$overwrite" == "Y"]; then |
| 52 | + sudo install --backup=simple --suffix=.backup --mode=0644 "$config" "$target" |
| 53 | + echo "New version of $target installed, backup at $target.backup" |
| 54 | + else |
| 55 | + echo "Skipping $config, check manually if local copy requires any updates!" |
| 56 | + fi |
| 57 | + else |
| 58 | + echo "$config and $target are identical, no need to update" |
| 59 | + fi |
| 60 | + done |
| 61 | + |
| 62 | + echo "Reloading systemd units & restarting camera-streamer..." |
| 63 | + sudo systemctl daemon-reload |
| 64 | + sudo systemctl restart camera-streamer |
| 65 | + |
| 66 | + echo "Update process complete!" |
| 67 | +popd |
0 commit comments