]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blobdiff - src/initscripts/helper/aws-setup
cloud-init: Disable using ISP nameservers
[people/pmueller/ipfire-2.x.git] / src / initscripts / helper / aws-setup
index 777c8b9265f4afeda19c857356967dfa7ad1e97c..8843198221df07be6f74ab9343cadcc621007a04 100644 (file)
@@ -3,6 +3,9 @@
 . /etc/sysconfig/rc
 . ${rc_functions}
 
+# Set PATH to find our own executables
+export PATH=/usr/local/sbin:/usr/local/bin:${PATH}
+
 get() {
        local file="${1}"
 
@@ -47,22 +50,6 @@ prefix2netmask() {
        to_address "$(( netmask ^ 0xffffffff ))"
 }
 
-find_interface() {
-       local mac="${1}"
-
-       local path
-       for path in /sys/class/net/*; do
-               local address="$(<${path}/address)"
-
-               if [ "${mac}" = "${address}" ]; then
-                       basename "${path}"
-                       return 0
-               fi
-       done
-
-       return 1
-}
-
 import_aws_configuration() {
        local instance_id="$(get meta-data/instance-id)"
 
@@ -120,16 +107,14 @@ import_aws_configuration() {
                        chmod 700 /tmp/aws-user-data.script
 
                        # Run the user-data script
-                       /tmp/aws-user-data.script
+                       local now="$(date -u +"%s")"
+                       /tmp/aws-user-data.script &>/var/log/user-data.log.${now}
 
                        # Delete the script right away
                        rm /tmp/aws-user-data.script
                fi
        fi
 
-       # Import any DNS server settings
-       eval $(/usr/local/bin/readhash <(grep -E "^DNS([0-9])=" /var/ipfire/ethernet/settings 2>/dev/null))
-
        # Import network configuration
        # After this, no network connectivity will be available from this script due to the
        # renaming of the network interfaces for which they have to be shut down
@@ -173,10 +158,6 @@ import_aws_configuration() {
                                # The gateway is always the first IP address in the subnet
                                local gateway="$(to_address $(( netaddress_num + 1 )))"
 
-                               # The AWS internal DNS service is available on the second IP address of the VPC
-                               local dns1="$(to_address $(( vpc_netaddress_num + 2 )))"
-                               local dns2=
-
                                (
                                        echo "RED_TYPE=STATIC"
                                        echo "RED_DEV=${interface_name}"
@@ -187,8 +168,6 @@ import_aws_configuration() {
                                        echo "RED_NETADDRESS=${netaddress}"
                                        echo "RED_BROADCAST=${broadcast}"
                                        echo "DEFAULT_GATEWAY=${gateway}"
-                                       echo "DNS1=${DNS1:-${dns1}}"
-                                       echo "DNS2=${DNS2:-${dns2}}"
                                ) >> /var/ipfire/ethernet/settings
 
                                # Import aliases for RED
@@ -228,14 +207,6 @@ import_aws_configuration() {
                                ) >> /var/ipfire/ethernet/settings
                                ;;
                esac
-
-               # Rename interface
-               local interface="$(find_interface "${mac}")"
-
-               if [ -n "${interface}" ] && [ -n "${interface_name}" ] && [ "${interface}" != "${interface_name}" ]; then
-                       ip link set "${interface}" down
-                       ip link set "${interface}" name "${interface_name}"
-               fi
        done
 
        # Save CONFIG_TYPE
@@ -243,6 +214,9 @@ import_aws_configuration() {
 
        # Actions performed only on the very first start
        if [ ! -e "/var/ipfire/main/firstsetup_ok" ]; then
+               # Disable using ISP nameservers
+               sed -e "s/^USE_ISP_NAMESERVERS=.*/USE_ISP_NAMESERVERS=off/" -i /var/ipfire/dns/settings
+
                # Enable SSH
                sed -e "s/ENABLE_SSH=.*/ENABLE_SSH=on/g" -i /var/ipfire/remote/settings
 
@@ -307,6 +281,9 @@ case "${reason}" in
 
                # Remove all IP addresses
                ip addr flush dev "${interface}"
+
+               # Shut down the interface
+               ip link set "${interface}" down
                ;;
 
        *)