From 554616c99940ba907c4fffe03b737871490b5c59 Mon Sep 17 00:00:00 2001 From: Nico Rey Date: Sun, 20 Dec 2020 19:02:14 -0300 Subject: [PATCH 1/2] Add script to prune images --- WORKING.md | 7 +++++++ prune.sh | 11 +++++++---- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/WORKING.md b/WORKING.md index a156e1e..6198b1c 100644 --- a/WORKING.md +++ b/WORKING.md @@ -34,3 +34,10 @@ Will show the scheduled jobs for today, each job can be described using `at -c < # Images Images are saved in the web server's directory, so you can access your received images at http://your.raspberry.pi.ip/, where `your.raspberry.pi.ip` is your Raspberry PI IP address. + +# Pruning +Run `prune.sh` to delete old images. By default it deletes the 10 oldest images from the disk and the database. If you want to schedule this task, run + +```bash +cat <(crontab -l) <(echo "1 0 * * * /home/pi/raspberry-noaa/prune.sh") | crontab - +``` diff --git a/prune.sh b/prune.sh index 31109c8..94433c9 100755 --- a/prune.sh +++ b/prune.sh @@ -4,7 +4,10 @@ . "$HOME/.noaa.conf" . "$NOAA_HOME/common.sh" -find "${NOAA_HOME}/map/" -type f -name '*.png' -mtime +1 -exec rm -f {} \; -log "${NOAA_HOME}/map/ folder pruned" "INFO" -find "${NOAA_OUTPUT}/audio/" -type f -name '*.wav' -mtime +1 -exec rm -f {} \; -log "${NOAA_OUTPUT}/audio/ folder pruned" "INFO" +for img_path in $(sqlite3 ${NOAA_HOME}/panel.db "select file_path from decoded_passes limit 10;"); do + find "${NOAA_OUTPUT}/images/" -type f -name "${IMG_NAME}*.jpg" -exec rm -f {} \; + find "${NOAA_OUTPUT}/images/thumb/" -type f -name "${IMG_NAME}*.jpg" -exec rm -f {} \; + log "${img_path} file pruned" "INFO" + sqlite3 "${NOAA_HOME}/panel.db" "delete from decoded_passes where file_path = \"$img_path\";" + log "Database entry pruned" "INFO" +done From c3d0d16382a0287f075eec21c1013cc33b46f69a Mon Sep 17 00:00:00 2001 From: Nico Rey Date: Tue, 22 Dec 2020 16:36:20 -0300 Subject: [PATCH 2/2] Fix ownership of www folders --- install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install.sh b/install.sh index 5e59315..a78a0f8 100755 --- a/install.sh +++ b/install.sh @@ -184,7 +184,7 @@ log_running "Setting up Nginx..." sudo cp templates/nginx.cfg /etc/nginx/sites-enabled/default ( sudo mkdir -p /var/www/wx/images - sudo chown -R www-data:www-data /var/www/wx + sudo chown -R pi:pi /var/www/wx sudo usermod -a -G www-data pi sudo chmod 775 /var/www/wx )