mirror of
https://github.com/alexbelgium/hassio-addons.git
synced 2026-01-11 02:11:01 +01:00
Improve timezone handling
https://github.com/alexbelgium/hassio-addons/issues/1595#issuecomment-2393969024
This commit is contained in:
@@ -6,67 +6,58 @@ set -e
|
|||||||
# SET SYSTEM #
|
# SET SYSTEM #
|
||||||
##############
|
##############
|
||||||
|
|
||||||
echo " "
|
|
||||||
bashio::log.info "Setting password for the user pi"
|
bashio::log.info "Setting password for the user pi"
|
||||||
echo "pi:$(bashio::config "pi_password")" | sudo chpasswd
|
echo "pi:$(bashio::config "pi_password")" | chpasswd
|
||||||
echo "... done"
|
bashio::log.info "Password set successfully for user pi."
|
||||||
|
|
||||||
echo " "
|
bashio::log.info "Setting timezone :"
|
||||||
bashio::log.info "Starting system services"
|
|
||||||
|
|
||||||
# Set TZ
|
# Use timezone defined in add-on options if available
|
||||||
if bashio::config.has_value 'TZ'; then
|
if bashio::config.has_value 'TZ'; then
|
||||||
TIMEZONE=$(bashio::config 'TZ')
|
TZ_VALUE="$(bashio::config 'TZ')"
|
||||||
echo "... setting timezone to $TIMEZONE"
|
if timedatectl set-timezone "$TZ_VALUE"; then
|
||||||
ln -snf /usr/share/zoneinfo/"$TIMEZONE" /etc/localtime
|
echo "... timezone set to $TZ_VALUE as defined in add-on options (BirdNET config ignored)."
|
||||||
echo "$TIMEZONE" >/etc/timezone
|
else
|
||||||
fi || (bashio::log.fatal "Error : $TIMEZONE not found. Here is a list of valid timezones : https://manpages.ubuntu.com/manpages/focal/man3/DateTime::TimeZone::Catalog.3pm.html")
|
bashio::log.warning "Couldn't set timezone to $TZ_VALUE. Refer to the list of valid timezones: https://manpages.ubuntu.com/manpages/focal/man3/DateTime::TimeZone::Catalog.3pm.html"
|
||||||
|
timedatectl set-ntp true &>/dev/null
|
||||||
# Correcting systemctl
|
fi
|
||||||
echo "... correcting systemctl"
|
# Use BirdNET-defined timezone if no add-on option is provided
|
||||||
mv /helpers/systemctl3.py /bin/systemctl
|
elif [ -f /data/timezone ]; then
|
||||||
chmod a+x /bin/systemctl
|
BIRDN_CONFIG_TZ="$(cat /data/timezone)"
|
||||||
|
timedatectl set-ntp false &>/dev/null
|
||||||
# Correcting systemctl
|
if timedatectl set-timezone "$BIRDN_CONFIG_TZ"; then
|
||||||
echo "... correcting datetimectl"
|
echo "... set to $BIRDN_CONFIG_TZ as defined in BirdNET config."
|
||||||
mv /helpers/timedatectl /usr/bin/timedatectl
|
else
|
||||||
chmod a+x /usr/bin/timedatectl
|
bashio::log.warning "Couldn't set timezone to $BIRDN_CONFIG_TZ. Reverting to automatic timezone."
|
||||||
|
timedatectl set-ntp true &>/dev/null
|
||||||
# Correct language labels
|
fi
|
||||||
export "$(grep "^DATABASE_LANG" /config/birdnet.conf)"
|
# Fallback to automatic timezone if no manual settings are found
|
||||||
# Saving default of en
|
else
|
||||||
cp "$HOME"/BirdNET-Pi/model/labels.txt "$HOME"/BirdNET-Pi/model/labels.bak
|
if timedatectl set-ntp true &>/dev/null; then
|
||||||
# Adapt to new language
|
bashio::log.info "... automatic timezone enabled."
|
||||||
echo "... adapting labels according to birdnet.conf file to $DATABASE_LANG"
|
else
|
||||||
/."$HOME"/BirdNET-Pi/scripts/install_language_label_nm.sh -l "$DATABASE_LANG"
|
bashio::log.fatal "Couldn't set automatic timezone! Please set a manual one from the options."
|
||||||
|
fi
|
||||||
echo "... starting cron"
|
|
||||||
systemctl start cron
|
|
||||||
|
|
||||||
# Starting dbus
|
|
||||||
echo "... starting dbus"
|
|
||||||
service dbus start
|
|
||||||
|
|
||||||
# Starting journald
|
|
||||||
# echo "... starting journald"
|
|
||||||
# systemctl start systemd-journald
|
|
||||||
|
|
||||||
# Starting services
|
|
||||||
echo ""
|
|
||||||
bashio::log.info "Starting BirdNET-Pi services"
|
|
||||||
chmod +x "$HOME"/BirdNET-Pi/scripts/restart_services.sh
|
|
||||||
"$HOME"/BirdNET-Pi/scripts/restart_services.sh
|
|
||||||
|
|
||||||
if bashio::config.true LIVESTREAM_BOOT_ENABLED; then
|
|
||||||
echo "... starting livestream"
|
|
||||||
sudo systemctl enable icecast2
|
|
||||||
sudo systemctl start icecast2.service
|
|
||||||
sudo systemctl enable --now livestream.service
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Correct the phpsysinfo for the correct gotty service
|
bashio::log.info "Starting system services"
|
||||||
gottyservice="$(pgrep -l "gotty" | awk '{print $NF}' | head -n 1)"
|
|
||||||
echo "... using $gottyservice in phpsysinfo"
|
|
||||||
sed -i "s/,gotty,/,${gottyservice:-gotty},/g" "$HOME"/BirdNET-Pi/templates/phpsysinfo.ini
|
|
||||||
|
|
||||||
echo " "
|
bashio::log.info "Starting cron service"
|
||||||
|
systemctl start cron >/dev/null
|
||||||
|
|
||||||
|
bashio::log.info "Starting dbus service"
|
||||||
|
service dbus start >/dev/null
|
||||||
|
|
||||||
|
bashio::log.info "Starting BirdNET-Pi services"
|
||||||
|
chmod +x "$HOME/BirdNET-Pi/scripts/restart_services.sh" >/dev/null
|
||||||
|
"$HOME/BirdNET-Pi/scripts/restart_services.sh" >/dev/null
|
||||||
|
|
||||||
|
# Start livestream services if enabled in configuration
|
||||||
|
if bashio::config.true LIVESTREAM_BOOT_ENABLED; then
|
||||||
|
echo "... starting livestream services"
|
||||||
|
systemctl enable icecast2 >/dev/null
|
||||||
|
systemctl start icecast2.service >/dev/null
|
||||||
|
systemctl enable --now livestream.service >/dev/null
|
||||||
|
fi
|
||||||
|
|
||||||
|
bashio::log.info "Setup complete."
|
||||||
|
|||||||
Reference in New Issue
Block a user