Archived
1
0
Fork 0
This repository has been archived on 2024-07-01. You can view files and clone it, but cannot push or open issues or pull requests.
weewx-docker/entrypoint.sh

94 lines
2.4 KiB
Bash
Raw Permalink Normal View History

2022-01-30 22:11:34 +00:00
#!/bin/bash
set -o nounset
set -o errexit
set -o pipefail
CONF_FILE="/data/weewx.conf"
# echo version before starting syslog so we don't confound our tests
if [ "$1" = "--version" ]; then
gosu weewx:weewx ./bin/weewxd --version
exit 0
fi
if [ "$(id -u)" = 0 ]; then
# set timezone using environment
2022-07-16 20:53:20 +00:00
ln -snf /usr/share/zoneinfo/"${TZ:-UTC}" /etc/localtime
2022-01-30 22:11:34 +00:00
# start the syslog daemon as root
/sbin/syslogd -n -S -O - &
2022-12-22 21:57:53 +00:00
# setup cron
if [ -e /data/cron/dwd ]; then
cp /data/cron/dwd /etc/cron.hourly/
else
cp /defaults/cron/dwd /etc/cron.hourly/
fi
chmod +x /etc/cron.hourly/*
2022-12-23 10:24:01 +00:00
cron &
2022-12-22 22:36:24 +00:00
# run cron tasks on startup
/etc/cron.hourly/dwd || true
2022-07-27 18:46:11 +00:00
# skin config: WDC
2022-07-27 14:28:39 +00:00
rm -f ./skins/weewx-wdc/skin.conf
if [ -e /data/skin-wdc/skin.conf ]; then
ln -s /data/skin-wdc/skin.conf ./skins/weewx-wdc/skin.conf
else
ln -s /defaults/skin-wdc/skin.conf ./skins/weewx-wdc/skin.conf
2022-07-10 17:12:38 +00:00
fi
2023-03-24 20:47:54 +00:00
# skin: move dwd icons
2023-03-24 21:27:38 +00:00
mkdir /data/static_html || true
2023-03-24 21:36:53 +00:00
chmod +x /data/static_html
2023-03-24 21:14:24 +00:00
rm -rf /data/static_html/dwd
2023-03-24 20:47:54 +00:00
cp -r ./public_html/dwd /data/static_html
chown -R "${WEEWX_UID:-weewx}:${WEEWX_GID:-weewx}" /data/static_html
chmod 444 /data/static_html/dwd/{icons,warn_icons}/*
2022-01-30 22:11:34 +00:00
if [ "${WEEWX_UID:-weewx}" != 0 ]; then
# drop privileges and restart this script
echo "Switching uid:gid to ${WEEWX_UID:-weewx}:${WEEWX_GID:-weewx}"
gosu "${WEEWX_UID:-weewx}:${WEEWX_GID:-weewx}" "$(readlink -f "$0")" "$@"
exit 0
fi
fi
copy_default_config() {
# create a default configuration on the data volume
echo "Creating a configration file on the container data volume."
cp weewx.conf "${CONF_FILE}"
echo "The default configuration has been copied."
# Change the default location of the SQLITE database to the volume
echo "Setting SQLITE_ROOT to the container volume."
sed -i "s/SQLITE_ROOT =.*/SQLITE_ROOT = \/data/g" "${CONF_FILE}"
}
if [ "$1" = "--gen-test-config" ]; then
copy_default_config
echo "Generating a test configuration."
./bin/wee_config --reconfigure --no-prompt "${CONF_FILE}"
exit 0
fi
if [ "$1" = "--shell" ]; then
2023-06-22 18:45:42 +00:00
/bin/bash
2022-01-30 22:11:34 +00:00
exit $?
fi
if [ "$1" = "--upgrade" ]; then
./bin/wee_config --upgrade --no-prompt --dist-config weewx.conf "${CONF_FILE}"
exit $?
fi
if [ ! -f "${CONF_FILE}" ]; then
copy_default_config
echo "Running configuration tool."
./bin/wee_config --reconfigure "${CONF_FILE}"
exit 1
fi
2023-06-22 18:45:42 +00:00
exec ./bin/weewxd "$@"