#!/bin/bash # postinst script for #PACKAGE# # # see: dh_installdeb(1) set -e # summary of how this script can be called: # * `configure' # * `abort-upgrade' # * `abort-remove' `in-favour' # # * `abort-remove' # * `abort-deconfigure' `in-favour' # `removing' # # for details, see https://www.debian.org/doc/debian-policy/ or # the debian-policy package case "$1" in configure) [ -z $NODE_ID ] && export NODE_ID=$(ip -4 -br addr | grep 10.0. | awk '{ print $3 }' | awk 'BEGIN{FS="[./]"} { print $4 }') export MGMT_ID=$(ip -4 -br addr | grep 10.0. | awk '{ print $3 }' | awk 'BEGIN{FS="[./]"} { print $3 }') export MGMT_MAC=$(ip -br link show dev $(ip -4 -br addr | grep 10.0. | awk '{ print $1 }') | awk '{ print $3 }') [ "$MGMT_ID" -ge 0 -a "$MGMT_ID" -lt 16 ] && export DOMAINNAME=.usw1.wit.com [ "$MGMT_ID" -ge 16 -a "$MGMT_ID" -lt 32 ] && export DOMAINNAME=.usw2.wit.com [ ${HOSTNAME:0:1} = h ] && export HOSTTYPE=hypervisor [ ${HOSTNAME:0:1} = d ] && export HOSTTYPE=datanode [ $HOSTTYPE = hypervisor -a $DOMAINNAME = .usw1.wit.com ] && export TIER_ID=2 [ $HOSTTYPE = datanode -a $DOMAINNAME = .usw1.wit.com ] && export TIER_ID=4 [ $HOSTTYPE = hypervisor -a $DOMAINNAME = .usw2.wit.com ] && export TIER_ID=18 [ $HOSTTYPE = datanode -a $DOMAINNAME = .usw2.wit.com ] && export TIER_ID=20 if [ -z "$TIER_ID" ]; then echo "Unable to autodetect TIER_ID, looks like we deal with a special node, please set in environment" exit 2 fi if [ -z "$DOMAINNAME" ]; then echo "Unable to autodetect DOMAINNAME, looks like we deal with a special case, please set in environment and/or update the code" exit 2 fi export NODE_ASN="$(printf "%03d" $TIER_ID)$(printf "%03d" $NODE_ID)" echo "auto lo:0" >/etc/network/interfaces.d/lo echo "iface lo:0 inet static\n address 10.1.$TIER_ID.$NODE_ID/32" >> /etc/network/interfaces.d/lo echo "iface lo:0 inet6 static\n address 2604:bbc0::$TIER_ID:$NODE_ID/128" >> /etc/network/interfaces.d/lo sed -i -e "s/VTEPINDEX/$NODE_ID/" -e "s/TIERID/$TIER_ID/" -e "s/NODEASN/$NODE_ASN/" /etc/frr/frr.conf.wit chown frr.frr /etc/frr/frr.conf.wit /etc/frr/daemons.wit sed -i -e "s/HOSTNAME\.DOMAINNAME/${HOSTNAME}${DOMAINNAME}/" /etc/ipsec.conf.wit echo ": RSA ${HOSTNAME}${DOMAINNAME}.key" >/etc/ipsec.secrets chmod 600 /etc/ipsec.secrets echo 'SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="'$MGMT_MAC'", ATTR{type}=="1", NAME="mgmt1"' >/etc/udev/rules.d/70-persistent-net.rules i=0 for nic in $(ip -br link | awk '{ print $1 }'); do if ethtool $nic | grep -q 10000; then i=$((i+1)) echo 'SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="'$(cat /sys/class/net/$nic/address)'", ATTR{type}=="1", NAME="feth'$i'"' >>/etc/udev/rules.d/70-persistent-net.rules fi done sed -i "/$MGMT_MAC.*feth./d" /etc/udev/rules.d/70-persistent-net.rules systemctl stop systemd-networkd.socket systemctl stop systemd-networkd.service systemctl stop systemd-networkd-wait-online systemctl disable systemd-networkd.service systemctl disable systemd-networkd.socket systemctl disable systemd-networkd-wait-online systemctl enable firewall systemctl restart systemd-timesyncd systemctl restart strongswan update-grub sysctl -p /etc/sysctl.d/10-frr.conf ;; abort-upgrade|abort-remove|abort-deconfigure) ;; *) echo "postinst called with unknown argument \`$1'" >&2 exit 1 ;; esac # dh_installdeb will replace this with shell code automatically # generated by other debhelper scripts. #DEBHELPER# exit 0