Add conf file and better script and installation process
This commit is contained in:
parent
d05661dc15
commit
5d0f72b637
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,2 +1,3 @@
|
||||
|
||||
.venv/
|
||||
.idea/
|
12
Makefile
12
Makefile
@ -4,13 +4,7 @@ run:
|
||||
./src/nbmrec.sh
|
||||
|
||||
install:
|
||||
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
|
||||
|
||||
./install.sh
|
||||
|
||||
uninstall:
|
||||
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
|
||||
./install.sh --uninstall
|
6
conf/nbmrec.conf
Normal file
6
conf/nbmrec.conf
Normal file
@ -0,0 +1,6 @@
|
||||
# NBMrec configuration file
|
||||
START_TIME=22:00
|
||||
END_TIME=06:00
|
||||
RECORD_DIR=/mnt/DATA/media/records
|
||||
PREFIX=nbmrec
|
||||
VERBOSE=false
|
@ -3,8 +3,8 @@ Description=NBMrec daemon nocturnal bird migration service
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
User=1000
|
||||
ExecStart=/usr/local/bin/nbmrec.sh -d night
|
||||
User=<USER>
|
||||
ExecStart=/usr/local/bin/nbmrec.sh
|
||||
RemainAfterExit=yes
|
||||
|
||||
[Install]
|
||||
|
@ -2,7 +2,7 @@
|
||||
Description=Record bird migration every night
|
||||
|
||||
[Timer]
|
||||
OnCalendar=*-*-* 22:00
|
||||
OnCalendar=*-*-* <start_time>
|
||||
Unit=nbmrec.service
|
||||
|
||||
[Install]
|
||||
|
42
install.sh
Executable file
42
install.sh
Executable file
@ -0,0 +1,42 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Install script for NBMrec daemon
|
||||
# by Samuel ORTION
|
||||
|
||||
install()
|
||||
{
|
||||
START_TIME="22:00" # default start time
|
||||
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 mkdir -p /usr/local/etc/nbmrec/
|
||||
sudo cp ./conf/nbmrec.conf /usr/local/etc/nbmrec/nbmrec.conf
|
||||
|
||||
if [ -f /usr/local/etc/nbmrec/nbmrec.conf ]; then
|
||||
source /usr/local/etc/nbmrec/nbmrec.conf
|
||||
fi
|
||||
|
||||
sudo sed -i "s/<USER>/$USER/g" /etc/systemd/system/nbmrec.service
|
||||
sudo sed -i "s/<start_time>/$START_TIME/g" /etc/systemd/system/nbmrec.timer
|
||||
|
||||
sudo systemctl daemon-reload
|
||||
sudo systemctl enable --now nbmrec.timer
|
||||
}
|
||||
|
||||
uninstall()
|
||||
{
|
||||
sudo systemctl disable --now nbmrec.timer
|
||||
sudo rm -rf /usr/local/bin/nbmrec.sh
|
||||
sudo rm -rf /etc/systemd/system/nbmrec.service /etc/systemd/system/nbmrec.timer
|
||||
sudo rm -rf /usr/local/etc/nbmrec/
|
||||
sudo systemctl daemon-reload
|
||||
}
|
||||
|
||||
# Check if --uninstall is specified
|
||||
if [ "$1" == "--uninstall" ]; then
|
||||
uninstall
|
||||
exit 0
|
||||
else
|
||||
install
|
||||
exit 0
|
||||
fi
|
@ -6,16 +6,27 @@
|
||||
|
||||
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
|
||||
PREFIX="nbmrec"
|
||||
RECORD_FILENAME="${PREFIX}_$(date +"%Y%m%d_%H%M%S").wav"
|
||||
RECORD_FILEPATH="${RECORD_DIR}/${RECORD_DATE}/${RECORD_FILENAME}"
|
||||
START_TIME="22:00"
|
||||
END_TIME="06:00"
|
||||
RECORD_DURATION=$(( $(date -d "$END_TIME + 1 day" "+%s") - $(date -d "$START_TIME" "+%s") ))
|
||||
VERBOSE=false
|
||||
|
||||
# Load conf file if any
|
||||
if [ -f /usr/local/etc/nbmrec/nbmrec.conf ]; then
|
||||
source /usr/local/etc/nbmrec.conf
|
||||
fi
|
||||
|
||||
RECORD_DURATION=$(( $(date -d "$END_TIME + 1 day" "+%s") - $(date -d "$START_TIME" "+%s") ))
|
||||
|
||||
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"
|
||||
echo " -v : switch to VERBOSE mode"
|
||||
}
|
||||
|
||||
# Get command line options
|
||||
@ -44,24 +55,22 @@ while getopts ":hd:f:" opt; do
|
||||
esac
|
||||
done
|
||||
|
||||
verbose=false
|
||||
|
||||
main() {
|
||||
# Create output folder
|
||||
if $verbose
|
||||
if $VERBOSE
|
||||
then
|
||||
echo "Creating record output folder"
|
||||
fi
|
||||
mkdir -p "$RECORD_DIR/$RECORD_DATE/"
|
||||
|
||||
# Perform recording
|
||||
if $verbose
|
||||
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
|
||||
if $VERBOSE
|
||||
then
|
||||
echo "Done"
|
||||
fi
|
||||
|
Loading…
Reference in New Issue
Block a user