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