#!/usr/bin/bash # save-restore - restore files made with ipset(1) save # Copyright (C)2026 Corwin Brust # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # You should have received a copy of the GNU General Public License # along with this program. If not, see . # ################# # # Work in the current directory # 1. Look for files named on the command line # 1.1 ..on the command line or, otherwise # 1.2 .. in CWD as *.save # 2. Create a flat-file "DB" with lines in the form NAME MAX # 3. Sort and reduce DB combining counts for non-empty sets # 4. Filter files into ipset restore # ################# folder=${folder:-} savext=${savext:-.save} db=${db:-name-maxelem.db} dbtmp=${dbtmp:-$db.tmp} ipset=${ipset:-$(which ipset)} ipsetcmd=${ipsetcmd:-restore} scriptdir=${scriptdir:-$(dirname $0)} savecnt="${scriptdir}/save-count.pl" sortcnt="${scriptdir}/combine-counts.pl" loadset="${scriptdir}/combine-saves.pl" files=${files:-"$@"} if test -z "$files" ; then files=$(ls -1 ${folder}*${savext} 2>/dev/null) fi if test -z "$files" ; then echo "No ipset save files."; exit 1; fi #echo "'$files'" cat "$files" | \ $savecnt >$dbtmp \ && $sortcnt <$dbtmp >$db \ && cat "$files" \ | $loadset $db \ | $ipset $ipsetcmd RV=$? rm -f $dbtmp 2>/dev/null exit $RV;