Skip to content

Commit

Permalink
Apply static IP changes without a reboot (#1723)
Browse files Browse the repository at this point in the history
Related tiny-pilot/tinypilot-pro#1172

This PR introduces the `apply-static-ip` script that replaces the use of
`reboot` to allow the static IP settings to take effect.

This code was originally reviewed in
tiny-pilot/tinypilot-pro#1175 before being
backported here.

<a data-ca-tag
href="https://codeapprove.com/pr/tiny-pilot/tinypilot/1723"><img
src="https://codeapprove.com/external/github-tag-allbg.png" alt="Review
on CodeApprove" /></a>
  • Loading branch information
jdeanwallace authored Jan 17, 2024
1 parent 88cf332 commit 13d1b53
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 8 deletions.
20 changes: 20 additions & 0 deletions debian-pkg/opt/tinypilot-privileged/scripts/apply-static-ip
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash
#
# Immediately apply the current static IP config to the device.

# Exit on first failure.
set -e

# Echo commands before executing them, by default to stderr.
set -x

# Exit on unset variable.
set -u

# 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
10 changes: 5 additions & 5 deletions debian-pkg/opt/tinypilot-privileged/scripts/set-static-ip
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@ fi
# Exit on unset variable.
set -u

# Use the unset-static-ip script to remove any existing configuration.
"${SCRIPT_DIR}/unset-static-ip" --quiet
# 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
Expand All @@ -157,11 +157,11 @@ fi
echo "${MARKER_END}"
} | sudo tee --append "${CONFIG_FILE}" > /dev/null

# Changes require a reboot so prompt the user.
# Apply changes.
"${SCRIPT_DIR}/apply-static-ip"

echo "A static local IP address has been set."
echo " Interface: ${INTERFACE}"
echo " IP Address: ${IP_ADDRESS}"
echo " Routers: ${ROUTERS}"
echo " Domain Name Servers: ${DNS}"
echo ""
echo "Reboot your TinyPilot device to apply the changes."
6 changes: 3 additions & 3 deletions debian-pkg/opt/tinypilot-privileged/scripts/unset-static-ip
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ set -u
# Remove any existing marker sections from the config file.
"${SCRIPT_DIR}/strip-marker-sections" /etc/dhcpcd.conf

# Changes require a reboot so prompt the user.
# Apply changes.
"${SCRIPT_DIR}/apply-static-ip"

if [[ "${QUIET}" == "false" ]] ; then
echo "Any changes made by the set-static-ip script have been reverted."
echo ""
echo "Reboot your TinyPilot device to apply the changes."
fi

0 comments on commit 13d1b53

Please sign in to comment.