Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
123 changes: 104 additions & 19 deletions scripts/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# Usage: ./install.sh [language]
# Example: ./install.sh nl
#
# https://github.com/RonnyCHL/Translate
# https://github.com/Svardsten53/Translate
#

set -e
Expand All @@ -24,20 +24,83 @@ I18N_SOURCE_DIR="$(dirname "$SCRIPT_DIR")/i18n"

# Find BirdNET-Pi installation
find_birdnet_home() {
# Check common locations
if [ -d "$HOME/BirdNET-Pi" ]; then
echo "$HOME/BirdNET-Pi"
elif [ -d "/home/pi/BirdNET-Pi" ]; then
echo "/home/pi/BirdNET-Pi"
# Check common locations in order of likelihood
local locations=(
"$HOME/BirdNET-Pi"
"/home/pi/BirdNET-Pi"
"/BirdNET-Pi"
"/opt/BirdNET-Pi"
)

for loc in "${locations[@]}"; do
if [ -d "$loc/homepage" ]; then
echo "$loc"
return
fi
done

# Search for it
local found=$(find /home /opt / -maxdepth 3 -type d -name "BirdNET-Pi" 2>/dev/null | head -1)
if [ -n "$found" ] && [ -d "$found/homepage" ]; then
echo "$found"
else
# Search for it
local found=$(find /home -maxdepth 2 -type d -name "BirdNET-Pi" 2>/dev/null | head -1)
if [ -n "$found" ]; then
echo "$found"
else
echo ""
echo ""
fi
}

# Find web root where files are served from
find_webroot() {
local birdnet_home="$1"

# Method 1: Check Caddy config
if [ -f /etc/caddy/Caddyfile ]; then
local caddy_root=$(grep -E "^\s*root\s+" /etc/caddy/Caddyfile 2>/dev/null | head -1 | awk '{print $NF}')
if [ -n "$caddy_root" ] && [ -d "$caddy_root" ]; then
echo "$caddy_root"
return
fi
fi

# Method 2: Check nginx config
if [ -d /etc/nginx ]; then
local nginx_root=$(grep -rh "root\s" /etc/nginx/sites-enabled/ 2>/dev/null | grep -v "#" | head -1 | awk '{print $2}' | tr -d ';')
if [ -n "$nginx_root" ] && [ -d "$nginx_root" ]; then
echo "$nginx_root"
return
fi
fi

# Method 3: Check Apache config
if [ -d /etc/apache2 ]; then
local apache_root=$(grep -rh "DocumentRoot" /etc/apache2/sites-enabled/ 2>/dev/null | head -1 | awk '{print $2}')
if [ -n "$apache_root" ] && [ -d "$apache_root" ]; then
echo "$apache_root"
return
fi
fi

# Method 4: Check common web roots that might be symlinks to BirdNET-Pi
local web_roots=(
"/var/www/html"
"/var/www"
"/srv/www"
)

for root in "${web_roots[@]}"; do
if [ -d "$root" ]; then
echo "$root"
return
fi
done

# Method 5: Fallback - use BirdNET-Pi homepage directory directly
# This works if the webserver is configured to serve from there
if [ -d "$birdnet_home/homepage" ]; then
echo "$birdnet_home/homepage"
return
fi

echo ""
}

BIRDNET_HOME=$(find_birdnet_home)
Expand All @@ -49,10 +112,14 @@ if [ -z "$BIRDNET_HOME" ]; then
exit 1
fi

# Find web root
WEBROOT=$(find_webroot "$BIRDNET_HOME")

echo -e "${GREEN}BirdNET-Pi i18n Installation${NC}"
echo "=============================="
echo ""
echo "BirdNET-Pi location: $BIRDNET_HOME"
echo "Web root: $WEBROOT"
echo "Default language: $DEFAULT_LANG"
echo ""

Expand All @@ -62,15 +129,33 @@ if [ ! -d "$I18N_SOURCE_DIR" ]; then
exit 1
fi

# Create target directory
I18N_TARGET_DIR="$BIRDNET_HOME/i18n"
# Determine where to install i18n files
# They need to be accessible via /i18n/ in the browser
if [ -n "$WEBROOT" ] && [ "$WEBROOT" != "$BIRDNET_HOME/homepage" ]; then
# Web root is separate from BirdNET-Pi, install there
I18N_TARGET_DIR="$WEBROOT/i18n"
echo "Installing to web root: $I18N_TARGET_DIR"
else
# Web root is the homepage directory or we're using BirdNET-Pi directly
I18N_TARGET_DIR="$BIRDNET_HOME/homepage/i18n"
echo "Installing to homepage: $I18N_TARGET_DIR"

# Also create in BirdNET-Pi root for backwards compatibility
mkdir -p "$BIRDNET_HOME/i18n/langs"
cp "$I18N_SOURCE_DIR/i18n.js" "$BIRDNET_HOME/i18n/"
cp "$I18N_SOURCE_DIR/langs/"*.json "$BIRDNET_HOME/i18n/langs/" 2>/dev/null || true
if [ -f "$I18N_SOURCE_DIR/config.js" ]; then
cp "$I18N_SOURCE_DIR/config.js" "$BIRDNET_HOME/i18n/"
fi
fi

echo "Creating i18n directory..."
mkdir -p "$I18N_TARGET_DIR/langs"
sudo mkdir -p "$I18N_TARGET_DIR/langs"

# Copy i18n files
echo "Copying i18n files..."
cp "$I18N_SOURCE_DIR/i18n.js" "$I18N_TARGET_DIR/"
cp "$I18N_SOURCE_DIR/langs/"*.json "$I18N_TARGET_DIR/langs/" 2>/dev/null || true
sudo cp "$I18N_SOURCE_DIR/i18n.js" "$I18N_TARGET_DIR/"
sudo cp "$I18N_SOURCE_DIR/langs/"*.json "$I18N_TARGET_DIR/langs/" 2>/dev/null || true

# Check if language file exists
if [ ! -f "$I18N_TARGET_DIR/langs/${DEFAULT_LANG}.json" ]; then
Expand Down Expand Up @@ -134,9 +219,9 @@ echo "Setting up configuration..."
if [ -f "$I18N_SOURCE_DIR/config.js" ]; then
# Only copy if not already exists (preserve user customizations)
if [ ! -f "$I18N_TARGET_DIR/config.js" ]; then
cp "$I18N_SOURCE_DIR/config.js" "$I18N_TARGET_DIR/"
sudo cp "$I18N_SOURCE_DIR/config.js" "$I18N_TARGET_DIR/"
# Update default language in config
sed -i "s/defaultLang: 'nl'/defaultLang: '${DEFAULT_LANG}'/" "$I18N_TARGET_DIR/config.js"
sudo sed -i "s/defaultLang: 'nl'/defaultLang: '${DEFAULT_LANG}'/" "$I18N_TARGET_DIR/config.js"
echo " Created config.js with default language: $DEFAULT_LANG"
else
echo " Config.js already exists (preserving user settings)"
Expand Down
130 changes: 105 additions & 25 deletions scripts/update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#
# Usage: ./update.sh
#
# https://github.com/RonnyCHL/Translate
# https://github.com/Svardsten53/Translate
#

set -e
Expand All @@ -17,21 +17,93 @@ YELLOW='\033[1;33m'
NC='\033[0m' # No Color

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
I18N_SOURCE_DIR="$(dirname "$SCRIPT_DIR")/i18n"

# Find BirdNET-Pi installation
find_birdnet_home() {
if [ -d "$HOME/BirdNET-Pi" ]; then
echo "$HOME/BirdNET-Pi"
elif [ -d "/home/pi/BirdNET-Pi" ]; then
echo "/home/pi/BirdNET-Pi"
local locations=(
"$HOME/BirdNET-Pi"
"/home/pi/BirdNET-Pi"
"/BirdNET-Pi"
"/opt/BirdNET-Pi"
)

for loc in "${locations[@]}"; do
if [ -d "$loc/homepage" ]; then
echo "$loc"
return
fi
done

local found=$(find /home /opt / -maxdepth 3 -type d -name "BirdNET-Pi" 2>/dev/null | head -1)
if [ -n "$found" ] && [ -d "$found/homepage" ]; then
echo "$found"
else
local found=$(find /home -maxdepth 2 -type d -name "BirdNET-Pi" 2>/dev/null | head -1)
if [ -n "$found" ]; then
echo "$found"
else
echo ""
echo ""
fi
}

# Find web root
find_webroot() {
local birdnet_home="$1"

if [ -f /etc/caddy/Caddyfile ]; then
local caddy_root=$(grep -E "^\s*root\s+" /etc/caddy/Caddyfile 2>/dev/null | head -1 | awk '{print $NF}')
if [ -n "$caddy_root" ] && [ -d "$caddy_root" ]; then
echo "$caddy_root"
return
fi
fi

if [ -d /etc/nginx ]; then
local nginx_root=$(grep -rh "root\s" /etc/nginx/sites-enabled/ 2>/dev/null | grep -v "#" | head -1 | awk '{print $2}' | tr -d ';')
if [ -n "$nginx_root" ] && [ -d "$nginx_root" ]; then
echo "$nginx_root"
return
fi
fi

if [ -d /etc/apache2 ]; then
local apache_root=$(grep -rh "DocumentRoot" /etc/apache2/sites-enabled/ 2>/dev/null | head -1 | awk '{print $2}')
if [ -n "$apache_root" ] && [ -d "$apache_root" ]; then
echo "$apache_root"
return
fi
fi

# Check if homepage/i18n exists (previous install location)
if [ -d "$birdnet_home/homepage/i18n" ]; then
echo "$birdnet_home/homepage"
return
fi

echo ""
}

# Find where i18n is currently installed
find_i18n_dir() {
local birdnet_home="$1"
local webroot="$2"

# Check webroot first
if [ -n "$webroot" ] && [ -f "$webroot/i18n/i18n.js" ]; then
echo "$webroot/i18n"
return
fi

# Check homepage
if [ -f "$birdnet_home/homepage/i18n/i18n.js" ]; then
echo "$birdnet_home/homepage/i18n"
return
fi

# Check BirdNET-Pi root
if [ -f "$birdnet_home/i18n/i18n.js" ]; then
echo "$birdnet_home/i18n"
return
fi

echo ""
}

BIRDNET_HOME=$(find_birdnet_home)
Expand All @@ -41,28 +113,36 @@ if [ -z "$BIRDNET_HOME" ]; then
exit 1
fi

I18N_DIR="$BIRDNET_HOME/i18n"
WEBROOT=$(find_webroot "$BIRDNET_HOME")
I18N_DIR=$(find_i18n_dir "$BIRDNET_HOME" "$WEBROOT")

echo -e "${GREEN}BirdNET-Pi i18n Update${NC}"
echo "======================"
echo ""
echo "BirdNET-Pi location: $BIRDNET_HOME"
echo "Web root: ${WEBROOT:-not detected}"
echo "i18n location: ${I18N_DIR:-not found}"
echo ""

# Check if i18n directory exists
if [ ! -d "$I18N_DIR" ]; then
echo -e "${RED}Error: i18n directory not found at $I18N_DIR${NC}"
echo "Please run install.sh first."
exit 1
# If i18n not found, run full install
if [ -z "$I18N_DIR" ] || [ ! -f "$I18N_DIR/i18n.js" ]; then
echo -e "${YELLOW}i18n not found. Running full installation...${NC}"
echo ""
"$SCRIPT_DIR/install.sh"
exit 0
fi

# Check if i18n.js exists
if [ ! -f "$I18N_DIR/i18n.js" ]; then
echo -e "${RED}Error: i18n.js not found!${NC}"
echo "Please run install.sh first."
exit 1
fi
# Update i18n.js from source (in case there are updates)
if [ -f "$I18N_SOURCE_DIR/i18n.js" ]; then
echo "Updating i18n.js..."
sudo cp "$I18N_SOURCE_DIR/i18n.js" "$I18N_DIR/"

echo "BirdNET-Pi location: $BIRDNET_HOME"
echo ""
# Also update language files
if [ -d "$I18N_SOURCE_DIR/langs" ]; then
echo "Updating language files..."
sudo cp "$I18N_SOURCE_DIR/langs/"*.json "$I18N_DIR/langs/" 2>/dev/null || true
fi
fi

# Script tags to check/add
SCRIPT_TAG='<script src="/i18n/i18n.js" defer></script>'
Expand All @@ -73,7 +153,6 @@ restore_script_tag() {
local file="$1"
local tag="$2"
local tag_name="$3"
local changes=0

if [ ! -f "$file" ]; then
echo -e "${YELLOW}Warning: File not found: $file${NC}"
Expand Down Expand Up @@ -104,6 +183,7 @@ restore_script_tag() {
INDEX_FILE="$BIRDNET_HOME/homepage/index.php"
VIEWS_FILE="$BIRDNET_HOME/homepage/views.php"

echo ""
echo "Checking and restoring script tags..."
echo ""

Expand Down