This commit is contained in:
Samuel Ortion 2022-06-30 22:20:25 +02:00
parent ac6048530d
commit 8efff3b5ad
3 changed files with 75 additions and 4 deletions

View File

@ -1,16 +1,16 @@
all: run
run:
./rec.sh
./src/nbmrec.sh
install:
sudo cp ./src/rec.sh /usr/local/bin/rec.sh
sudo cp ./src/nbmrec.sh /usr/local/bin/nbmrec.sh
sudo cp ./conf/nbmrec.service /etc/systemd/system/nbmrec.service
sudo cp ./conf/nbmrec.timer /etc/systemd/system/nbmrec.timer
sudo systemctl daemon-reload
sudo systemctl enable nbmrec.timer
uninstall:
sudo rm -rf /usr/local/bin/rec.sh
sudo rm -rf /usr/local/bin/nbmrec.sh
sudo rm -rf /etc/systemd/system/nbmrec.service /etc/systemd/system/nbmrec.timer
sudo systemctl daemon-reload

View File

@ -4,7 +4,7 @@ Description=NBMrec daemon nocturnal bird migration service
[Service]
Type=oneshot
User=1000
ExecStart=/usr/local/bin/nmbrec.sh -d night
ExecStart=/usr/local/bin/nbmrec.sh -d night
RemainAfterExit=yes
[Install]

71
src/nbmrec.sh Executable file
View File

@ -0,0 +1,71 @@
#!/bin/bash
# NBMrec
# nocturnal bird migration recorder daemon
# by Samuel ORTION
RECORD_DIR="/mnt/DATA/media/records"
RECORD_DATE=$(date +"%Y-%m-%d")
RECORD_FILENAME=$(date +"%Y%m%d_%H%M%S")
RECORD_FILEPATH="${RECORD_DIR}/${RECORD_DATE}/${RECORD_FILENAME}.wav" 
RECORD_DURATION=60
usage() {
echo "Usage: $0 [ -d <duration> ] [ -f <filename> ]"
echo " -d <duration> : duration of the recording in seconds or 'night' for all night recording"
echo " -f <filename> : filename of the recording"
echo " -h : display this help"
echo " -v : switch to verbose mode"
}
# Get command line options
while getopts ":hd:f:" opt; do
case $opt in
h)
usage
;;
d)
RECORD_DURATION=$OPTARG
if [ "$RECORD_DURATION" == "night" ]; then
RECORD_DURATION=32400
fi
;;
f)
RECORD_FILEPATH=$OPTARG
;;
\?)
echo "Invalid option: -$OPTARG" >&2
exit 1
;;
:)
echo "Option -$OPTARG requires an argument." >&2
exit 1
;;
esac
done
verbose=false
main() {
# Create output folder
if $verbose
then
echo "Creating record output folder"
fi
mkdir -p "$RECORD_DIR/$RECORD_DATE/"
# Perform recording
if $verbose
then
echo "Recording $RECORD_FILENAME"
fi
rec -b 16 -r 48000 -c 1 -t wav $RECORD_FILEPATH trim 0 $RECORD_DURATION
if $verbose
then
echo "Done"
fi
}
main
exit 0