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/
|
.venv/
|
||||||
|
.idea/
|
12
Makefile
12
Makefile
@ -4,13 +4,7 @@ run:
|
|||||||
./src/nbmrec.sh
|
./src/nbmrec.sh
|
||||||
|
|
||||||
install:
|
install:
|
||||||
sudo cp ./src/nbmrec.sh /usr/local/bin/nbmrec.sh
|
./install.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:
|
uninstall:
|
||||||
sudo rm -rf /usr/local/bin/nbmrec.sh
|
./install.sh --uninstall
|
||||||
sudo rm -rf /etc/systemd/system/nbmrec.service /etc/systemd/system/nbmrec.timer
|
|
||||||
sudo systemctl daemon-reload
|
|
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]
|
[Service]
|
||||||
Type=oneshot
|
Type=oneshot
|
||||||
User=1000
|
User=<USER>
|
||||||
ExecStart=/usr/local/bin/nbmrec.sh -d night
|
ExecStart=/usr/local/bin/nbmrec.sh
|
||||||
RemainAfterExit=yes
|
RemainAfterExit=yes
|
||||||
|
|
||||||
[Install]
|
[Install]
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
Description=Record bird migration every night
|
Description=Record bird migration every night
|
||||||
|
|
||||||
[Timer]
|
[Timer]
|
||||||
OnCalendar=*-*-* 22:00
|
OnCalendar=*-*-* <start_time>
|
||||||
Unit=nbmrec.service
|
Unit=nbmrec.service
|
||||||
|
|
||||||
[Install]
|
[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_DIR="/mnt/DATA/media/records"
|
||||||
RECORD_DATE=$(date +"%Y-%m-%d")
|
RECORD_DATE=$(date +"%Y-%m-%d")
|
||||||
RECORD_FILENAME=$(date +"%Y%m%d_%H%M%S")
|
PREFIX="nbmrec"
|
||||||
RECORD_FILEPATH="${RECORD_DIR}/${RECORD_DATE}/${RECORD_FILENAME}.wav"
|
RECORD_FILENAME="${PREFIX}_$(date +"%Y%m%d_%H%M%S").wav"
|
||||||
RECORD_DURATION=60
|
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() {
|
usage() {
|
||||||
echo "Usage: $0 [ -d <duration> ] [ -f <filename> ]"
|
echo "Usage: $0 [ -d <duration> ] [ -f <filename> ]"
|
||||||
echo " -d <duration> : duration of the recording in seconds or 'night' for all night recording"
|
echo " -d <duration> : duration of the recording in seconds or 'night' for all night recording"
|
||||||
echo " -f <filename> : filename of the recording"
|
echo " -f <filename> : filename of the recording"
|
||||||
echo " -h : display this help"
|
echo " -h : display this help"
|
||||||
echo " -v : switch to verbose mode"
|
echo " -v : switch to VERBOSE mode"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Get command line options
|
# Get command line options
|
||||||
@ -44,24 +55,22 @@ while getopts ":hd:f:" opt; do
|
|||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
verbose=false
|
|
||||||
|
|
||||||
main() {
|
main() {
|
||||||
# Create output folder
|
# Create output folder
|
||||||
if $verbose
|
if $VERBOSE
|
||||||
then
|
then
|
||||||
echo "Creating record output folder"
|
echo "Creating record output folder"
|
||||||
fi
|
fi
|
||||||
mkdir -p "$RECORD_DIR/$RECORD_DATE/"
|
mkdir -p "$RECORD_DIR/$RECORD_DATE/"
|
||||||
|
|
||||||
# Perform recording
|
# Perform recording
|
||||||
if $verbose
|
if $VERBOSE
|
||||||
then
|
then
|
||||||
echo "Recording $RECORD_FILENAME"
|
echo "Recording $RECORD_FILENAME"
|
||||||
fi
|
fi
|
||||||
rec -b 16 -r 48000 -c 1 -t wav $RECORD_FILEPATH trim 0 $RECORD_DURATION
|
rec -b 16 -r 48000 -c 1 -t wav $RECORD_FILEPATH trim 0 $RECORD_DURATION
|
||||||
|
|
||||||
if $verbose
|
if $VERBOSE
|
||||||
then
|
then
|
||||||
echo "Done"
|
echo "Done"
|
||||||
fi
|
fi
|
||||||
|
Loading…
Reference in New Issue
Block a user