This commit is contained in:
Alexandre
2024-10-09 10:09:20 +02:00
committed by GitHub
parent 62716e4176
commit da52b55f27
14 changed files with 452 additions and 460 deletions

View File

@@ -1,24 +1,36 @@
#!/usr/bin/with-contenv bashio
#!/command/with-contenv bashio
# shellcheck shell=bash
set -e
# Check if there are files in "$HOME"/BirdSongs/StreamData and move them to /data/StreamData
if [ -d /data/StreamData ] && [ "$(ls -A /data/StreamData/)" ]; then
if [ -d /data/StreamData ]; then
bashio::log.fatal "Container was stopped while files were still being analyzed."
bashio::log.warning "Container was stopped while files were still being analysed, restoring them"
# Check if there are .wav files in /data/StreamData
if find /data/StreamData -type f -name "*.wav" | grep -q .; then
bashio::log.warning "Restoring .wav files from /data/StreamData to $HOME/BirdSongs/StreamData."
# Copy files
if [ "$(ls -A /data/StreamData)" ]; then
mv -v /data/StreamData/* "$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."
# 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
echo "... done"
echo ""
# Setting permissions
chown -R pi:pi "$HOME"/BirdSongs
chmod -R 755 "$HOME"/BirdSongs
# Cleaning folder
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