planktoscope/scripts/bash/update.sh

72 lines
2.8 KiB
Bash
Raw Normal View History

2020-11-25 16:58:32 +01:00
#!/bin/bash
2020-11-27 11:53:21 +01:00
log="logger -t update.sh -s "
2020-11-25 16:58:32 +01:00
2020-11-30 02:46:40 +01:00
function update(){
sudo killall -15 raspimjpeg
sudo killall -15 python3
git stash
git merge
git checkout stash@'{0}' -- config.json hardware.json
# TODO we need to change this to drop stash@{1} if changes made to the flow are to be restored by the user
git stash drop
sudo systemctl restart nodered.service
}
2020-12-01 21:12:29 +01:00
function special(){
if [[ -f "/etc/systemd/system/usb-mount@.service" ]]; then
sudo rm /etc/systemd/system/usb-mount@.service
fi
if [[ -f "/etc/udev/rules.d/99-local.rules" ]]; then
sudo rm /etc/udev/rules.d/99-local.rules
fi
if ! hash thumbsup &> /dev/null ; then
2020-12-03 13:18:19 +01:00
${log} "thumbsup is not installed, installing now"
sudo chown -R pi:pi /usr/lib/node_modules/
2020-12-03 18:00:40 +01:00
sudo chown pi:pi /usr/bin
if npm install -g thumbsup; then
${log} "Error when installing thumbsup"
2020-12-03 17:28:54 +01:00
else
${log} "Thumbsup installed, installing dependencies now"
sudo apt install -y libimage-exiftool-perl graphicsmagick
sudo apt autoremove -y
${log} "Install complete, running thumbsup for the first time now"
thumbsup --config /home/pi/PlanktonScope/scripts/thumbsup/config.json
fi
sudo chown -R root:root /usr/lib/node_modules/
2020-12-03 18:00:40 +01:00
sudo chown root:root /usr/bin
2020-12-03 14:19:13 +01:00
fi
2020-12-03 17:28:54 +01:00
if ! [[ -f "/etc/nginx/sites-available/gallery.conf" ]]; then
2020-12-03 14:19:13 +01:00
${log} "Nginx config is not installed, doing that now"
sudo cp /home/pi/PlanktonScope/scripts/thumbsup/gallery.conf /etc/nginx/sites-available/gallery.conf
sudo ln -s /etc/nginx/sites-available/gallery.conf /etc/nginx/sites-enabled/gallery.conf
sudo nginx -t && sudo systemctl reload nginx
2020-12-03 13:18:19 +01:00
fi
2020-12-03 17:28:54 +01:00
if [[ -f "/etc/nginx/sites-available/img.conf" ]]; then
2020-12-03 16:29:12 +01:00
${log} "Getting rid of the old nginx config"
sudo rm /etc/nginx/sites-available/img.conf
sudo rm /etc/nginx/sites-enabled/img.conf
sudo nginx -t && sudo systemctl reload nginx
fi
2020-12-01 21:12:29 +01:00
}
2020-11-27 11:53:21 +01:00
${log} "Updating the main repository"
2020-11-30 02:46:40 +01:00
cd /home/pi/PlanktonScope || { echo "/home/pi/PlanktonScope does not exist"; exit 1; }
2020-11-25 16:58:32 +01:00
2020-11-30 02:46:40 +01:00
# TODO We need to add here a way to load the latest version of this script and execute it again
remote=$(git ls-remote -h origin master | awk '{print $1}')
local=$(git rev-parse HEAD)
${log} "Local : $local - Remote: $remote"
if [[ "$local" == "$remote" ]]; then
${log} "nothing to do!"
else
git fetch
UPDATE=$(git diff --numstat origin/master scripts/bash/update.sh | awk '/update.sh/ {print $NF}')
if [[ -n "${UPDATE}" ]]; then
# Update the file and restart the script
git checkout origin/master scripts/bash/update.sh
exec scripts/bash/update.sh
fi
2020-12-01 21:12:29 +01:00
special
2020-11-30 02:46:40 +01:00
update
${log} "Done!"
fi