Fixed whitespace handling in domain lists

All whitespace removed from host entries before handling, blank lines
are skipped

This WILL mangle comments in the map files, but is best to ensure
working files
This commit is contained in:
VibroAxe 2019-02-17 14:32:16 +00:00
parent 12f9397291
commit 1cf7dc39fd

View file

@ -15,12 +15,22 @@ echo "map \$http_host \$cacheidentifier {" >> $OUTPUTFILE
echo " hostnames;" >> $OUTPUTFILE
echo " default \$http_host;" >> $OUTPUTFILE
jq -r '.cache_domains | to_entries[] | .key' cache_domains.json | while read CACHE_ENTRY; do
#for each cache entry, find the cache indentifier
CACHE_IDENTIFIER=$(jq -r ".cache_domains[$CACHE_ENTRY].name" cache_domains.json)
jq -r ".cache_domains[$CACHE_ENTRY].domain_files | to_entries[] | .key" cache_domains.json | while read CACHEHOSTS_FILEID; do
#Get the key for each domain files
jq -r ".cache_domains[$CACHE_ENTRY].domain_files[$CACHEHOSTS_FILEID]" cache_domains.json | while read CACHEHOSTS_FILENAME; do
#Get the actual file name
echo Reading cache ${CACHE_IDENTIFIER} from ${CACHEHOSTS_FILENAME}
cat ${CACHEHOSTS_FILENAME} | while read CACHE_HOST; do
echo " ${CACHE_HOST} ${CACHE_IDENTIFIER};" >> $OUTPUTFILE
#for each file in the hosts file
#remove all whitespace (mangles comments but ensures valid config files)
echo "host: $CACHE_HOST"
CACHE_HOST=${CACHE_HOST// /}
echo "new host: $CACHE_HOST"
if [ ! "x${CACHE_HOST}" == "x" ]; then
echo " ${CACHE_HOST} ${CACHE_IDENTIFIER};" >> $OUTPUTFILE
fi
done
done
done