diff options
author | Timo Weingärtner <timo@tiwe.de> | 2013-01-04 21:16:37 +0100 |
---|---|---|
committer | Timo Weingärtner <timo@tiwe.de> | 2013-01-07 14:18:40 +0100 |
commit | 8d177fb1f42cb80ffbf678669cd726d40f26f123 (patch) | |
tree | 4d283d547e78b7a5e9a7f94fc60f68a1dcdf1c97 /update-openssh-known-hosts | |
parent | b976b61bd47d0a404d94e390c429ac5e336b261a (diff) | |
download | openssh-known-hosts-8d177fb1f42cb80ffbf678669cd726d40f26f123.tar.gz |
implement hostname filtering
Fixes GH-1.
Diffstat (limited to 'update-openssh-known-hosts')
-rwxr-xr-x | update-openssh-known-hosts | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/update-openssh-known-hosts b/update-openssh-known-hosts index 8b77aee..e191f92 100755 --- a/update-openssh-known-hosts +++ b/update-openssh-known-hosts @@ -82,7 +82,32 @@ run-parts --list "${CONFDIR}/sources/" | while read sourcefile; do mv ${source}/new ${source}/current fi if [ -e ${source}/current ]; then - sort -u ${source}/current >&3 + if [ -e "${sourcefile}.filter" ]; then + mapfile -t filter < "${sourcefile}.filter" + for i in ${!filter[@]}; do + if [[ ${filter[$i]} =~ ^($|#) ]]; then + unset filter[$i] + fi + done + while read hostlist rest; do + IFS=, read -a hostarray <<<$hostlist + new_hostlist='' + for host in ${hostarray[@]}; do + for rule in "${filter[@]}"; do + if [[ ${host} =~ ${rule#* } ]]; then + if [[ ${rule%% *} =~ ^[aopy] ]]; then + new_hostlist="${new_hostlist}${host}," + fi + break + fi + done + done + [ "$new_hostlist" ] || continue + echo "${new_hostlist%,} ${rest}" + done < ${source}/current | sort -u >&3 + else + sort -u ${source}/current >&3 + fi fi done 3>| "${OUTFILE}.new" |