check() {
load_package_config
- local c string="$1"
+ local c string="$1"
c="$(grep -c "$string" "$outputFile")"
+ c="${c:-0}"
if [ ! -s "$outputFile" ]; then
echo "No block-list ('$outputFile') found."
elif [ -z "$string" ]; then
echo "Usage: /etc/init.d/${packageName} check string"
elif [ "$c" -gt 0 ]; then
- if [ "$c" -gt 1 ]; then
+ if [ "$c" -eq 1 ]; then
+ echo "Found 1 match for '$string' in '$outputFile':"
+ elif [ "$c" -le 20 ]; then
echo "Found $c matches for '$string' in '$outputFile':"
else
- echo "Found 1 match for '$string' in '$outputFile':"
+ echo "Found $c matches for '$string' in '$outputFile'."
+ fi
+ if [ "$c" -le 20 ]; then
+ case "$targetDNS" in
+ dnsmasq.addnhosts)
+ grep "$string" "$outputFile" | sed 's|^127.0.0.1 ||;s|^:: ||;';;
+ dnsmasq.conf)
+ grep "$string" "$outputFile" | sed 's|local=/||;s|/$||;';;
+ dnsmasq.ipset)
+ grep "$string" "$outputFile" | sed 's|ipset=/||;s|/adb$||;';;
+ dnsmasq.servers)
+ grep "$string" "$outputFile" | sed 's|server=/||;s|/$||;';;
+ unbound.adb_list)
+ grep "$string" "$outputFile" | sed 's|^local-zone: "||;s|" static$||;';;
+ esac
fi
- case "$targetDNS" in
- dnsmasq.addnhosts)
- grep "$string" "$outputFile" | sed 's|^127.0.0.1 ||;s|^:: ||;';;
- dnsmasq.conf)
- grep "$string" "$outputFile" | sed 's|local=/||;s|/$||;';;
- dnsmasq.ipset)
- grep "$string" "$outputFile" | sed 's|ipset=/||;s|/adb$||;';;
- dnsmasq.servers)
- grep "$string" "$outputFile" | sed 's|server=/||;s|/$||;';;
- unbound.adb_list)
- grep "$string" "$outputFile" | sed 's|^local-zone: "||;s|" static$||;';;
- esac
else
- echo "The $string is not found in current block-list ('$outputFile')."
+ echo "The '$string' is not found in current block-list ('$outputFile')."
fi
}