Skip to content

Commit cbed973

Browse files
committed
ci: fix policy shellcheck warnings
1 parent 548e91a commit cbed973

4 files changed

Lines changed: 39 additions & 11 deletions

File tree

lib/policy/engine.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ policy_array_matches() {
1717
for pattern in "$@"; do
1818
[[ -n "${pattern}" ]] || continue
1919
glob="${pattern//+/*}"
20-
if [[ "${needle}" == ${glob} ]]; then
21-
return 0
22-
fi
20+
case "${needle}" in
21+
${glob}) return 0 ;;
22+
esac
2323
done
2424
return 1
2525
}

lib/policy/policy.sh

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,26 @@ policy_json_array() {
5353
printf ']'
5454
}
5555

56+
policy_active_ifaces_json() {
57+
local raw item
58+
local -a items=()
59+
60+
raw="$(policy_read_state_value "active_ifaces" || true)"
61+
if [[ -z "${raw}" ]]; then
62+
printf '[]'
63+
return 0
64+
fi
65+
66+
IFS=',' read -r -a items <<<"${raw}"
67+
for item in "${items[@]}"; do
68+
[[ -n "${item}" ]] || continue
69+
policy_json_array "${items[@]}"
70+
return 0
71+
done
72+
73+
printf '[]'
74+
}
75+
5676
policy_write_state() {
5777
local status="${1:?missing status}"
5878
local last_event="${2:-}"
@@ -206,14 +226,14 @@ policy_monitor_loop() {
206226
pending_event="${line}"
207227
pending_ts="$(timestamp_utc)"
208228
case "${line}" in
209-
*inet*|*inet6*|*address*|*Deleted*) refresh_requested="true" ;;
229+
*inet*|*address*|*Deleted*) refresh_requested="true" ;;
210230
esac
211231

212232
while IFS= read -r -t "${BOX_POLICY_DEBOUNCE_SECONDS}" next_line <&"${POLICY_EVENTS[0]}"; do
213233
pending_event="${next_line}"
214234
pending_ts="$(timestamp_utc)"
215235
case "${next_line}" in
216-
*inet*|*inet6*|*address*|*Deleted*) refresh_requested="true" ;;
236+
*inet*|*address*|*Deleted*) refresh_requested="true" ;;
217237
esac
218238
marker_state="$(if policy_disable_marker_present; then printf 'present'; else printf 'absent'; fi)"
219239
if [[ "${marker_state}" != "${previous_marker_state}" ]]; then
@@ -346,7 +366,7 @@ policy_status_json() {
346366
"$(json_pair "applied_state" "$(policy_read_state_value "applied_state" || printf 'unchanged')")" \
347367
"$(json_pair "proxy_mode" "${BOX_POLICY_PROXY_MODE}")" \
348368
"$(json_num_pair "debounce_seconds" "${BOX_POLICY_DEBOUNCE_SECONDS}")" \
349-
"\"active_ifaces\":$(policy_json_array $(tr ',' ' ' <<<"$(policy_read_state_value "active_ifaces" || true)"))" \
369+
"\"active_ifaces\":$(policy_active_ifaces_json)" \
350370
"$(json_bool_pair "wifi_connected" "$(policy_read_state_value "wifi_connected" || printf 'false')")" \
351371
"$(json_pair "ssid" "$(policy_read_state_value "ssid" || true)")" \
352372
"$(json_pair "bssid" "$(policy_read_state_value "bssid" || true)")" \

packaging/scripts/systemd-lifecycle.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Usage:
1919
Notes:
2020
- disable/restart actions only manage units and do not delete /etc/box or /var/lib/box.
2121
- enable starts the core units, conditionally enables policy if configured, and enables the default
22-
scheduled updater timer (`box-update-all.timer`).
22+
scheduled updater timer (box-update-all.timer).
2323
- use package removal + manual purge only when full cleanup is explicitly desired.
2424
USAGE
2525
}

tests/integration/test_policy.sh

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,15 @@ cleanup() {
1111
local pid
1212
if [[ -f "${BOX_RUN_DIR}/policy.pid" ]]; then
1313
pid="$(tr -d '[:space:]' <"${BOX_RUN_DIR}/policy.pid" || true)"
14-
[[ -n "${pid:-}" ]] && kill -TERM "${pid}" >/dev/null 2>&1 || true
14+
if [[ -n "${pid:-}" ]]; then
15+
kill -TERM "${pid}" >/dev/null 2>&1 || true
16+
fi
1517
fi
1618
if [[ -f "${BOX_RUN_DIR}/box.pid" ]]; then
1719
pid="$(tr -d '[:space:]' <"${BOX_RUN_DIR}/box.pid" || true)"
18-
[[ -n "${pid:-}" ]] && kill -TERM "${pid}" >/dev/null 2>&1 || true
20+
if [[ -n "${pid:-}" ]]; then
21+
kill -TERM "${pid}" >/dev/null 2>&1 || true
22+
fi
1923
fi
2024
rm -rf "${TMP_DIR}"
2125
}
@@ -93,11 +97,15 @@ force_reset_runtime() {
9397
local pid
9498
if [[ -f "${BOX_RUN_DIR}/policy.pid" ]]; then
9599
pid="$(tr -d '[:space:]' <"${BOX_RUN_DIR}/policy.pid" || true)"
96-
[[ -n "${pid:-}" ]] && kill -TERM "${pid}" >/dev/null 2>&1 || true
100+
if [[ -n "${pid:-}" ]]; then
101+
kill -TERM "${pid}" >/dev/null 2>&1 || true
102+
fi
97103
fi
98104
if [[ -f "${BOX_RUN_DIR}/box.pid" ]]; then
99105
pid="$(tr -d '[:space:]' <"${BOX_RUN_DIR}/box.pid" || true)"
100-
[[ -n "${pid:-}" ]] && kill -TERM "${pid}" >/dev/null 2>&1 || true
106+
if [[ -n "${pid:-}" ]]; then
107+
kill -TERM "${pid}" >/dev/null 2>&1 || true
108+
fi
101109
fi
102110
sleep 1
103111
rm -rf "${BOX_RUN_DIR}" "${BOX_VAR_DIR}" "${BOX_LOG_DIR}"

0 commit comments

Comments
 (0)