From 98c240a36f7fd7d1967cb6ea362a2eec4b48a28a Mon Sep 17 00:00:00 2001 From: Alexandre <44178713+alexbelgium@users.noreply.github.com> Date: Mon, 7 Oct 2024 14:49:10 +0200 Subject: [PATCH] chown --- .../etc/cont-init.d/02-restorestreamdata.sh | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/birdnet-pi/rootfs/etc/cont-init.d/02-restorestreamdata.sh b/birdnet-pi/rootfs/etc/cont-init.d/02-restorestreamdata.sh index 8a32a8dc1..8ab4ae674 100755 --- a/birdnet-pi/rootfs/etc/cont-init.d/02-restorestreamdata.sh +++ b/birdnet-pi/rootfs/etc/cont-init.d/02-restorestreamdata.sh @@ -9,6 +9,9 @@ if [ -d /data/StreamData ]; then if find /data/StreamData -type f -name "*.wav" | grep -q .; then bashio::log.warning "Restoring .wav files from /data/StreamData to $HOME/BirdSongs/StreamData." + # Create the destination directory if it does not exist + mkdir -p "$HOME"/BirdSongs/StreamData + # Count the number of .wav files to be moved file_count=$(find /data/StreamData -type f -name "*.wav" | wc -l) echo "... found $file_count .wav files to restore." @@ -16,10 +19,18 @@ if [ -d /data/StreamData ]; then # Move the .wav files using `mv` to avoid double log entries mv -v /data/StreamData/*.wav "$HOME"/BirdSongs/StreamData/ + # Update permissions only if files were moved successfully + if [ "$file_count" -gt 0 ]; then + chown -R pi:pi "$HOME"/BirdSongs/StreamData + fi + + echo "... $file_count files restored successfully." else echo "... no .wav files found to restore." fi - # Clean up the source folder if empty - rm -r /data/StreamData + # Clean up the source folder if it is empty + if [ -z "$(ls -A /data/StreamData)" ]; then + rm -r /data/StreamData + fi fi