mirror of
https://github.com/hassio-addons/addon-chrony.git
synced 2025-05-05 03:31:25 +00:00
🔨 Simplifies add-on code logic
This commit is contained in:
parent
16dffabaf7
commit
045e041f39
3 changed files with 18 additions and 29 deletions
|
@ -20,6 +20,7 @@ then
|
||||||
bashio::log.fatal
|
bashio::log.fatal
|
||||||
bashio::exit.nok
|
bashio::exit.nok
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if bashio::config.equals 'mode' 'server' \
|
if bashio::config.equals 'mode' 'server' \
|
||||||
&& bashio::config.is_empty 'ntp_server';
|
&& bashio::config.is_empty 'ntp_server';
|
||||||
then
|
then
|
||||||
|
|
|
@ -1,30 +1,19 @@
|
||||||
#!/usr/bin/with-contenv bashio
|
#!/usr/bin/with-contenv bashio
|
||||||
# ==============================================================================
|
# ==============================================================================
|
||||||
# Community Hass.io Add-ons: chrony
|
# Community Hass.io Add-ons: chrony
|
||||||
# This files configures the conf file from the options set
|
# This file configures the conf file from the options set
|
||||||
# ==============================================================================
|
# ==============================================================================
|
||||||
readonly CHRONY_CONF='/etc/chrony/chrony.conf'
|
readonly CHRONY_CONF='/etc/chrony/chrony.conf'
|
||||||
readonly NTPMODE=$(bashio::config 'mode')
|
declare mode
|
||||||
|
declare -a serverlist
|
||||||
|
|
||||||
declare configline
|
mode=$(bashio::config 'mode')
|
||||||
declare serverlist
|
bashio::log.debug "Running in NTP mode: ${mode}"
|
||||||
|
|
||||||
if bashio::config.equals 'mode' 'pool';
|
for server in $(bashio::config "ntp_${mode}"); do
|
||||||
then
|
bashio::log.debug "Adding server ${server}"
|
||||||
readonly SOURCE=$(bashio::config 'ntp_pool')
|
echo "${mode} ${server} iburst" >> ${CHRONY_CONF}
|
||||||
elif bashio::config.equals 'mode' 'server';
|
serverlist+=("${server}")
|
||||||
then
|
|
||||||
readonly SOURCE=$(bashio::config 'ntp_server')
|
|
||||||
fi
|
|
||||||
|
|
||||||
for server in ${SOURCE}; do
|
|
||||||
configline=${NTPMODE}
|
|
||||||
configline+=" "
|
|
||||||
configline+=$server
|
|
||||||
configline+=" iburst"
|
|
||||||
bashio::log.debug "Setting config to ${configline}"
|
|
||||||
echo "${configline}" >> ${CHRONY_CONF}
|
|
||||||
serverlist+=$server
|
|
||||||
serverlist+=" "
|
|
||||||
done
|
done
|
||||||
echo "initstepslew 10 ${serverlist}" >> ${CHRONY_CONF}
|
|
||||||
|
echo "initstepslew 10 ${serverlist[*]}" >> ${CHRONY_CONF}
|
||||||
|
|
|
@ -5,12 +5,11 @@
|
||||||
# ==============================================================================
|
# ==============================================================================
|
||||||
declare -a options
|
declare -a options
|
||||||
|
|
||||||
options+=("-d")
|
|
||||||
if bashio::config.false 'set_system_clock'
|
|
||||||
then
|
|
||||||
options+=("-x")
|
|
||||||
fi
|
|
||||||
|
|
||||||
bashio::log.info "Starting chronyd..."
|
bashio::log.info "Starting chronyd..."
|
||||||
|
|
||||||
|
options+=(-d)
|
||||||
|
if bashio::config.false 'set_system_clock'; then
|
||||||
|
options+=(-x)
|
||||||
|
fi
|
||||||
|
|
||||||
exec chronyd "${options[@]}"
|
exec chronyd "${options[@]}"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue