🔨 Simplifies add-on code logic

This commit is contained in:
Franck Nijhof 2019-03-20 13:00:49 +01:00
parent 16dffabaf7
commit 045e041f39
No known key found for this signature in database
GPG key ID: D62583BA8AB11CA3
3 changed files with 18 additions and 29 deletions

View file

@ -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

View file

@ -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}

View file

@ -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[@]}"