#!/bin/sh
#
# Univention Setup
#  gateway change script
#
# SPDX-FileCopyrightText: 2004-2025 Univention GmbH
# SPDX-License-Identifier: AGPL-3.0-only

# shellcheck source=../setup_utils.sh
. /usr/lib/univention-system-setup/scripts/setup_utils.sh

info_header "$0" "$(gettext "Setting IPv4 gateway")"

[ "$check_ldap_access" = "1" ] &&
	exit 0

gateway="$(get_profile_var gateway)" ||
	exit 0

if [ -z "$gateway" ]; then
	univention-config-registry unset gateway
	ip route del default
else
	univention-config-registry set gateway="$gateway"
	ip route replace default via "$gateway"
fi

if [ -d "/var/lib/univention-system-setup/gateway.post" ]; then
	old_gateway="$(univention-config-registry get gateway)"
	run-parts /var/lib/univention-system-setup/gateway.post --arg="$old_gateway" --arg="$gateway"
fi

exit 0
