diff options
author | Timo Weingärtner <timo@tiwe.de> | 2013-01-07 17:31:27 +0100 |
---|---|---|
committer | Timo Weingärtner <timo@tiwe.de> | 2013-01-07 17:31:27 +0100 |
commit | 1b05237ebb0ef83d2b0603369347da9832711c82 (patch) | |
tree | 2f4dbdee17fbcb6b12cc9cc9fc8b2852e2ebc8a9 /update-openssh-known-hosts | |
parent | 8d177fb1f42cb80ffbf678669cd726d40f26f123 (diff) | |
download | openssh-known-hosts-1b05237ebb0ef83d2b0603369347da9832711c82.tar.gz |
implement caching for filtered version
filtering can take a long time, about 1m for 20k key entries
Diffstat (limited to 'update-openssh-known-hosts')
-rwxr-xr-x | update-openssh-known-hosts | 44 |
1 files changed, 24 insertions, 20 deletions
diff --git a/update-openssh-known-hosts b/update-openssh-known-hosts index e191f92..d9ef613 100755 --- a/update-openssh-known-hosts +++ b/update-openssh-known-hosts @@ -83,28 +83,32 @@ run-parts --list "${CONFDIR}/sources/" | while read sourcefile; do fi if [ -e ${source}/current ]; then 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}," + if [[ ${source}/filtered -ot ${source}/current ]] || [[ ${source}/filtered -ot ${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 - break - fi + done done - done - [ "$new_hostlist" ] || continue - echo "${new_hostlist%,} ${rest}" - done < ${source}/current | sort -u >&3 + [ "$new_hostlist" ] || continue + echo "${new_hostlist%,} ${rest}" + done < ${source}/current | sort -u >| ${source}/filtered.new + mv ${source}/filtered.new ${source}/filtered + fi + cat ${source}/filtered >&3 else sort -u ${source}/current >&3 fi |