#! /bin/sh set -e . /usr/share/debconf/confmodule # File paths for various configuration files NETPLAN_INSTALLER_FILE=00-installer-config.yaml FILE_PATH_NETPLAN_CONFIG=etc/netplan FILE_PATH_NM_CONFIG=etc/NetworkManager/system-connections FILE_INTERFACES=/etc/network/interfaces FILE_NETCFG_CONNECTION_TYPE=/tmp/connection_type # The connection type file is written by the nm-conf code. # The base-installer snippet will already take care of copying # the generated interfaces file, so if we are not dealing # with nm-conf anyway: just exit. if [ ! -e $FILE_NETCFG_CONNECTION_TYPE ]; then logger -t netcfg "DEBUG: copy-config: $FILE_NETCFG_CONNECTION_TYPE not found: netcfg did not complete or was compiled without network-manager support; exiting." exit 0 fi # Flag to determine whether Netplan is installed. if in-target sh -c "dpkg-query -s netplan-generator 2>/dev/null | grep -q '^Status: install ok installed'"; then NETPLAN_IS_INSTALLED=true else NETPLAN_IS_INSTALLED=false fi # Flag to determine whether Network Manager is installed. if in-target sh -c "dpkg-query -s network-manager 2>/dev/null | grep -q '^Status: install ok installed'"; then NM_IS_INSTALLED=true else NM_IS_INSTALLED=false fi # The type of the connection used during installation NETCFG_CONNECTION_TYPE=$(cat $FILE_NETCFG_CONNECTION_TYPE | \ grep "connection type" | cut -d ':' -f2 | sed 's/ //g') NETCFG_CONNECTION_SECURITY=$(cat $FILE_NETCFG_CONNECTION_TYPE | \ grep "security" | cut -d ':' -f2 | sed 's/ //g') # netcfg/target_network_config question values CONFIG_NETPLAN="netplan" CONFIG_NM="nm_config" CONFIG_INTERFACES="ifupdown" CONFIG_LOOPBACK="loopback" db_get netcfg/target_network_config # Check for preseeding. If the value of the question is empty then set # default options. Document automatic selection changes in the template. if [ -z "$RET" ]; then # Fall through to classic NM/ifupdown config if no Netplan config was # written (e.g. for WEP "secured" WiFi) if $NETPLAN_IS_INSTALLED && [ -f "/$FILE_PATH_NETPLAN_CONFIG/$NETPLAN_INSTALLER_FILE" ]; then db_set netcfg/target_network_config $CONFIG_NETPLAN elif $NM_IS_INSTALLED; then db_set netcfg/target_network_config $CONFIG_NM else db_set netcfg/target_network_config $CONFIG_INTERFACES fi fi db_get netcfg/target_network_config case $RET in $CONFIG_NETPLAN) # Copy Netplan configuration. First make sure the directory exists mkdir -p /target/$FILE_PATH_NETPLAN_CONFIG cp /$FILE_PATH_NETPLAN_CONFIG/* /target/$FILE_PATH_NETPLAN_CONFIG/ # Also write nm-all.yaml if NM_IS_INSTALLED. # TODO: We might rather do that inside the network-manager package, see: # https://bugs.launchpad.net/ubuntu/+source/ubuntu-settings/+bug/2020110 if $NM_IS_INSTALLED; then cat > /target/$FILE_PATH_NETPLAN_CONFIG/01-network-manager-all.yaml < /target/$FILE_INTERFACES <