Files
computer-playbook/scripts/system/network/ipv6/restore.sh
kevinveenbirkenbachandClaude Opus 4.7 c02229b4be refactor(make): align targets to domain prefixes (compose-, network-, etc.)
Apply a consistent naming convention to the Make target inventory so
every target is grouped by its domain:

- compose-*  (compose-up/down/restart/stop/exec/inner-run)
- network-*  (network-dns-setup/remove, network-ipv6-disable/restore,
              network-refresh, network-trust-ca)
- security-* (security-apparmor-restore/teardown)
- diagnose-* (diagnose-network, diagnose-disk-usage)
- fix-*      (fix-chmod, fix-dockerignore)
- clean-*    (clean-cache, clean-pycache-dirs)
- install-*  (install-agent)
- meta-*     (meta-list, meta-tree, meta-mig)

Drop the stale debug-network target and reintroduce its functionality
as diagnose-network. Cascade renames through:

- Makefile (.PHONY entries, prereqs, recursive $(MAKE) calls)
- contributor docs, agent-iteration docs, role-level docs
- bundle README, environment scripts, install/lint/test wrappers
- AGENTS.md, CLAUDE.md, compose/cache.override.yml, .github/workflows

Historical entries under docs/requirements/ and changelog/ stay
untouched as audit logs.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-21 21:00:45 +02:00

98 lines
3.0 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
STATE_FILE="/tmp/infinito-dev-environment-ipv6.state"
if [[ "${EUID:-$(id -u)}" -ne 0 ]]; then
echo "[ipv6] error: restore.sh must be run as root (for example via 'sudo' or 'make network-ipv6-restore')" >&2
exit 1
fi
restore_existing_interfaces() {
local iface
local value
if ! declare -p IFACE_DISABLE_IPV6 >/dev/null 2>&1; then
return 0
fi
for iface in "${!IFACE_DISABLE_IPV6[@]}"; do
[[ "${iface}" == "all" || "${iface}" == "default" ]] && continue
value="${IFACE_DISABLE_IPV6[${iface}]}"
if ! sysctl -w "net.ipv6.conf.${iface}.disable_ipv6=${value}" >/dev/null 2>&1; then
echo "[ipv6] warning: cannot restore net.ipv6.conf.${iface}.disable_ipv6"
fi
done
}
restart_docker_service() {
if ! command -v systemctl >/dev/null 2>&1; then
echo "[ipv6] warning: systemctl is unavailable; skipping docker.service restart"
return 0
fi
if ! systemctl list-unit-files docker.service >/dev/null 2>&1; then
echo "[ipv6] warning: docker.service is unavailable; skipping docker.service restart"
return 0
fi
echo "[ipv6] restarting docker.service"
if ! systemctl restart docker.service >/dev/null 2>&1; then
echo "[ipv6] warning: failed to restart docker.service"
return 0
fi
echo "[ipv6] restarted docker.service"
}
if ! command -v sysctl >/dev/null 2>&1; then
echo "[ipv6] skipping restore: sysctl is unavailable in this environment"
exit 0
fi
if [[ ! -f "${STATE_FILE}" ]]; then
echo "[ipv6] no saved state found; skipping restore"
exit 0
fi
# shellcheck disable=SC1090
source "${STATE_FILE}"
: "${ALL_DISABLE_IPV6:?Missing ALL_DISABLE_IPV6 in ${STATE_FILE}}"
: "${DEFAULT_DISABLE_IPV6:?Missing DEFAULT_DISABLE_IPV6 in ${STATE_FILE}}"
if ! current_all="$(sysctl -n net.ipv6.conf.all.disable_ipv6 2>/dev/null)"; then
echo "[ipv6] skipping restore: kernel does not expose net.ipv6.conf.all.disable_ipv6"
exit 0
fi
if ! current_default="$(sysctl -n net.ipv6.conf.default.disable_ipv6 2>/dev/null)"; then
echo "[ipv6] skipping restore: kernel does not expose net.ipv6.conf.default.disable_ipv6"
exit 0
fi
echo "[ipv6] current: all=${current_all} default=${current_default}"
echo "[ipv6] restoring: all=${ALL_DISABLE_IPV6} default=${DEFAULT_DISABLE_IPV6}"
if ! sysctl -w "net.ipv6.conf.all.disable_ipv6=${ALL_DISABLE_IPV6}" >/dev/null; then
echo "[ipv6] skipping restore: cannot update net.ipv6.conf.all.disable_ipv6"
exit 0
fi
if ! sysctl -w "net.ipv6.conf.default.disable_ipv6=${DEFAULT_DISABLE_IPV6}" >/dev/null; then
if ! sysctl -w "net.ipv6.conf.all.disable_ipv6=${current_all}" >/dev/null 2>&1; then
echo "[ipv6] warning: failed to restore net.ipv6.conf.all.disable_ipv6"
fi
echo "[ipv6] skipping restore: cannot update net.ipv6.conf.default.disable_ipv6"
exit 0
fi
restore_existing_interfaces
restart_docker_service
rm -f "${STATE_FILE}"
echo "[ipv6] restored for all, default, and currently existing interfaces"
echo "[ipv6] note: make network-ipv6-restore calls make network-refresh after the docker.service restart"