You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

81 lines
2.4 KiB

  1. #! /bin/sh
  2. set -e
  3. . /usr/share/debconf/confmodule
  4. # File paths for various configuration files
  5. FILE_PATH_NM_CONFIG=etc/NetworkManager/system-connections
  6. FILE_INTERFACES=/etc/network/interfaces
  7. FILE_NETCFG_CONNECTION_TYPE=/tmp/connection_type
  8. # The connection type file is written by the nm-conf code.
  9. # The base-installer snippet will already take care of copying
  10. # the generated interfaces file, so if we are not dealing
  11. # with nm-conf anyway: just exit.
  12. if [ ! -e $FILE_NETCFG_CONNECTION_TYPE ]; then
  13. logger -t netcfg "DEBUG: copy-config: $FILE_NETCFG_CONNECTION_TYPE not found: netcfg did not complete or was compiled without network-manager support; exiting."
  14. exit 0
  15. fi
  16. # Flag to determine whether Network Manager is installed.
  17. if in-target sh -c "dpkg-query -s network-manager 2>/dev/null | grep -q '^Status: install ok installed'"; then
  18. NM_IS_INSTALLED=true
  19. else
  20. NM_IS_INSTALLED=false
  21. fi
  22. # The type of the connection used during installation
  23. NETCFG_CONNECTION_TYPE=$(cat $FILE_NETCFG_CONNECTION_TYPE | \
  24. grep "connection type" | cut -d ':' -f2 | sed 's/ //g')
  25. NETCFG_CONNECTION_SECURITY=$(cat $FILE_NETCFG_CONNECTION_TYPE | \
  26. grep "security" | cut -d ':' -f2 | sed 's/ //g')
  27. # netcfg/target_network_config question values
  28. CONFIG_NM="nm_config"
  29. CONFIG_INTERFACES="ifupdown"
  30. CONFIG_LOOPBACK="loopback"
  31. db_get netcfg/target_network_config
  32. # Check for preseeding. If the value of the question is empty then set
  33. # default options. Document automatic selection changes in the template.
  34. if [ -z "$RET" ]; then
  35. if $NM_IS_INSTALLED; then
  36. db_set netcfg/target_network_config $CONFIG_NM
  37. else
  38. if [ "$NETCFG_CONNECTION_TYPE" = "wired" ]; then
  39. db_set netcfg/target_network_config $CONFIG_INTERFACES
  40. else # wireless
  41. db_set netcfg/target_network_config $CONFIG_LOOPBACK
  42. fi
  43. fi
  44. fi
  45. db_get netcfg/target_network_config
  46. case $RET in
  47. $CONFIG_NM)
  48. # Copy NM config file. First make sure the directory exists
  49. mkdir -p /target/$FILE_PATH_NM_CONFIG
  50. cp /$FILE_PATH_NM_CONFIG/* /target/$FILE_PATH_NM_CONFIG/
  51. # Rewrite /etc/network/interfaces to contain only loopback
  52. netcfg write_loopback
  53. ;;
  54. $CONFIG_LOOPBACK)
  55. # Rewrite /etc/network/interfaces to contain only loopback
  56. netcfg write_loopback
  57. ;;
  58. esac
  59. case $RET in
  60. $CONFIG_NM|$CONFIG_LOOPBACK)
  61. # Copy /etc/network/interfaces to target.
  62. mkdir -p /target$(dirname $FILE_INTERFACES)
  63. cp $FILE_INTERFACES /target$FILE_INTERFACES
  64. ;;
  65. esac
  66. exit 0