2022-08-15 14:28:58 +02:00
|
|
|
#! /usr/bin/env bash
|
2022-08-16 05:21:53 +02:00
|
|
|
# inspired by https://unix.stackexchange.com/questions/47132/execute-shell-script-from-php-as-root-user
|
2022-08-15 14:28:58 +02:00
|
|
|
set -e
|
|
|
|
# set -x
|
|
|
|
|
2022-08-21 06:13:15 +02:00
|
|
|
config_filepath="./config/birdnet.conf"
|
2022-08-15 14:28:58 +02:00
|
|
|
|
|
|
|
if [ -f "$config_filepath" ]; then
|
|
|
|
source "$config_filepath"
|
|
|
|
else
|
|
|
|
echo "Config file not found: $config_filepath"
|
2022-08-16 05:21:53 +02:00
|
|
|
# exit 1
|
2022-08-15 14:28:58 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ -z $DAEMON_USER ]]
|
|
|
|
then
|
|
|
|
echo "DAEMON_USER is not set"
|
2022-08-16 05:21:53 +02:00
|
|
|
# exit 1
|
2022-08-15 14:28:58 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ -z $DAEMON_PASSWORD ]]
|
|
|
|
then
|
|
|
|
echo "DAEMON_PASSWORD is not set"
|
2022-08-16 05:21:53 +02:00
|
|
|
# exit 1
|
2022-08-15 14:28:58 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
SERVICES="$(sudo -S <<< $DAEMON_PASSWORD ls /etc/systemd/system/ | grep 'birdnet')"
|
|
|
|
|
|
|
|
DEBUG=${DEBUG:-0}
|
|
|
|
|
|
|
|
debug() {
|
|
|
|
if [ $DEBUG -eq 1 ]; then
|
|
|
|
echo "$1"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
manage() {
|
|
|
|
action=$1
|
2022-08-16 05:21:53 +02:00
|
|
|
if [[ -z $2 ]]; then
|
|
|
|
services=$SERVICES
|
|
|
|
else
|
|
|
|
services=$2
|
|
|
|
fi
|
2022-08-15 14:28:58 +02:00
|
|
|
debug "$action birdnet services"
|
2022-08-16 05:21:53 +02:00
|
|
|
# sshpass -p $DAEMON_PASSWORD sudo -S -u $DAEMON_USER sudo systemctl $action $services
|
|
|
|
sudo systemctl $action $services
|
2022-08-15 14:28:58 +02:00
|
|
|
echo "done"
|
|
|
|
}
|
|
|
|
|
2022-08-16 05:21:53 +02:00
|
|
|
manage $1 $2
|