From 619ce4bb214895ed50964b072bc4405944fad502 Mon Sep 17 00:00:00 2001 From: David Brown Date: Thu, 22 Aug 2024 15:24:46 +0100 Subject: [PATCH 1/5] initial draft static IP bookworm compatibility --- .../scripts/apply-static-ip | 14 ++++- .../scripts/set-static-ip | 56 ++++++++++++------- .../scripts/unset-static-ip | 17 +++++- 3 files changed, 63 insertions(+), 24 deletions(-) diff --git a/debian-pkg/opt/tinypilot-privileged/scripts/apply-static-ip b/debian-pkg/opt/tinypilot-privileged/scripts/apply-static-ip index 139eb0f24..ec800e97c 100755 --- a/debian-pkg/opt/tinypilot-privileged/scripts/apply-static-ip +++ b/debian-pkg/opt/tinypilot-privileged/scripts/apply-static-ip @@ -11,10 +11,18 @@ set -x # Exit on unset variable. set -u +# Check which OS is running. +OS_CODENAME="$(grep '^VERSION_CODENAME' /etc/os-release | cut --delimiter '=' --fields 2)" + # 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_CODENAME}" == "bullseye" ]]; 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..4a3373d7d 100755 --- a/debian-pkg/opt/tinypilot-privileged/scripts/set-static-ip +++ b/debian-pkg/opt/tinypilot-privileged/scripts/set-static-ip @@ -131,32 +131,50 @@ readonly DNS # Default interface. if [[ -z "${INTERFACE}" ]] ; then - readonly INTERFACE="eth0" + if [[ "${OS_CODENAME}" == "bullseye" ]]; then + readonly INTERFACE="eth0" + else + readonly INTERFACE="Wired connection 1" + fi 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 +set -x + +# Check which OS is running. +OS_CODENAME="$(grep '^VERSION_CODENAME' /etc/os-release | cut --delimiter '=' --fields 2)" + +if [[ "${OS_CODENAME}" == "bullseye" ]]; 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 + # Bookworm process. + nmcli connection modify "${INTERFACE}" \ + 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..f138ed5bd 100755 --- a/debian-pkg/opt/tinypilot-privileged/scripts/unset-static-ip +++ b/debian-pkg/opt/tinypilot-privileged/scripts/unset-static-ip @@ -58,8 +58,21 @@ fi # Exit on unset variable set -u -# Remove any existing marker sections from the config file. -"${SCRIPT_DIR}/strip-marker-sections" /etc/dhcpcd.conf +# Check which OS is running. +OS_CODENAME="$(grep '^VERSION_CODENAME' /etc/os-release | cut --delimiter '=' --fields 2)" + +if [[ "${OS_CODENAME}" == "bullseye" ]]; then + # Remove any existing marker sections from the config file. + "${SCRIPT_DIR}/strip-marker-sections" /etc/dhcpcd.conf +else + # Bookworm process. + # we need the interface here - just assume physical interface for now? + nmcli connection modify 'Wired connection 1' \ + ipv4.method auto \ + ipv4.addresses '' \ + ipv4.gateway '' \ + ipv4.dns '' +fi # Apply changes. "${SCRIPT_DIR}/apply-static-ip" From ebd0b0e81c3a5a3402b6923fb50247656833df1e Mon Sep 17 00:00:00 2001 From: David Brown Date: Thu, 22 Aug 2024 15:36:31 +0100 Subject: [PATCH 2/5] comments --- debian-pkg/opt/tinypilot-privileged/scripts/set-static-ip | 3 --- debian-pkg/opt/tinypilot-privileged/scripts/unset-static-ip | 2 -- 2 files changed, 5 deletions(-) diff --git a/debian-pkg/opt/tinypilot-privileged/scripts/set-static-ip b/debian-pkg/opt/tinypilot-privileged/scripts/set-static-ip index 4a3373d7d..0586f4f30 100755 --- a/debian-pkg/opt/tinypilot-privileged/scripts/set-static-ip +++ b/debian-pkg/opt/tinypilot-privileged/scripts/set-static-ip @@ -141,8 +141,6 @@ fi # Exit on unset variable. set -u -set -x - # Check which OS is running. OS_CODENAME="$(grep '^VERSION_CODENAME' /etc/os-release | cut --delimiter '=' --fields 2)" @@ -167,7 +165,6 @@ if [[ "${OS_CODENAME}" == "bullseye" ]]; then echo "${MARKER_END}" } | sudo tee --append "${CONFIG_FILE}" > /dev/null else - # Bookworm process. nmcli connection modify "${INTERFACE}" \ ipv4.method manual \ ipv4.addresses "${IP_ADDRESS}" \ diff --git a/debian-pkg/opt/tinypilot-privileged/scripts/unset-static-ip b/debian-pkg/opt/tinypilot-privileged/scripts/unset-static-ip index f138ed5bd..23bf3d29a 100755 --- a/debian-pkg/opt/tinypilot-privileged/scripts/unset-static-ip +++ b/debian-pkg/opt/tinypilot-privileged/scripts/unset-static-ip @@ -65,8 +65,6 @@ if [[ "${OS_CODENAME}" == "bullseye" ]]; then # Remove any existing marker sections from the config file. "${SCRIPT_DIR}/strip-marker-sections" /etc/dhcpcd.conf else - # Bookworm process. - # we need the interface here - just assume physical interface for now? nmcli connection modify 'Wired connection 1' \ ipv4.method auto \ ipv4.addresses '' \ From 46d8bf68eb06444c07f9ffe986e0f294d6c3a35b Mon Sep 17 00:00:00 2001 From: David Brown Date: Thu, 22 Aug 2024 15:40:21 +0100 Subject: [PATCH 3/5] style --- debian-pkg/opt/tinypilot-privileged/scripts/apply-static-ip | 2 +- debian-pkg/opt/tinypilot-privileged/scripts/set-static-ip | 2 +- debian-pkg/opt/tinypilot-privileged/scripts/unset-static-ip | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/debian-pkg/opt/tinypilot-privileged/scripts/apply-static-ip b/debian-pkg/opt/tinypilot-privileged/scripts/apply-static-ip index ec800e97c..3990d416b 100755 --- a/debian-pkg/opt/tinypilot-privileged/scripts/apply-static-ip +++ b/debian-pkg/opt/tinypilot-privileged/scripts/apply-static-ip @@ -18,7 +18,7 @@ OS_CODENAME="$(grep '^VERSION_CODENAME' /etc/os-release | cut --delimiter '=' -- # is flushed and a new IP is assigned. This was an issue when running the script # manually via a remote shell. trap '' HUP -if [[ "${OS_CODENAME}" == "bullseye" ]]; then +if [[ "${OS_CODENAME}" == 'bullseye' ]]; then ip address flush dev eth0 systemctl restart \ dhcpcd.service diff --git a/debian-pkg/opt/tinypilot-privileged/scripts/set-static-ip b/debian-pkg/opt/tinypilot-privileged/scripts/set-static-ip index 0586f4f30..b9c68e799 100755 --- a/debian-pkg/opt/tinypilot-privileged/scripts/set-static-ip +++ b/debian-pkg/opt/tinypilot-privileged/scripts/set-static-ip @@ -144,7 +144,7 @@ set -u # Check which OS is running. OS_CODENAME="$(grep '^VERSION_CODENAME' /etc/os-release | cut --delimiter '=' --fields 2)" -if [[ "${OS_CODENAME}" == "bullseye" ]]; then +if [[ "${OS_CODENAME}" == 'bullseye' ]]; then # Remove any existing automated configuration. "${SCRIPT_DIR}/strip-marker-sections" "${CONFIG_FILE}" diff --git a/debian-pkg/opt/tinypilot-privileged/scripts/unset-static-ip b/debian-pkg/opt/tinypilot-privileged/scripts/unset-static-ip index 23bf3d29a..2b248906e 100755 --- a/debian-pkg/opt/tinypilot-privileged/scripts/unset-static-ip +++ b/debian-pkg/opt/tinypilot-privileged/scripts/unset-static-ip @@ -61,7 +61,7 @@ set -u # Check which OS is running. OS_CODENAME="$(grep '^VERSION_CODENAME' /etc/os-release | cut --delimiter '=' --fields 2)" -if [[ "${OS_CODENAME}" == "bullseye" ]]; then +if [[ "${OS_CODENAME}" == 'bullseye' ]]; then # Remove any existing marker sections from the config file. "${SCRIPT_DIR}/strip-marker-sections" /etc/dhcpcd.conf else From bc2fad71ee65117a07e278205efdf15aa90aab9e Mon Sep 17 00:00:00 2001 From: David Brown Date: Fri, 23 Aug 2024 15:27:12 +0100 Subject: [PATCH 4/5] Using version number insead of name. Hardcode connection name --- .../tinypilot-privileged/scripts/apply-static-ip | 6 +++--- .../opt/tinypilot-privileged/scripts/set-static-ip | 14 +++++--------- .../tinypilot-privileged/scripts/unset-static-ip | 6 +++--- 3 files changed, 11 insertions(+), 15 deletions(-) diff --git a/debian-pkg/opt/tinypilot-privileged/scripts/apply-static-ip b/debian-pkg/opt/tinypilot-privileged/scripts/apply-static-ip index 3990d416b..598af7dfe 100755 --- a/debian-pkg/opt/tinypilot-privileged/scripts/apply-static-ip +++ b/debian-pkg/opt/tinypilot-privileged/scripts/apply-static-ip @@ -11,14 +11,14 @@ set -x # Exit on unset variable. set -u -# Check which OS is running. -OS_CODENAME="$(grep '^VERSION_CODENAME' /etc/os-release | cut --delimiter '=' --fields 2)" +# 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 -if [[ "${OS_CODENAME}" == 'bullseye' ]]; then +if [[ "${OS_VERSION}" == 11 ]]; then ip address flush dev eth0 systemctl restart \ dhcpcd.service diff --git a/debian-pkg/opt/tinypilot-privileged/scripts/set-static-ip b/debian-pkg/opt/tinypilot-privileged/scripts/set-static-ip index b9c68e799..b33631cfa 100755 --- a/debian-pkg/opt/tinypilot-privileged/scripts/set-static-ip +++ b/debian-pkg/opt/tinypilot-privileged/scripts/set-static-ip @@ -131,20 +131,16 @@ readonly DNS # Default interface. if [[ -z "${INTERFACE}" ]] ; then - if [[ "${OS_CODENAME}" == "bullseye" ]]; then - readonly INTERFACE="eth0" - else - readonly INTERFACE="Wired connection 1" - fi + readonly INTERFACE="eth0" fi # Exit on unset variable. set -u -# Check which OS is running. -OS_CODENAME="$(grep '^VERSION_CODENAME' /etc/os-release | cut --delimiter '=' --fields 2)" +# Determine which version of the OS is running. +OS_VERSION="$(lsb_release --release --short)" -if [[ "${OS_CODENAME}" == 'bullseye' ]]; then +if [[ "${OS_VERSION}" == 11 ]]; then # Remove any existing automated configuration. "${SCRIPT_DIR}/strip-marker-sections" "${CONFIG_FILE}" @@ -165,7 +161,7 @@ if [[ "${OS_CODENAME}" == 'bullseye' ]]; then echo "${MARKER_END}" } | sudo tee --append "${CONFIG_FILE}" > /dev/null else - nmcli connection modify "${INTERFACE}" \ + nmcli connection modify 'Wired connection 1' \ ipv4.method manual \ ipv4.addresses "${IP_ADDRESS}" \ ipv4.gateway "${ROUTERS}" \ diff --git a/debian-pkg/opt/tinypilot-privileged/scripts/unset-static-ip b/debian-pkg/opt/tinypilot-privileged/scripts/unset-static-ip index 2b248906e..b57ea2f49 100755 --- a/debian-pkg/opt/tinypilot-privileged/scripts/unset-static-ip +++ b/debian-pkg/opt/tinypilot-privileged/scripts/unset-static-ip @@ -58,10 +58,10 @@ fi # Exit on unset variable set -u -# Check which OS is running. -OS_CODENAME="$(grep '^VERSION_CODENAME' /etc/os-release | cut --delimiter '=' --fields 2)" +# Determine which version of the OS is running. +OS_VERSION="$(lsb_release --release --short)" -if [[ "${OS_CODENAME}" == 'bullseye' ]]; then +if [[ "${OS_VERSION}" == 11 ]]; then # Remove any existing marker sections from the config file. "${SCRIPT_DIR}/strip-marker-sections" /etc/dhcpcd.conf else From 4aa0e7c61372874579e07bfa740509b5d1dd5f35 Mon Sep 17 00:00:00 2001 From: David Brown Date: Tue, 3 Sep 2024 15:11:51 +0100 Subject: [PATCH 5/5] fix numeric comparisons, readonly variable --- debian-pkg/opt/tinypilot-privileged/scripts/apply-static-ip | 3 ++- debian-pkg/opt/tinypilot-privileged/scripts/set-static-ip | 3 ++- debian-pkg/opt/tinypilot-privileged/scripts/unset-static-ip | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/debian-pkg/opt/tinypilot-privileged/scripts/apply-static-ip b/debian-pkg/opt/tinypilot-privileged/scripts/apply-static-ip index 598af7dfe..fdef9c85a 100755 --- a/debian-pkg/opt/tinypilot-privileged/scripts/apply-static-ip +++ b/debian-pkg/opt/tinypilot-privileged/scripts/apply-static-ip @@ -13,12 +13,13 @@ 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 -if [[ "${OS_VERSION}" == 11 ]]; then +if (( "${OS_VERSION}" == 11 )); then ip address flush dev eth0 systemctl restart \ dhcpcd.service diff --git a/debian-pkg/opt/tinypilot-privileged/scripts/set-static-ip b/debian-pkg/opt/tinypilot-privileged/scripts/set-static-ip index b33631cfa..3ca2b8eec 100755 --- a/debian-pkg/opt/tinypilot-privileged/scripts/set-static-ip +++ b/debian-pkg/opt/tinypilot-privileged/scripts/set-static-ip @@ -139,8 +139,9 @@ set -u # Determine which version of the OS is running. OS_VERSION="$(lsb_release --release --short)" +readonly OS_VERSION -if [[ "${OS_VERSION}" == 11 ]]; then +if (( "${OS_VERSION}" == 11 )); then # Remove any existing automated configuration. "${SCRIPT_DIR}/strip-marker-sections" "${CONFIG_FILE}" diff --git a/debian-pkg/opt/tinypilot-privileged/scripts/unset-static-ip b/debian-pkg/opt/tinypilot-privileged/scripts/unset-static-ip index b57ea2f49..66f926608 100755 --- a/debian-pkg/opt/tinypilot-privileged/scripts/unset-static-ip +++ b/debian-pkg/opt/tinypilot-privileged/scripts/unset-static-ip @@ -60,8 +60,9 @@ set -u # Determine which version of the OS is running. OS_VERSION="$(lsb_release --release --short)" +readonly OS_VERSION -if [[ "${OS_VERSION}" == 11 ]]; then +if (( "${OS_VERSION}" == 11 )); then # Remove any existing marker sections from the config file. "${SCRIPT_DIR}/strip-marker-sections" /etc/dhcpcd.conf else