Skip to content

Commit a8fe178

Browse files
committed
run: use $iplist_dir and $status_file values set in the -common and -setvars scripts; fixed ip lists removal; improved logic for fetch and apply results tracking
1 parent 63f6903 commit a8fe178

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

geoip-shell-run.sh

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,6 @@ fi
9898
trimsp lists
9999
fast_el_cnt "$lists" " " lists_cnt
100100

101-
iplist_dir="$datadir/ip_lists"
102-
103-
status_file="$iplist_dir/status"
104-
105101
failed_lists_cnt=0
106102

107103
[ "$_fw_backend" = ipt ] && raw_mode="-r"
@@ -130,10 +126,10 @@ trap 'set +f; rm -f \"$iplist_dir/\"*.iplist 2>/dev/null; eval "$trap_args_unloc
130126
# check for valid action and translate *run action to *apply action
131127
# *apply does the same thing whether we want to update, apply(refresh) or to add a new ip list, which is why this translation is needed
132128
case "$action_run" in
133-
add) action_apply=add ;;
129+
add) action_apply=add; [ ! "$lists" ] && die "no list id's were specified!" ;;
134130
# if firewall is in incoherent state, force re-fetch
135131
update) action_apply=add; check_lists_coherence || force="-f" ;;
136-
remove) action_apply=remove ;;
132+
remove) action_apply=remove; rm_lists="$lists" ;;
137133
restore)
138134
check_lists_coherence -n 2>/dev/null && { echolog "Geoip firewall rules and sets are Ok. Exiting."; die 0; }
139135
if [ "$nobackup" ]; then
@@ -157,22 +153,24 @@ esac
157153

158154
#### Daemon loop
159155

156+
unset echolists ok_lists missing_lists lists_fetch fetched_lists
157+
160158
[ ! "$daemon_mode" ] && max_attempts=1
161-
attempt=0 secs=4 ok_lists='' missing_lists=
159+
case "$action_run" in add|update) lists_fetch="$lists" ;; *) max_attempts=1; esac
160+
161+
attempt=0 secs=4
162162
while true; do
163163
attempt=$((attempt+1))
164164
secs=$((secs+1))
165165
[ "$daemon_mode" ] && [ $attempt -gt $max_attempts ] && die "Giving up."
166166

167167
### Fetch ip lists
168168

169-
if [ "$action_apply" = add ]; then
170-
[ ! "$lists" ] && die "no list id's were specified!"
171-
169+
if [ "$action_apply" = add ] && [ "$lists_fetch" ]; then
172170
# mark all lists as failed in the status file before launching *fetch. if *fetch completes successfully, it will reset this
173-
setstatus "$status_file" "FailedLists=$lists"
171+
setstatus "$status_file" "FailedLists=$lists_fetch"
174172

175-
call_script "$i_script-fetch.sh" -l "$lists" -p "$iplist_dir" -s "$status_file" -u "$dl_source" "$force" "$raw_mode"
173+
call_script "$i_script-fetch.sh" -l "$lists_fetch" -p "$iplist_dir" -s "$status_file" -u "$dl_source" "$force" "$raw_mode"
176174

177175
# read *fetch results from the status file
178176
getstatus "$status_file" FailedLists failed_lists &&
@@ -197,14 +195,16 @@ while true; do
197195

198196
### Apply ip lists
199197

200-
san_str -s lists "$fetched_lists $ok_lists"
198+
lists_fetch=
199+
san_str -s ok_lists "$fetched_lists $ok_lists"
200+
san_str -s apply_lists "$ok_lists $rm_lists"
201201
apply_rv=0
202202
case "$action_run" in update|add|remove)
203-
[ ! "$lists" ] && {
203+
[ ! "$apply_lists" ] && {
204204
echolog "Firewall reconfiguration isn't required."; die 0
205205
}
206206

207-
call_script "$i_script-apply.sh" "$action_apply" -l "$lists"; apply_rv=$?
207+
call_script "$i_script-apply.sh" "$action_apply" -l "$apply_lists"; apply_rv=$?
208208
set +f; rm "$iplist_dir/"*.iplist 2>/dev/null; set -f
209209

210210
case "$apply_rv" in
@@ -213,7 +213,7 @@ while true; do
213213
echolog -err "*apply exited with code '254'. $FAIL execute action '$action_apply'." ;;
214214
*) debugprint "NOTE: *apply exited with error code '$apply_rv'."; die "$apply_rv"
215215
esac
216-
echolists=" for lists '$lists'"
216+
echolists=" for lists '$ok_lists$rm_lists'"
217217
esac
218218

219219
if check_lists_coherence; then

0 commit comments

Comments
 (0)