diff --git a/debian-pkg/opt/tinypilot-privileged/scripts/apply-static-ip b/debian-pkg/opt/tinypilot-privileged/scripts/apply-static-ip index 139eb0f24..fdef9c85a 100755 --- a/debian-pkg/opt/tinypilot-privileged/scripts/apply-static-ip +++ b/debian-pkg/opt/tinypilot-privileged/scripts/apply-static-ip @@ -11,10 +11,19 @@ set -x # Exit on unset variable. set -u +# Determine which version of the OS is running. +OS_VERSION="$(lsb_release --release --short)" +readonly OS_VERSION + # 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 diff --git a/debian-pkg/opt/tinypilot-privileged/scripts/set-static-ip b/debian-pkg/opt/tinypilot-privileged/scripts/set-static-ip index acad26d65..3ca2b8eec 100755 --- a/debian-pkg/opt/tinypilot-privileged/scripts/set-static-ip +++ b/debian-pkg/opt/tinypilot-privileged/scripts/set-static-ip @@ -137,26 +137,38 @@ 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)" +readonly OS_VERSION + +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" diff --git a/debian-pkg/opt/tinypilot-privileged/scripts/unset-static-ip b/debian-pkg/opt/tinypilot-privileged/scripts/unset-static-ip index 88c866e58..66f926608 100755 --- a/debian-pkg/opt/tinypilot-privileged/scripts/unset-static-ip +++ b/debian-pkg/opt/tinypilot-privileged/scripts/unset-static-ip @@ -58,8 +58,20 @@ 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)" +readonly OS_VERSION + +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"