Improved code

This commit is contained in:
Alexandre
2024-10-06 20:53:28 +02:00
committed by GitHub
parent d31ea625a7
commit f60165fe57

View File

@@ -2,26 +2,31 @@
# 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
# Check if the /data/StreamData directory exists
if [ -d /data/StreamData ]; then
# Count the number of .wav files in /data/StreamData
wav_count=$(find /data/StreamData -type f -name "*.wav" | wc -l)
bashio::log.warning "Container was stopped while files were still being analyzed, restoring $wav_count .wav files"
# Check specifically for any .wav files in the directory
wav_file_exists=$(find /data/StreamData -type f -name "*.wav" -print -quit)
# Copy files
if [ "$wav_count" -gt 0 ]; then
mv -v /data/StreamData/* "$HOME"/BirdSongs/StreamData/
# If a .wav file is found
if [ -n "$wav_file_exists" ]; then
# Count the number of .wav files in /data/StreamData
wav_count=$(find /data/StreamData -type f -name "*.wav" | wc -l)
bashio::log.warning "Container was stopped while files were still being analyzed, restoring $wav_count .wav files"
# Move files if there are any .wav files
if [ "$wav_count" -gt 0 ]; then
mv -v /data/StreamData/*.wav "$HOME"/BirdSongs/StreamData/
fi
echo "... done"
echo ""
# Setting permissions
chown -R pi:pi "$HOME"/BirdSongs
chmod -R 755 "$HOME"/BirdSongs
fi
echo "... done"
echo ""
# Setting permissions
chown -R pi:pi "$HOME"/BirdSongs
chmod -R 755 "$HOME"/BirdSongs
# Cleaning folder
# Cleaning folder only if the directory exists (in case it was modified)
rm -r /data/StreamData
fi