Merge pull request #288 from jmherbst/remove-python-shebangs
Removing python shebangs and adding python3 virtual env to callsites
This commit is contained in:
@@ -77,6 +77,9 @@ move_analyzed() {
|
|||||||
# Uses one argument:
|
# Uses one argument:
|
||||||
# - {DIRECTORY}
|
# - {DIRECTORY}
|
||||||
run_analysis() {
|
run_analysis() {
|
||||||
|
PYTHON_VIRTUAL_ENV="$HOME/BirdNET-Pi/birdnet/bin/python3"
|
||||||
|
DIR="$HOME/BirdNET-Pi/scripts"
|
||||||
|
|
||||||
sleep .5
|
sleep .5
|
||||||
|
|
||||||
### TESTING NEW WEEK CALCULATION
|
### TESTING NEW WEEK CALCULATION
|
||||||
@@ -125,7 +128,7 @@ run_analysis() {
|
|||||||
BIRDWEATHER_ID_PARAM=""
|
BIRDWEATHER_ID_PARAM=""
|
||||||
BIRDWEATHER_ID_LOG=""
|
BIRDWEATHER_ID_LOG=""
|
||||||
fi
|
fi
|
||||||
echo analyze.py \
|
echo $PYTHON_VIRTUAL_ENV "$DIR\analyze.py" \
|
||||||
--i "${1}/${i}" \
|
--i "${1}/${i}" \
|
||||||
--o "${1}/${i}.csv" \
|
--o "${1}/${i}.csv" \
|
||||||
--lat "${LATITUDE}" \
|
--lat "${LATITUDE}" \
|
||||||
@@ -137,7 +140,7 @@ run_analysis() {
|
|||||||
${INCLUDEPARAM} \
|
${INCLUDEPARAM} \
|
||||||
${EXCLUDEPARAM} \
|
${EXCLUDEPARAM} \
|
||||||
${BIRDWEATHER_ID_LOG}
|
${BIRDWEATHER_ID_LOG}
|
||||||
analyze.py \
|
$PYTHON_VIRTUAL_ENV $DIR/analyze.py \
|
||||||
--i "${1}/${i}" \
|
--i "${1}/${i}" \
|
||||||
--o "${1}/${i}.csv" \
|
--o "${1}/${i}.csv" \
|
||||||
--lat "${LATITUDE}" \
|
--lat "${LATITUDE}" \
|
||||||
|
|||||||
@@ -9,6 +9,8 @@ config_file=$my_dir/birdnet.conf
|
|||||||
export USER=$USER
|
export USER=$USER
|
||||||
export HOME=$HOME
|
export HOME=$HOME
|
||||||
|
|
||||||
|
export PYTHON_VIRTUAL_ENV="$HOME/BirdNET-Pi/birdnet/bin/python3"
|
||||||
|
|
||||||
install_depends() {
|
install_depends() {
|
||||||
apt install -y debian-keyring debian-archive-keyring apt-transport-https
|
apt install -y debian-keyring debian-archive-keyring apt-transport-https
|
||||||
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' | sudo gpg --dearmor -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg
|
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' | sudo gpg --dearmor -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg
|
||||||
@@ -66,7 +68,7 @@ Restart=always
|
|||||||
Type=simple
|
Type=simple
|
||||||
RestartSec=10
|
RestartSec=10
|
||||||
User=${USER}
|
User=${USER}
|
||||||
ExecStart=/usr/local/bin/server.py
|
ExecStart=$PYTHON_VIRTUAL_ENV /usr/local/bin/server.py
|
||||||
[Install]
|
[Install]
|
||||||
WantedBy=multi-user.target
|
WantedBy=multi-user.target
|
||||||
EOF
|
EOF
|
||||||
@@ -309,7 +311,7 @@ Restart=always
|
|||||||
RestartSec=120
|
RestartSec=120
|
||||||
Type=simple
|
Type=simple
|
||||||
User=$USER
|
User=$USER
|
||||||
ExecStart=/usr/local/bin/daily_plot.py
|
ExecStart=$PYTHON_VIRTUAL_ENV /usr/local/bin/daily_plot.py
|
||||||
[Install]
|
[Install]
|
||||||
WantedBy=multi-user.target
|
WantedBy=multi-user.target
|
||||||
EOF
|
EOF
|
||||||
|
|||||||
@@ -177,6 +177,7 @@ while($results=$result3->fetchArray(SQLITE3_ASSOC)){
|
|||||||
$flickrjson = json_decode(file_get_contents("https://www.flickr.com/services/rest/?method=flickr.photos.search&api_key=".$config["FLICKR_API_KEY"]."&text=\"".str_replace('_', '+', $comname)."\"&license=2%2C3%2C4%2C5%2C6%2C9&sort=relevance&per_page=15&format=json&nojsoncallback=1"), true)["photos"]["photo"];
|
$flickrjson = json_decode(file_get_contents("https://www.flickr.com/services/rest/?method=flickr.photos.search&api_key=".$config["FLICKR_API_KEY"]."&text=\"".str_replace('_', '+', $comname)."\"&license=2%2C3%2C4%2C5%2C6%2C9&sort=relevance&per_page=15&format=json&nojsoncallback=1"), true)["photos"]["photo"];
|
||||||
|
|
||||||
foreach ($flickrjson as $val) {
|
foreach ($flickrjson as $val) {
|
||||||
|
|
||||||
$iter++;
|
$iter++;
|
||||||
$modaltext = "https://flickr.com/photos/".$val["owner"]."/".$val["id"];
|
$modaltext = "https://flickr.com/photos/".$val["owner"]."/".$val["id"];
|
||||||
$authorlink = "https://flickr.com/people/".$val["owner"];
|
$authorlink = "https://flickr.com/people/".$val["owner"];
|
||||||
|
|||||||
@@ -2,15 +2,56 @@
|
|||||||
# Update BirdNET-Pi's Git Repo
|
# Update BirdNET-Pi's Git Repo
|
||||||
source /etc/birdnet/birdnet.conf
|
source /etc/birdnet/birdnet.conf
|
||||||
trap 'exit 1' SIGINT SIGHUP
|
trap 'exit 1' SIGINT SIGHUP
|
||||||
|
|
||||||
|
usage() { echo "Usage: $0 [-r <remote name>] [-b <branch name>]" 1>&2; exit 1; }
|
||||||
|
|
||||||
|
# Defaults
|
||||||
|
remote="origin"
|
||||||
|
branch="main"
|
||||||
|
|
||||||
|
while getopts ":r:b:" o; do
|
||||||
|
case "${o}" in
|
||||||
|
r)
|
||||||
|
remote=${OPTARG}
|
||||||
|
git remote show $remote > /dev/null 2>&1
|
||||||
|
ret_val=$?
|
||||||
|
|
||||||
|
if [ $ret_val -ne 0 ]; then
|
||||||
|
echo "Error: remote '$remote' not found. Add the upstream remote to your repository and try again."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
b)
|
||||||
|
branch=${OPTARG}
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
usage
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
shift $((OPTIND-1))
|
||||||
|
|
||||||
USER=$(awk -F: '/1000/ {print $1}' /etc/passwd)
|
USER=$(awk -F: '/1000/ {print $1}' /etc/passwd)
|
||||||
HOME=$(awk -F: '/1000/ {print $6}' /etc/passwd)
|
HOME=$(awk -F: '/1000/ {print $6}' /etc/passwd)
|
||||||
my_dir=$HOME/BirdNET-Pi/scripts
|
my_dir=$HOME/BirdNET-Pi/scripts
|
||||||
|
|
||||||
sudo -u$USER git -C $my_dir rm privacy_server.py
|
|
||||||
sudo -u${USER} git -C $my_dir stash
|
sudo_with_user () {
|
||||||
sudo -u${USER} git -C $my_dir pull -f
|
set -x
|
||||||
|
sudo -u $USER "$@"
|
||||||
|
set +x
|
||||||
|
}
|
||||||
|
|
||||||
|
# Reset current HEAD to remove any local changes
|
||||||
|
sudo_with_user git reset --hard
|
||||||
|
|
||||||
|
# Fetches latest changes
|
||||||
|
sudo_with_user git fetch $remote $branch
|
||||||
|
|
||||||
|
# Switches git to specified branch
|
||||||
|
sudo_with_user git switch -C $branch --track $remote/$branch
|
||||||
|
|
||||||
sudo systemctl daemon-reload
|
sudo systemctl daemon-reload
|
||||||
sudo -u${USER} git -C $my_dir stash pop
|
|
||||||
sudo ln -sf $my_dir/* /usr/local/bin/
|
sudo ln -sf $my_dir/* /usr/local/bin/
|
||||||
|
|
||||||
# The script below handles changes to the host system
|
# The script below handles changes to the host system
|
||||||
|
|||||||
@@ -5,10 +5,7 @@ trap 'exit 1' SIGINT SIGHUP
|
|||||||
USER=$(awk -F: '/1000/ {print $1}' /etc/passwd)
|
USER=$(awk -F: '/1000/ {print $1}' /etc/passwd)
|
||||||
HOME=$(awk -F: '/1000/ {print $6}' /etc/passwd)
|
HOME=$(awk -F: '/1000/ {print $6}' /etc/passwd)
|
||||||
my_dir=$HOME/BirdNET-Pi/scripts
|
my_dir=$HOME/BirdNET-Pi/scripts
|
||||||
if ! grep python3 <(head -n1 $my_dir/analyze.py) &>/dev/null;then
|
|
||||||
echo "Ensure all python scripts use the virtual environment"
|
|
||||||
sudo -u$USER sed -si "1 i\\#\!$HOME/BirdNET-Pi/birdnet/bin/python3" $my_dir/*.py
|
|
||||||
fi
|
|
||||||
if ! grep PRIVACY_THRESHOLD /etc/birdnet/birdnet.conf &>/dev/null;then
|
if ! grep PRIVACY_THRESHOLD /etc/birdnet/birdnet.conf &>/dev/null;then
|
||||||
sudo -u$USER echo "PRIVACY_THRESHOLD=0" >> /etc/birdnet/birdnet.conf
|
sudo -u$USER echo "PRIVACY_THRESHOLD=0" >> /etc/birdnet/birdnet.conf
|
||||||
git -C $HOME/BirdNET-Pi rm $my_dir/privacy_server.py
|
git -C $HOME/BirdNET-Pi rm $my_dir/privacy_server.py
|
||||||
@@ -17,6 +14,14 @@ if [ -f $my_dir/privacy_server ] || [ -L /usr/local/bin/privacy_server.py ];then
|
|||||||
rm -f $my_dir/privacy_server.py
|
rm -f $my_dir/privacy_server.py
|
||||||
rm -f /usr/local/bin/privacy_server.py
|
rm -f /usr/local/bin/privacy_server.py
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Adds python virtual-env to the python systemd services
|
||||||
|
if ! grep 'BirdNET-Pi/birdnet/' $HOME/BirdNET-Pi/templates/birdnet_server.service || ! grep 'BirdNET-Pi/birdnet' $HOME/BirdNET-Pi/templates/chart_viewer.service;then
|
||||||
|
sudo -E sed -i "s|ExecStart=.*|ExecStart=$HOME/BirdNET-Pi/birdnet/bin/python3 /usr/local/bin/server.py|" ~/BirdNET-Pi/templates/birdnet_server.service
|
||||||
|
sudo -E sed -i "s|ExecStart=.*|ExecStart=$HOME/BirdNET-Pi/birdnet/bin/python3 /usr/local/bin/daily_plot.py|" ~/BirdNET-Pi/templates/chart_viewer.service
|
||||||
|
sudo systemctl daemon-reload && restart_services.sh
|
||||||
|
fi
|
||||||
|
|
||||||
if grep privacy ~/BirdNET-Pi/templates/birdnet_server.service &>/dev/null;then
|
if grep privacy ~/BirdNET-Pi/templates/birdnet_server.service &>/dev/null;then
|
||||||
sudo -E sed -i 's/privacy_server.py/server.py/g' \
|
sudo -E sed -i 's/privacy_server.py/server.py/g' \
|
||||||
~/BirdNET-Pi/templates/birdnet_server.service
|
~/BirdNET-Pi/templates/birdnet_server.service
|
||||||
|
|||||||
Reference in New Issue
Block a user