🔨 Simplifies add-on code logic (#7)

This commit is contained in:
Franck Nijhof 2019-03-20 13:41:11 +01:00 committed by Paul Sinclair
parent 1bc9e0540a
commit 52b69cb20d
3 changed files with 18 additions and 29 deletions

View file

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

View file

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

View file

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