From 1b05237ebb0ef83d2b0603369347da9832711c82 Mon Sep 17 00:00:00 2001 From: Timo Weingärtner Date: Mon, 7 Jan 2013 17:31:27 +0100 Subject: implement caching for filtered version filtering can take a long time, about 1m for 20k key entries --- update-openssh-known-hosts | 44 ++++++++++++++++++++++++-------------------- 1 file 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 -- cgit v1.2.3