wit-network-config/debian/wit-hypervisor-config.postinst

143 lines
5.0 KiB
Plaintext
Raw Normal View History

2018-07-27 15:51:10 -05:00
#!/bin/bash
2018-07-26 03:57:41 -05:00
# postinst script for #PACKAGE#
#
# see: dh_installdeb(1)
set -e
# summary of how this script can be called:
# * <postinst> `configure' <most-recently-configured-version>
# * <old-postinst> `abort-upgrade' <new version>
# * <conflictor's-postinst> `abort-remove' `in-favour' <package>
# <new-version>
# * <postinst> `abort-remove'
# * <deconfigured's-postinst> `abort-deconfigure' `in-favour'
# <failed-install-package> <version> `removing'
# <conflicting-package> <version>
# for details, see https://www.debian.org/doc/debian-policy/ or
# the debian-policy package
case "$1" in
configure)
2018-07-28 15:52:38 -05:00
### START gather all the info from the box and generate the variabels
2018-07-27 15:51:10 -05:00
[ -z $NODE_ID ] && export NODE_ID=$(ip -4 -br addr | grep 10.0. | awk '{ print $3 }' | awk 'BEGIN{FS="[./]"} { print $4 }')
2018-07-27 15:34:21 -05:00
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
[ $HOSTTYPE != hypervisor -a $HOSTTYPE != datanode ] && sed -i -e '/TIER_ID/d' -e "$ s/$/\nTIER_ID=$TIER_ID/" /etc/environment
2018-07-27 15:34:21 -05:00
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
2018-07-28 13:47:08 -05:00
export NODE_ASN="4200$(printf "%03d" $TIER_ID)$(printf "%03d" $NODE_ID)"
export LOOPBACKv4="10.1.$TIER_ID.$NODE_ID"
export LOOPBACKv6="2604:bbc0::$TIER_ID:$NODE_ID"
2018-07-27 15:34:21 -05:00
2018-07-28 15:52:38 -05:00
## END variables
## START writing config files
2018-07-27 15:34:21 -05:00
sed -i -e '/#*PasswordAuthentication /d' /etc/ssh/sshd_config
echo "PasswordAuthentication no" >>/etc/ssh/sshd_config
echo "iface lo inet static" > /etc/network/interfaces.d/lo
2018-07-28 13:47:08 -05:00
echo " address ${LOOPBACKv4}/32" >> /etc/network/interfaces.d/lo
echo "" >> /etc/network/interfaces.d/lo
echo "iface lo inet6 static" >> /etc/network/interfaces.d/lo
2018-07-28 13:47:08 -05:00
echo " address ${LOOPBACKv6}/128" >> /etc/network/interfaces.d/lo
2018-07-27 05:39:47 -05:00
2018-07-27 15:34:21 -05:00
2018-07-28 13:47:08 -05:00
sed -i -e "s/FRRROUTERID/${LOOPBACKv4}/" -e "s/NODEASN/${NODE_ASN}/" /etc/frr/frr.conf.wit
2018-07-27 15:34:21 -05:00
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
2018-07-27 05:39:47 -05:00
2018-07-28 13:47:08 -05:00
2018-07-27 05:39:47 -05:00
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
2018-07-28 15:52:38 -05:00
sed -i -e "/.*debcore1/d" -e "/.*${HOSTNAME}/d" /etc/hosts
echo -e "${LOOPBACKv4}\t${HOSTNAME}${DOMAINNAME}\t${HOSTNAME}" >>/etc/hosts
sed -i -e '/GRUB_CMDLINE_LINUX_DEFAULT=/d' -e '/GRUB_CMDLINE_LINUX=/d' -e '/GRUB_SERIAL_COMMAND=/d' -e '/GRUB_TERMINAL=/d' /etc/default/grub
echo -e 'GRUB_CMDLINE_LINUX_DEFAULT=""\nGRUB_CMDLINE_LINUX="console=tty0 console=ttyS1,115200n8"\nGRUB_TERMINAL=serial\nGRUB_SERIAL_COMMAND="serial --speed=115200 --unit=1 --word=8 --parity=no --stop=1"' >>/etc/default/grub
## END config file section
## START configuring services as we need it
2018-07-26 03:57:41 -05:00
systemctl enable firewall
systemctl restart systemd-timesyncd
systemctl restart ssh
2018-07-26 03:57:41 -05:00
update-grub
sysctl -p /etc/sysctl.d/10-frr.conf
2018-07-28 15:52:38 -05:00
## END services section
2018-07-26 03:57:41 -05:00
;;
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