mirror of
https://github.com/hassio-addons/addon-chrony.git
synced 2025-05-04 19:21:35 +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::exit.nok
|
||||
fi
|
||||
|
||||
if bashio::config.equals 'mode' 'server' \
|
||||
&& bashio::config.is_empty 'ntp_server';
|
||||
then
|
||||
|
@ -34,4 +35,4 @@ then
|
|||
bashio::log.fatal 'configuration.'
|
||||
bashio::log.fatal
|
||||
bashio::exit.nok
|
||||
fi
|
||||
fi
|
||||
|
|
|
@ -1,30 +1,19 @@
|
|||
#!/usr/bin/with-contenv bashio
|
||||
# ==============================================================================
|
||||
# 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 NTPMODE=$(bashio::config 'mode')
|
||||
declare mode
|
||||
declare -a serverlist
|
||||
|
||||
declare configline
|
||||
declare serverlist
|
||||
mode=$(bashio::config 'mode')
|
||||
bashio::log.debug "Running in NTP mode: ${mode}"
|
||||
|
||||
if bashio::config.equals 'mode' 'pool';
|
||||
then
|
||||
readonly SOURCE=$(bashio::config 'ntp_pool')
|
||||
elif bashio::config.equals 'mode' '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+=" "
|
||||
for server in $(bashio::config "ntp_${mode}"); do
|
||||
bashio::log.debug "Adding server ${server}"
|
||||
echo "${mode} ${server} iburst" >> ${CHRONY_CONF}
|
||||
serverlist+=("${server}")
|
||||
done
|
||||
echo "initstepslew 10 ${serverlist}" >> ${CHRONY_CONF}
|
||||
|
||||
echo "initstepslew 10 ${serverlist[*]}" >> ${CHRONY_CONF}
|
||||
|
|
|
@ -5,12 +5,11 @@
|
|||
# ==============================================================================
|
||||
declare -a options
|
||||
|
||||
options+=("-d")
|
||||
if bashio::config.false 'set_system_clock'
|
||||
then
|
||||
options+=("-x")
|
||||
fi
|
||||
|
||||
bashio::log.info "Starting chronyd..."
|
||||
|
||||
options+=(-d)
|
||||
if bashio::config.false 'set_system_clock'; then
|
||||
options+=(-x)
|
||||
fi
|
||||
|
||||
exec chronyd "${options[@]}"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue