#!/bin/sh -e # # 2012-2018 Steven Armstrong (steven-cdist at armstrong.cc) # # This file is part of cdist. # # cdist is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # cdist is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with cdist. If not, see . # __package ifupdown # Use cumulus ifupdown2 instead of ifupown and ifenslave # ifupdown2 is currently not compatible with network-wait-online. #__package ifupdown \ # --name ifupdown2 type_files="$__type/files/debian" mkdir "$__object/files" interface_filename="${__object_id}.conf" ( cat << DONE # Created by cdist ${__type##*/} # Do not change. Changes will be overwritten. # DONE if [ -f "$__object/parameter/comment" ]; then awk '{ print "# "$0 }' < "$__object/parameter/comment" fi if [ -f "$__object/parameter/onboot" ]; then # shellcheck disable=SC2154 printf "auto %s\n" "$name" elif [ -f "$__object/parameter/hotplug" ]; then # shellcheck disable=SC2154 printf "allow-hotplug %s\n" "$name" fi ignored_parameters="linkdelay" manually_handled_parameters="name comment extra-config state method onboot hotplug nodns noroute no-network-wait-online symmetric-routing bond-slaves" # shellcheck disable=SC2154 case "$method" in dhcp) printf "iface %s inet %s\n" "$name" "$method" ignored_parameters="$ignored_parameters address broadcast gateway netmask" ;; static|manual) printf "iface %s inet %s\n" "$name" "$method" ;; *) echo "Unsupported value for parameter --method. Got '$method'. See man page for supported values." >&2 exit 1 ;; esac for param in "$__object"/parameter/*; do if echo "$ignored_parameters" | grep -w -q "$param"; then continue fi if echo "$manually_handled_parameters" | grep -w -q "$param"; then continue fi if [ -f "$type_files/name-map" ]; then key="$(awk -v param="$param" '{ if ($1 == param) {print $2;} else { print param;} }' "$type_files/name-map")" else key="$param" fi printf " %s %s\n" "$key" "$(cat "$__object/parameter/$param")" done if [ -f "$__object/parameter/bond-mode" ] || [ -f "$__object/parameter/bond-primary" ]; then # Note: ifenslave is not needed when using ifupdown2 # install package required for bonding __package ifenslave if [ -f "$__object/parameter/bond-slaves" ]; then printf ' bond-slaves %s\n' "$(cat "$__object/parameter/bond-slaves")" else # need this or the slave tries to bring the master up, but the master hangs waiting for a slave printf ' bond-slaves none\n' fi fi if [ -f "$__object/parameter/no-network-wait-online" ]; then # Do not consider this interface in network-wait-online.service printf ' no-network-wait-online yes\n' fi if [ -f "$__object/parameter/symmetric-routing" ]; then # Deploy scripts that implement the feature ... __file /sbin/symmetric-routing \ --owner root --group root --mode 0755 \ --source "$__type/files/symmetric-routing" require="__package/ifupdown __file/sbin/symmetric-routing" \ __file /etc/network/if-up.d/symmetric-routing \ --owner root --group root --mode 0755 \ --source "$__type/files/debian/ifupdown-symmetric-routing" require="__package/ifupdown __file/etc/network/if-up.d/symmetric-routing" \ __link /etc/network/if-down.d/symmetric-routing \ --type symbolic \ --source ../if-up.d/symmetric-routing # ... then enable it in interface stanza file. printf ' symmetric-routing yes\n' fi # shellcheck disable=SC2154 if [ -n "$vlan" ] && [ -n "$device" ]; then # Explicit parent interface for vlans printf ' vlan-raw-device %s\n' "$device" fi if [ -f "$__object/parameter/extra-config" ]; then extra_config="$(cat "$__object/parameter/extra-config")" if [ "$extra_config" = "-" ]; then extra_config="$__object/stdin" fi awk '{print " " $0}' "$extra_config" fi ) >> "$__object/files/$interface_filename" __directory /etc/network \ --state present \ --owner root \ --group root \ --mode 755 require="__directory/etc/network" \ __directory /etc/network/interfaces.d \ --state present \ --owner root \ --group root \ --mode 755 require="__directory/etc/network" \ __file /etc/network/interfaces \ --source "$type_files/interfaces" \ --owner root \ --group root \ --mode 644 # shellcheck disable=SC2154 require="__file/etc/network/interfaces __directory/etc/network/interfaces.d" \ __file "/etc/network/interfaces.d/$interface_filename" \ --owner root \ --group root \ --mode 644 \ --source "$__object/files/$interface_filename" \ --state "$state" if [ "$method" = "dhcp" ] && [ -f "$__object/parameter/noroute" ]; then ( cat << DONE # Created by cdist ${__type##*/} # Do not change. Changes will be overwritten. # if [ "\$interface" = "$name" ]; then case "\$reason" in BOUND|RENEW|REBIND|REBOOT) # prevent default gateway to be set by this interface unset new_routers ;; esac fi DONE ) | \ __file "/etc/dhcp/dhclient-enter-hooks.d/cdist-__network_interface-${name}-noroute" \ --owner root \ --group root \ --mode 644 \ --source - \ --state "$state" fi # end noroute if [ "$method" = "dhcp" ] && [ -f "$__object/parameter/nodns" ]; then ( cat << DONE # Created by cdist ${__type##*/} # Do not change. Changes will be overwritten. # if [ "\$interface" = "$name" ]; then # Prevent /etc/resolv.conf from being changed by this interface # by overriding the default 'make_resolv_conf' function. make_resolv_conf(){ : } fi DONE ) | \ __file "/etc/dhcp/dhclient-enter-hooks.d/cdist-__network_interface-${name}-nodns" \ --owner root \ --group root \ --mode 644 \ --source - \ --state "$state" fi # end nodns os=$(cat "$__global/explorer/os") if [ "$os" = "ubuntu" ]; then # workaround the bloody upstart race conditions # by deploying a script that delays the emission of the net-device-up # signal until the interface is really up and configured. #script_name="00000-wait-for-ip" #__file "/etc/network/if-up.d/$script_name" \ # --owner root --group root --mode 755 \ # --source "$type_files/$script_name" # Deal with systemd network-online.target race conditions require="__package/ifupdown" \ __file /etc/network/if-pre-up.d/network-online \ --owner root --group root --mode 0755 \ --source "$__type/files/debian/network-online" require="__file/etc/network/if-pre-up.d/network-online" \ __link /etc/network/if-up.d/network-online \ --type symbolic \ --source ../if-pre-up.d/network-online fi