fix shellcheck warnings in helper scripts
This commit is contained in:
parent
b0ec18c672
commit
cafc2b7a75
@ -3,18 +3,18 @@
|
||||
SERVERFILE=$SAVEDIR/chrony.servers.$interface
|
||||
|
||||
chrony_config() {
|
||||
rm -f $SERVERFILE
|
||||
rm -f "$SERVERFILE"
|
||||
if [ "$PEERNTP" != "no" ]; then
|
||||
for server in $new_ntp_servers; do
|
||||
echo "$server ${NTPSERVERARGS:-iburst}" >> $SERVERFILE
|
||||
echo "$server ${NTPSERVERARGS:-iburst}" >> "$SERVERFILE"
|
||||
done
|
||||
/usr/libexec/chrony-helper update-daemon || :
|
||||
fi
|
||||
}
|
||||
|
||||
chrony_restore() {
|
||||
if [ -f $SERVERFILE ]; then
|
||||
rm -f $SERVERFILE
|
||||
if [ -f "$SERVERFILE" ]; then
|
||||
rm -f "$SERVERFILE"
|
||||
/usr/libexec/chrony-helper update-daemon || :
|
||||
fi
|
||||
}
|
||||
|
@ -12,8 +12,8 @@ helper_dir=/var/run/chrony-helper
|
||||
added_servers_file=$helper_dir/added_servers
|
||||
|
||||
network_sysconfig_file=/etc/sysconfig/network
|
||||
dhclient_servers_files=/var/lib/dhclient/chrony.servers.*
|
||||
dnssrv_servers_files=$helper_dir/dnssrv@*
|
||||
dhclient_servers_files="/var/lib/dhclient/chrony.servers.*"
|
||||
dnssrv_servers_files="$helper_dir/dnssrv@*"
|
||||
dnssrv_timer_prefix=chrony-dnssrv@
|
||||
|
||||
. $network_sysconfig_file &> /dev/null
|
||||
@ -50,27 +50,30 @@ update_daemon() {
|
||||
|
||||
all_servers=$(
|
||||
echo "$all_servers_with_args" |
|
||||
while read server serverargs; do
|
||||
while read -r server serverargs; do
|
||||
echo "$server"
|
||||
done | sort -u)
|
||||
added_servers=$( (
|
||||
cat $added_servers_file 2> /dev/null
|
||||
echo "$all_servers_with_args" |
|
||||
while read server serverargs; do
|
||||
while read -r server serverargs; do
|
||||
[ -z "$server" ] && continue
|
||||
chrony_command "add server $server $serverargs" &> /dev/null &&
|
||||
echo "$server"
|
||||
done) | sort -u)
|
||||
|
||||
comm -23 <(echo -n "$added_servers") <(echo -n "$all_servers") |
|
||||
while read server; do
|
||||
while read -r server; do
|
||||
chrony_command "delete $server" &> /dev/null
|
||||
done
|
||||
|
||||
added_servers=$(comm -12 <(echo -n "$added_servers") <(echo -n "$all_servers"))
|
||||
|
||||
[ -n "$added_servers" ] && echo "$added_servers" > $added_servers_file ||
|
||||
if [ -n "$added_servers" ]; then
|
||||
echo "$added_servers" > $added_servers_file
|
||||
else
|
||||
rm -f $added_servers_file
|
||||
fi
|
||||
}
|
||||
|
||||
get_dnssrv_servers() {
|
||||
@ -81,10 +84,9 @@ get_dnssrv_servers() {
|
||||
return 1
|
||||
fi
|
||||
|
||||
output=$(dig "$name" srv +short +ndots=2 +search 2> /dev/null)
|
||||
[ $? -ne 0 ] && return 0
|
||||
output=$(dig "$name" srv +short +ndots=2 +search 2> /dev/null) || return 0
|
||||
|
||||
echo "$output" | while read prio weight port target; do
|
||||
echo "$output" | while read -r _ _ port target; do
|
||||
server=${target%.}
|
||||
[ -z "$server" ] && continue
|
||||
echo "$server port $port ${NTPSERVERARGS:-iburst}"
|
||||
@ -112,13 +114,19 @@ update_dnssrv_servers() {
|
||||
check_dnssrv_name "$name" || return 1
|
||||
|
||||
servers=$(get_dnssrv_servers "$name")
|
||||
[ -n "$servers" ] && echo "$servers" > "$srv_file" || rm -f "$srv_file"
|
||||
if [ -n "$servers" ]; then
|
||||
echo "$servers" > "$srv_file"
|
||||
else
|
||||
rm -f "$srv_file"
|
||||
fi
|
||||
}
|
||||
|
||||
set_dnssrv_timer() {
|
||||
local state=$1 name=$2
|
||||
local srv_file=$helper_dir/dnssrv@$name servers
|
||||
local timer=$dnssrv_timer_prefix$(systemd-escape "$name").timer
|
||||
local timer
|
||||
|
||||
timer=$dnssrv_timer_prefix$(systemd-escape "$name").timer || return 1
|
||||
|
||||
check_dnssrv_name "$name" || return 1
|
||||
|
||||
@ -155,8 +163,10 @@ is_source_line() {
|
||||
}
|
||||
|
||||
list_static_sources() {
|
||||
while read line; do
|
||||
is_source_line "$line" && echo "$line" || :
|
||||
while read -r line; do
|
||||
if is_source_line "$line"; then
|
||||
echo "$line"
|
||||
fi
|
||||
done < $chrony_conf
|
||||
}
|
||||
|
||||
@ -165,11 +175,11 @@ set_static_sources() {
|
||||
|
||||
new_config=$(
|
||||
sources=$(
|
||||
while read line; do
|
||||
while read -r line; do
|
||||
is_source_line "$line" && echo "$line"
|
||||
done)
|
||||
|
||||
while read line; do
|
||||
while read -r line; do
|
||||
if ! is_source_line "$line"; then
|
||||
echo "$line"
|
||||
continue
|
||||
@ -178,9 +188,12 @@ set_static_sources() {
|
||||
tmp_sources=$(
|
||||
local removed=0
|
||||
|
||||
echo "$sources" | while read line2; do
|
||||
[ "$removed" -ne 0 -o "$line" != "$line2" ] && \
|
||||
echo "$line2" || removed=1
|
||||
echo "$sources" | while read -r line2; do
|
||||
if [ "$removed" -ne 0 ] || [ "$line" != "$line2" ]; then
|
||||
echo "$line2"
|
||||
else
|
||||
removed=1
|
||||
fi
|
||||
done)
|
||||
|
||||
[ "$sources" == "$tmp_sources" ] && continue
|
||||
|
Loading…
Reference in New Issue
Block a user