Skip to content

Commit

Permalink
Clean birdnet-pi
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbelgium committed Apr 26, 2024
1 parent d680605 commit 55a9a22
Show file tree
Hide file tree
Showing 99 changed files with 104 additions and 735 deletions.
43 changes: 28 additions & 15 deletions zzz_draft_birdnet-pi/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ RUN \
echo "Install dependencies" && \
apt-get update -y && apt-get install curl gcc python3-dev git jq sudo -y && \
\
# Correct for systemctl
curl -f -L -s -S https://raw.githubusercontent.com/gdraheim/docker-systemctl-replacement/master/files/docker/systemctl3.py -o /bin/systemctl && \
chmod a+x /bin/systemctl && \
\
# Change user to pi and create /home/pi
echo "setting users" && \
groupmod -o -g 101 abc && usermod -o -u 101 abc && \
Expand All @@ -49,19 +53,28 @@ RUN \
curl -f -L -s -S "https://raw.githubusercontent.com/Nachtzuster/BirdNET-Pi/main/newinstaller.sh" -o /newinstaller.sh && \
chmod 777 /newinstaller.sh && \
\
# Use installer to modify other scripts
#######################################
# Define file
sed -i "1a /./newinstallermod.sh && rm /newinstallermod.sh" /newinstaller.sh && \
echo '#!/bin/bash' >> /newinstallermod.sh && \
# Remove all instances of sudo from all other scripts
echo 'for file in $(grep -srl "sudo" $HOME/BirdNET-Pi/scripts); do sed -i "s|sudo ||" "$file"; done' >> /newinstallermod.sh && \
echo 'for file in $(grep -srl "my_dir" $HOME/BirdNET-Pi/scripts); do sed -i "s|\$my_dir|/config|" "$file"; done' >> /newinstallermod.sh && \
echo 'for file in $(grep -srl "install_services.sh" $HOME/BirdNET-Pi/scripts); do sed -i "/install_services.sh/c ./install_services.sh" "$file"; done' >> /newinstallermod.sh && \
# Disable pulseaudio
echo 'for file in $(grep -srl "pulseaudio --start" $HOME/BirdNET-Pi/scripts); do sed -i "/pulseaudio --start/d" "$file"; done' >> /newinstallermod.sh && \
# Set permission
chmod +x /newinstallermod.sh && \
\
# Modify installer
##################
# Avoid rebooting at end of installation
sed -i "/reboot/d" /newinstaller.sh && \
# Use apt-get as without user action
sed -i "s|apt |apt-get |g" /newinstaller.sh && \
# Remove all instances of sudo from the newinstaller
sed -i -e "s|== 0|== 7|g" -e "s|sudo -n true|true|g" -e "s|sudo -K|true|g" /newinstaller.sh && \
# Remove all instances of sudo from all other scripts
sed -i '1a for file in $(grep -srl "sudo" $HOME/BirdNET-Pi/scripts); do sed -i "s|sudo ||" "$file"; done' /newinstaller.sh && \
sed -i '1a for file in $(grep -srl "my_dir" $HOME/BirdNET-Pi/scripts); do sed -i "s|\$my_dir|/config|" "$file"; done' /newinstaller.sh && \
sed -i '1a for file in $(grep -srl "install_services.sh" $HOME/BirdNET-Pi/scripts); do sed -i "/install_services.sh/c ./install_services.sh" "$file"; done' /newinstaller.sh && \
# Avoid systemctl
sed -i '/git clone/a sed -i "s|systemctl enable|#systemctl enable|g" "$HOME"/BirdNET-Pi/scripts/install_services.sh' /newinstaller.sh && \
\
# Execute installer
/./newinstaller.sh && \
Expand All @@ -82,15 +95,15 @@ RUN \
# sudo chown -R pi:pi /app && \
# /./newinstaller.sh
#USER root
#sudo -E -u birdnet -s /bin/bash -c "/newinstaller.sh"
# Correct script
#sed -i "s|== 0|== 7|g" /newinstaller.sh && \
#sed -i "s|sudo -n true|true|g" /newinstaller.sh && \
#sed -i "s|sudo -K|true|g" /newinstaller.sh && \
#for file in $(grep -srl "sudo" $HOME/BirdNET-Pi/scripts); do \sed -i "s|sudo ||" "$file"; done && \
#/./newinstaller.sh
# Correct for absence of sudo
#sudo -E -u birdnet -s /bin/bash -c "/newinstaller.sh"
#sudo -E -u birdnet -s /bin/bash -c "/newinstaller.sh"
# Correct script
#sed -i "s|== 0|== 7|g" /newinstaller.sh && \
#sed -i "s|sudo -n true|true|g" /newinstaller.sh && \
#sed -i "s|sudo -K|true|g" /newinstaller.sh && \
#for file in $(grep -srl "sudo" $HOME/BirdNET-Pi/scripts); do \sed -i "s|sudo ||" "$file"; done && \
#/./newinstaller.sh
# Correct for absence of sudo
#sudo -E -u birdnet -s /bin/bash -c "/newinstaller.sh"

##################
# 2 Modify Image #
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@ until [[ -e /var/run/dbus/system_bus_socket ]]; do
done

exec \
s6-setuidgid "$USER" /sbin/agetty --autologin "${USER}"
--noclear %I "$TERM"
s6-setuidgid "$USER" /sbin/agetty --autologin "${USER}" --noclear %I "$TERM"
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/with-contenv bashio
# Waiting for dbus
until [[ -e /var/run/dbus/system_bus_socket ]]; do
#Disable pulseaudio as managed by HA
echo "Starting service: livestream"
until [[ -e /start ]]; do
sleep 1s
done

Expand Down
12 changes: 5 additions & 7 deletions zzz_draft_birdnet-pi/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,12 @@
"/dev/nvme1",
"/dev/nvme2"
],
"description": "Realtime BirdNET soundscape analyzer",
"description": "realtime acoustic bird classification system",
"environment": {
},
"image": "ghcr.io/alexbelgium/birdnet-pi-{arch}",
"init": false,
"ingress": true,
"ingress_stream": true,
"map": [
"addon_config:rw",
"media:rw",
Expand All @@ -76,10 +77,7 @@
"80/tcp": 80
},
"ports_description": {
"80/tcp": "web ui",
"8888/tcp": "web terminal",
"8080/tcp": "log",
"8501/tcp": "streamlit"
"80/tcp": "web ui"
},
"privileged": [
"SYS_ADMIN",
Expand All @@ -97,6 +95,6 @@
},
"slug": "birdnet-pi",
"url": "https://github.com/alexbelgium/hassio-addons/tree/master/birdnet-pi",
"version": "1.5",
"version": "1.8",
"video": true
}
22 changes: 22 additions & 0 deletions zzz_draft_birdnet-pi/rootfs/Caddyfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
%%interface%%:%%port%% {
reverse_proxy http://localhost:8080 {
header_up Host {host}
header_up X-Forwarded-For {remote}
header_up Connection "upgrade"
header_up Accept-Encoding ""
@base_url {
path /
file {
try_files {path} /%%ingress_entry%%
}
}
handle @base_url {
sub_filter_once off
sub_filter_types *
sub_filter href=\"/ href=\"%%ingress_entry%%/
sub_filter src=\"/ src=\"%%ingress_entry%%/
sub_filter hx-get=\"/ hx-get=\"%%ingress_entry%%/
sub_filter action=\"/ action=\"%%ingress_entry%%/
}
}
}
3 changes: 2 additions & 1 deletion zzz_draft_birdnet-pi/rootfs/custom-services.d/02_caddy
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#!/usr/bin/with-contenv bashio
# Dependencies
sockfile="$(find /run/php -name *.sock)"
sockfile="empty"
until [[ -e /var/run/dbus/system_bus_socket ]] && [[ -e "$sockfile" ]]; do
sleep 1s
sockfile="$(find /run/php -name *.sock)"
done

# Correct fpm.sock
Expand Down
24 changes: 24 additions & 0 deletions zzz_draft_birdnet-pi/rootfs/etc/cont-init.d/31-ingress.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/usr/bin/with-contenv bashio
# shellcheck shell=bash
set -e

#################
# NGINX SETTING #
#################

declare ingress_interface
declare ingress_port

bashio::log.info "Setting up ingress"

echo "... adding new instructions"
cat /Caddyfile >> /etc/caddy/Caddyfile
rm /Caddyfile

echo "... customizing"
ingress_port=$(bashio::addon.ingress_port)
ingress_interface=$(bashio::addon.ip_address)
ingress_entry=$(bashio::addon.ingress_entry)
sed -i "s/%%port%%/${ingress_port}/g" /etc/caddy/Caddyfile
sed -i "s/%%interface%%/${ingress_interface}/g" /etc/caddy/Caddyfile
sed -i "s|%%ingress_entry%%|${ingress_entry}|g" /etc/caddy/Caddyfile
27 changes: 19 additions & 8 deletions zzz_draft_birdnet-pi/rootfs/etc/cont-init.d/99-run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,29 @@ set -e
#################

# Starting dbus
echo "Starting service: dbus"
bashio::log.info "Starting system services..."
echo "... dbus"
service dbus start

bashio::log.info "ALSA_CARD option is set to $(bashio::config "ALSA_CARD"). If the microphone doesn't work, please adapt it"
echo " "
# Starting php service
echo "... php"
until [[ -e /var/run/dbus/system_bus_socket ]]; do
sleep 1s
done
systemctl start php*service

########################
# CONFIGURE birdnet-pi #
########################

bashio::log.info "Starting app..."
# Starting avahi service
echo "... avahi"
systemctl start avahi*service

# Restarting all services
bashio::log.info "Ensuring birdnet.conf is in /config ; please customize as needed"
if [ ! -f /config/birdnet.conf ]; then
cp /etc/birdnet/birdnet.conf /config
fi

bashio::log.info "Starting BirdNET-Pi services"
chmod +x $HOME/BirdNET-Pi/scripts/restart_services
/.$HOME/BirdNET-Pi/scripts/restart_services &>/proc/1/fd/1

bashio::log.info "App is accessible from webui"
24 changes: 0 additions & 24 deletions zzz_draft_birdnet-pi2/CHANGELOG.md

This file was deleted.

Loading

0 comments on commit 55a9a22

Please sign in to comment.