1
0
mirror of https://github.com/tonusoo/koduinternet-cpe synced 2024-11-27 13:31:05 +02:00
koduinternet-cpe/conf/usr/local/sbin/rm-expired-prefixes

44 lines
1.3 KiB
Plaintext
Raw Normal View History

2023-06-15 17:55:10 +03:00
#!/usr/bin/env bash
# Title : rm-expired-prefixes
# Last modified date : 16.03.2023
# Author : Martin Tonusoo
# Description : Script removes expired "prefix" statements from
# /etc/radvd.conf file based on the expiration
# field(ISO 8601 timestamp) at the end of "prefix"
# line. The expiration field is added to the "prefix"
# statements by dhclient exit hook.
# Options :
# Notes :
radvd_conf="/etc/radvd.conf"
new_radvd_conf="${radvd_conf}.rm-expired-prefixes.$$"
while IFS= read -r line; do
case "$line" in
" prefix "*)
# Add the "prefix" statement if its timestamp
# is in the future.
if [[ "${line##* }" > $(date --iso-8601="seconds") ]]; then
echo "$line"
else
prefix="${line%% \{*}"
logger -t "rm-expired-prefixes" -p daemon.info \
"INFO: Removed expired ${prefix# } from $radvd_conf"
fi
;;
*)
echo "$line"
;;
esac
done < "$radvd_conf" >> "$new_radvd_conf"
chown --reference="$radvd_conf" "$new_radvd_conf"
chmod --reference="$radvd_conf" "$new_radvd_conf"
mv -f "$new_radvd_conf" "$radvd_conf"
systemctl is-active --quiet radvd.service && systemctl reload radvd.service