#!/bin/bash # vi: et sts=4 sw=4 ts=4 set -e WORKDIR=${0%/*} CFG=$WORKDIR/update.cfg . "$CFG" TEMP_FILES=() cleanup() { rm -f -- "${TEMP_FILES[@]}" } trap 'cleanup' EXIT for (( I = 0 ; I < ${#OUT[@]} ; ++I )); do MY_URL=${URL[$I]} MY_OUT=${OUT[$I]} if [[ -z $MY_URL ]]; then echo "$CFG: URL[$I] empty" >&2 exit 2 fi if [[ -z $MY_OUT ]]; then echo "$CFG: OUT[$I] empty" >&2 exit 2 fi TEMP_OUT=$(mktemp -t "${0##*/}.XXXXXX") TEMP_FILES+=("$TEMP_OUT") if [[ -f $MY_OUT ]]; then cp -a -- "$MY_OUT" "$TEMP_OUT" fi wget \ -O "$TEMP_OUT" \ "$MY_URL" if [[ -f $MY_OUT ]]; then chmod --reference="$MY_OUT" "$TEMP_OUT" if [[ -n $BACKUPSUFFIX ]]; then mv -- "$MY_OUT" "$MY_OUT$BACKUPSUFFIX" fi fi mkdir -p -- "${MY_OUT%/*}" mv -- "$TEMP_OUT" "$MY_OUT" # If the old one is the same, don't keep it around if [[ -n $BACKUPSUFFIX && -f $MY_OUT$BACKUPSUFFIX ]]; then if diff -q "$MY_OUT" "$MY_OUT$BACKUPSUFFIX"; then rm -f -- "$MY_OUT$BACKUPSUFFIX" fi fi done if [[ -n $BACKUPSUFFIX && -f $BLOCKLIST ]]; then mv -- "$BLOCKLIST" "$BLOCKLIST$BACKUPSUFFIX" fi "$WORKDIR/make-block.pl" --out="$BLOCKLIST" # If the old one is the same the same, don't keep it around if [[ -n $BACKUPSUFFIX && -f $BLOCKLIST$BACKUPSUFFIX ]]; then if diff -q "$BLOCKLIST" "$BLOCKLIST$BACKUPSUFFIX"; then rm -f -- "$BLOCKLIST$BACKUPSUFFIX" fi fi if [[ -x /etc/rc.d/rc.dnsmasq ]]; then /etc/rc.d/rc.dnsmasq restart fi