Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Static IP address scripts Bookworm compatibility #1843

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions debian-pkg/opt/tinypilot-privileged/scripts/apply-static-ip
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,18 @@ set -x
# Exit on unset variable.
set -u

# Determine which version of the OS is running.
OS_VERSION="$(lsb_release --release --short)"

# Ignore hangup signals to avoid exiting the shell when the network interface
# is flushed and a new IP is assigned. This was an issue when running the script
# manually via a remote shell.
trap '' HUP
ip address flush dev eth0
systemctl restart \
dhcpcd.service
if [[ "${OS_VERSION}" == 11 ]]; then
ip address flush dev eth0
systemctl restart \
dhcpcd.service
else
nmcli connection down 'Wired connection 1'
nmcli connection up 'Wired connection 1'
fi
47 changes: 29 additions & 18 deletions debian-pkg/opt/tinypilot-privileged/scripts/set-static-ip
Original file line number Diff line number Diff line change
Expand Up @@ -137,26 +137,37 @@ fi
# Exit on unset variable.
set -u

# Remove any existing automated configuration.
"${SCRIPT_DIR}/strip-marker-sections" "${CONFIG_FILE}"

# Only proceed if no other configuration exists.
if grep -q "^interface ${INTERFACE}" "${CONFIG_FILE}" ; then
echo "An existing configuration exists in ${CONFIG_FILE} for ${INTERFACE}." >&2
echo "Please remove the existing configuration and try again." >&2
exit 1
# Determine which version of the OS is running.
OS_VERSION="$(lsb_release --release --short)"

if [[ "${OS_VERSION}" == 11 ]]; then
# Remove any existing automated configuration.
"${SCRIPT_DIR}/strip-marker-sections" "${CONFIG_FILE}"

# Only proceed if no other configuration exists.
if grep -q "^interface ${INTERFACE}" "${CONFIG_FILE}" ; then
echo "An existing configuration exists in ${CONFIG_FILE} for ${INTERFACE}." >&2
echo "Please remove the existing configuration and try again." >&2
exit 1
fi

# Write out the new configuration.
{
echo "${MARKER_START}"
echo "interface ${INTERFACE}"
echo "static ip_address=${IP_ADDRESS}"
echo "static routers=${ROUTERS}"
echo "static domain_name_servers=${DNS}"
echo "${MARKER_END}"
} | sudo tee --append "${CONFIG_FILE}" > /dev/null
else
nmcli connection modify 'Wired connection 1' \
ipv4.method manual \
ipv4.addresses "${IP_ADDRESS}" \
ipv4.gateway "${ROUTERS}" \
ipv4.dns "${DNS}"
fi

# Write out the new configuration.
{
echo "${MARKER_START}"
echo "interface ${INTERFACE}"
echo "static ip_address=${IP_ADDRESS}"
echo "static routers=${ROUTERS}"
echo "static domain_name_servers=${DNS}"
echo "${MARKER_END}"
} | sudo tee --append "${CONFIG_FILE}" > /dev/null

# Apply changes.
"${SCRIPT_DIR}/apply-static-ip"

Expand Down
15 changes: 13 additions & 2 deletions debian-pkg/opt/tinypilot-privileged/scripts/unset-static-ip
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,19 @@ fi
# Exit on unset variable
set -u

# Remove any existing marker sections from the config file.
"${SCRIPT_DIR}/strip-marker-sections" /etc/dhcpcd.conf
# Determine which version of the OS is running.
OS_VERSION="$(lsb_release --release --short)"

if [[ "${OS_VERSION}" == 11 ]]; then
# Remove any existing marker sections from the config file.
"${SCRIPT_DIR}/strip-marker-sections" /etc/dhcpcd.conf
else
nmcli connection modify 'Wired connection 1' \
ipv4.method auto \
ipv4.addresses '' \
ipv4.gateway '' \
ipv4.dns ''
fi

# Apply changes.
"${SCRIPT_DIR}/apply-static-ip"
Expand Down