Merge pull request #288 from jmherbst/remove-python-shebangs
Removing python shebangs and adding python3 virtual env to callsites
This commit is contained in:
@@ -31,8 +31,8 @@ fi
|
||||
|
||||
INCLUDE_LIST="$HOME/BirdNET-Pi/include_species_list.txt"
|
||||
EXCLUDE_LIST="$HOME/BirdNET-Pi/exclude_species_list.txt"
|
||||
if [ ! -f ${INCLUDE_LIST} ];then
|
||||
touch ${INCLUDE_LIST} &&
|
||||
if [ ! -f ${INCLUDE_LIST} ];then
|
||||
touch ${INCLUDE_LIST} &&
|
||||
chmod g+rw ${INCLUDE_LIST}
|
||||
fi
|
||||
if [ ! -f ${EXCLUDE_LIST} ];then
|
||||
@@ -61,8 +61,8 @@ get_files() {
|
||||
# Takes one argument:
|
||||
# - {DIRECTORY}
|
||||
move_analyzed() {
|
||||
for i in "${files[@]}";do
|
||||
j="${i}.csv"
|
||||
for i in "${files[@]}";do
|
||||
j="${i}.csv"
|
||||
if [ -f "${1}/${j}" ];then
|
||||
if [ ! -d "${1}-Analyzed" ];then
|
||||
mkdir -p "${1}-Analyzed" && echo "'Analyzed' directory created"
|
||||
@@ -77,7 +77,10 @@ move_analyzed() {
|
||||
# Uses one argument:
|
||||
# - {DIRECTORY}
|
||||
run_analysis() {
|
||||
sleep .5
|
||||
PYTHON_VIRTUAL_ENV="$HOME/BirdNET-Pi/birdnet/bin/python3"
|
||||
DIR="$HOME/BirdNET-Pi/scripts"
|
||||
|
||||
sleep .5
|
||||
|
||||
### TESTING NEW WEEK CALCULATION
|
||||
WEEK_OF_YEAR="$(echo "($(date +%m)-1) * 4" | bc -l)"
|
||||
@@ -125,7 +128,7 @@ run_analysis() {
|
||||
BIRDWEATHER_ID_PARAM=""
|
||||
BIRDWEATHER_ID_LOG=""
|
||||
fi
|
||||
echo analyze.py \
|
||||
echo $PYTHON_VIRTUAL_ENV "$DIR\analyze.py" \
|
||||
--i "${1}/${i}" \
|
||||
--o "${1}/${i}.csv" \
|
||||
--lat "${LATITUDE}" \
|
||||
@@ -137,7 +140,7 @@ run_analysis() {
|
||||
${INCLUDEPARAM} \
|
||||
${EXCLUDEPARAM} \
|
||||
${BIRDWEATHER_ID_LOG}
|
||||
analyze.py \
|
||||
$PYTHON_VIRTUAL_ENV $DIR/analyze.py \
|
||||
--i "${1}/${i}" \
|
||||
--o "${1}/${i}.csv" \
|
||||
--lat "${LATITUDE}" \
|
||||
|
||||
@@ -9,6 +9,8 @@ config_file=$my_dir/birdnet.conf
|
||||
export USER=$USER
|
||||
export HOME=$HOME
|
||||
|
||||
export PYTHON_VIRTUAL_ENV="$HOME/BirdNET-Pi/birdnet/bin/python3"
|
||||
|
||||
install_depends() {
|
||||
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
|
||||
@@ -66,7 +68,7 @@ Restart=always
|
||||
Type=simple
|
||||
RestartSec=10
|
||||
User=${USER}
|
||||
ExecStart=/usr/local/bin/server.py
|
||||
ExecStart=$PYTHON_VIRTUAL_ENV /usr/local/bin/server.py
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
EOF
|
||||
@@ -100,7 +102,7 @@ create_necessary_dirs() {
|
||||
|
||||
sudo -u ${USER} ln -fs $my_dir/exclude_species_list.txt $my_dir/scripts
|
||||
sudo -u ${USER} ln -fs $my_dir/include_species_list.txt $my_dir/scripts
|
||||
sudo -u ${USER} ln -fs $my_dir/homepage/* ${EXTRACTED}
|
||||
sudo -u ${USER} ln -fs $my_dir/homepage/* ${EXTRACTED}
|
||||
sudo -u ${USER} ln -fs $my_dir/model/labels.txt ${my_dir}/scripts
|
||||
sudo -u ${USER} ln -fs $my_dir/scripts ${EXTRACTED}
|
||||
sudo -u ${USER} ln -fs $my_dir/scripts/play.php ${EXTRACTED}
|
||||
@@ -309,7 +311,7 @@ Restart=always
|
||||
RestartSec=120
|
||||
Type=simple
|
||||
User=$USER
|
||||
ExecStart=/usr/local/bin/daily_plot.py
|
||||
ExecStart=$PYTHON_VIRTUAL_ENV /usr/local/bin/daily_plot.py
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
EOF
|
||||
@@ -370,7 +372,7 @@ install_phpsysinfo() {
|
||||
}
|
||||
|
||||
config_icecast() {
|
||||
if [ -f /etc/icecast2/icecast.xml ];then
|
||||
if [ -f /etc/icecast2/icecast.xml ];then
|
||||
cp /etc/icecast2/icecast.xml{,.prebirdnetpi}
|
||||
fi
|
||||
sed -i 's/>admin</>birdnet</g' /etc/icecast2/icecast.xml
|
||||
@@ -434,7 +436,7 @@ install_services() {
|
||||
USER=$USER HOME=$HOME ${my_dir}/scripts/createdb.sh
|
||||
}
|
||||
|
||||
if [ -f ${config_file} ];then
|
||||
if [ -f ${config_file} ];then
|
||||
source ${config_file}
|
||||
install_services
|
||||
else
|
||||
|
||||
@@ -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"];
|
||||
|
||||
foreach ($flickrjson as $val) {
|
||||
|
||||
$iter++;
|
||||
$modaltext = "https://flickr.com/photos/".$val["owner"]."/".$val["id"];
|
||||
$authorlink = "https://flickr.com/people/".$val["owner"];
|
||||
|
||||
@@ -2,15 +2,56 @@
|
||||
# Update BirdNET-Pi's Git Repo
|
||||
source /etc/birdnet/birdnet.conf
|
||||
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)
|
||||
HOME=$(awk -F: '/1000/ {print $6}' /etc/passwd)
|
||||
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 -u${USER} git -C $my_dir pull -f
|
||||
|
||||
sudo_with_user () {
|
||||
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 -u${USER} git -C $my_dir stash pop
|
||||
sudo ln -sf $my_dir/* /usr/local/bin/
|
||||
|
||||
# The script below handles changes to the host system
|
||||
|
||||
@@ -5,18 +5,23 @@ trap 'exit 1' SIGINT SIGHUP
|
||||
USER=$(awk -F: '/1000/ {print $1}' /etc/passwd)
|
||||
HOME=$(awk -F: '/1000/ {print $6}' /etc/passwd)
|
||||
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
|
||||
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
|
||||
fi
|
||||
if [ -f $my_dir/privacy_server ] || [ -L /usr/local/bin/privacy_server.py ];then
|
||||
rm -f $my_dir/privacy_server.py
|
||||
rm -f /usr/local/bin/privacy_server.py
|
||||
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
|
||||
sudo -E sed -i 's/privacy_server.py/server.py/g' \
|
||||
~/BirdNET-Pi/templates/birdnet_server.service
|
||||
|
||||
Reference in New Issue
Block a user