From 2dde5ec482bd8dad709fd83bd1ee5652a194d461 Mon Sep 17 00:00:00 2001 From: Andrew Beltrano Date: Fri, 10 May 2024 01:31:01 +0000 Subject: [PATCH 1/3] Add .template suffix to example netplan file. --- config/linux/network/netplan/CMakeLists.txt | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/config/linux/network/netplan/CMakeLists.txt b/config/linux/network/netplan/CMakeLists.txt index fc5845f8..50fa4358 100644 --- a/config/linux/network/netplan/CMakeLists.txt +++ b/config/linux/network/netplan/CMakeLists.txt @@ -1,8 +1,9 @@ install( FILES - ${CMAKE_CURRENT_LIST_DIR}/10-network-netremote-all-template.yaml + ${CMAKE_CURRENT_LIST_DIR}/10-network-netremote-all.yaml DESTINATION ${CMAKE_INSTALL_SYSCONFDIR}/netplan + RENAME 10-network-netremote-all.yaml.template PERMISSIONS OWNER_READ OWNER_WRITE COMPONENT config-netplan CONFIGURATIONS Debug @@ -10,8 +11,9 @@ install( install( FILES - ${CMAKE_CURRENT_LIST_DIR}/10-network-netremote-all-template.yaml + ${CMAKE_CURRENT_LIST_DIR}/10-network-netremote-all.yaml DESTINATION /${CMAKE_INSTALL_SYSCONFDIR}/netplan + RENAME 10-network-netremote-all.yaml.template PERMISSIONS OWNER_READ OWNER_WRITE COMPONENT config-netplan CONFIGURATIONS Release RelWithDebInfo MinSizeRel From 397dd52e08a71848cc0486bf850e31f51e0b87e5 Mon Sep 17 00:00:00 2001 From: Andrew Beltrano Date: Fri, 10 May 2024 01:36:44 +0000 Subject: [PATCH 2/3] Fix typo. --- packaging/deb/config-netplan/scripts/confnetplan | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packaging/deb/config-netplan/scripts/confnetplan b/packaging/deb/config-netplan/scripts/confnetplan index 229dc7a5..2a1fd1bf 100644 --- a/packaging/deb/config-netplan/scripts/confnetplan +++ b/packaging/deb/config-netplan/scripts/confnetplan @@ -9,8 +9,8 @@ readonly NETPLAN_ORIGIN_FILE_PATH=/etc/netplan/${NETPLAN_ORIGIN_FILE_NAME}.yaml readonly NETPLAN_ORIGIN_FILE_PERMS=0600 readonly NETPLAN_TRY_TIMEOUT_SECONDS_DEFAULT=10 readonly NETPLAN_BRIDGE_INTERFACE_PREFIX=brgateway -readonly NETPLAT_CONFIGURATION_FILE_REVIEW_SECONDS=5 -readonly NETPLAT_CONFIGURATION_FILE_REVIEW_SECONDS_DEBUG=1 +readonly NETPLAN_CONFIGURATION_FILE_REVIEW_SECONDS=5 +readonly NETPLAN_CONFIGURATION_FILE_REVIEW_SECONDS_DEBUG=1 # Netplan key-value constants. readonly NETPLAN_KEY_NETWORK=network @@ -505,8 +505,8 @@ function debconf_prompt_netplan_configuration() { # shellcheck disable=SC2015 [[ -z "${DEBCONF_DEBUG-}" ]] \ - && readonly configuration_file_review_seconds="${NETPLAT_CONFIGURATION_FILE_REVIEW_SECONDS}" \ - || readonly configuration_file_review_seconds="${NETPLAT_CONFIGURATION_FILE_REVIEW_SECONDS_DEBUG}" + && readonly configuration_file_review_seconds="${NETPLAN_CONFIGURATION_FILE_REVIEW_SECONDS}" \ + || readonly configuration_file_review_seconds="${NETPLAN_CONFIGURATION_FILE_REVIEW_SECONDS_DEBUG}" # Show the user the generated netplan configuration. db_subst "${QUESTION_NETWORK_CONFIGURE_SHOW_GENERATED_CONFIGURATION}" "${QUESTION_NETWORK_CONFIGURE_SHOW_GENERATED_CONFIGURATION_VAR}" "${NETPLAN_ORIGIN_FILE_PATH}" From 89621498eb6f6e2d0efaa4a56aff847e17267cbf Mon Sep 17 00:00:00 2001 From: Andrew Beltrano Date: Fri, 10 May 2024 05:47:21 +0000 Subject: [PATCH 3/3] Backup and move pre-existing netplan config files. --- ...ate.yaml => 10-network-netremote-all.yaml} | 0 .../deb/config-netplan/scripts/confnetplan | 23 +++++++++++++++++-- 2 files changed, 21 insertions(+), 2 deletions(-) rename config/linux/network/netplan/{10-network-netremote-all-template.yaml => 10-network-netremote-all.yaml} (100%) diff --git a/config/linux/network/netplan/10-network-netremote-all-template.yaml b/config/linux/network/netplan/10-network-netremote-all.yaml similarity index 100% rename from config/linux/network/netplan/10-network-netremote-all-template.yaml rename to config/linux/network/netplan/10-network-netremote-all.yaml diff --git a/packaging/deb/config-netplan/scripts/confnetplan b/packaging/deb/config-netplan/scripts/confnetplan index 2a1fd1bf..cb4005d0 100644 --- a/packaging/deb/config-netplan/scripts/confnetplan +++ b/packaging/deb/config-netplan/scripts/confnetplan @@ -3,6 +3,11 @@ # Include debconf shell utility library . /usr/share/debconf/confmodule +# Get timestamp including current date and time. +NOW= +NOW=$(date +"%Y%m%d-%H%M%S") +readonly NOW + # Define and initialize constants. readonly NETPLAN_ORIGIN_FILE_NAME=10-network-netremote-all readonly NETPLAN_ORIGIN_FILE_PATH=/etc/netplan/${NETPLAN_ORIGIN_FILE_NAME}.yaml @@ -11,6 +16,8 @@ readonly NETPLAN_TRY_TIMEOUT_SECONDS_DEFAULT=10 readonly NETPLAN_BRIDGE_INTERFACE_PREFIX=brgateway readonly NETPLAN_CONFIGURATION_FILE_REVIEW_SECONDS=5 readonly NETPLAN_CONFIGURATION_FILE_REVIEW_SECONDS_DEBUG=1 +readonly NETPLAN_CONFIGURATION_FILE_BACKUP_SUFFIX="${NOW}.bak" +readonly NETPLAN_CONFIGURATION_FILE_DIRECTORIES=(/{etc,lib,run}/netplan) # Netplan key-value constants. readonly NETPLAN_KEY_NETWORK=network @@ -426,14 +433,26 @@ function netplan_file_set_toplevel_fields() { netplan_configuration_set_key_value "${key}" "${value}" } -# Create the netplan configuration file if it does not exist, and set top-level fields. -# +# Create the netplan configuration file if it does not exist, set top-level fields, and create backups of any +# pre-existing netplan configuration files. +# # The netplan configuration file referred to by NETPLAN_ORIGIN_FILE_NAME is used. # # Arguments: # None # function netplan_configuration_create() { + # Rename any existing netplan configuration files as they will conflict with the generated configuration. + for netplan_configuration_directory in "${NETPLAN_CONFIGURATION_FILE_DIRECTORIES[@]}"; do + # If the directory does not exist, skip it as find will return an error if passed a non-existent directory. + if [[ ! -d ${netplan_configuration_directory} ]]; then + continue + fi + + # Rename the .yaml and .yml files in this directory, appending a suffix with the current time and .bak extension. + find "${netplan_configuration_directory}" -type f -regex ".*\.\(y[a]*ml\)" -print0 2> /dev/null | xargs -0 -I {} mv {} "{}.${NETPLAN_CONFIGURATION_FILE_BACKUP_SUFFIX}" + done + if [[ ! -f ${NETPLAN_ORIGIN_FILE_PATH} ]]; then install -m ${NETPLAN_ORIGIN_FILE_PERMS} /dev/null ${NETPLAN_ORIGIN_FILE_PATH} netplan_file_set_toplevel_fields