From 248bdb7f80cdb78b7bdfb3ce5158480632661ca9 Mon Sep 17 00:00:00 2001 From: root Date: Thu, 2 Aug 2018 21:35:37 +0000 Subject: [PATCH] refacotring to some extend now that we switched to dhcpcd and turned off networkd entirely. --- debian/wit-hypervisor-config.install | 1 - debian/wit-hypervisor-config.postinst | 26 +++++++++++--------------- debian/wit-hypervisor-config.transform | 2 +- files/dhcp-sethostname | 9 +++------ files/resolv.conf | 2 -- 5 files changed, 15 insertions(+), 25 deletions(-) delete mode 100644 files/resolv.conf diff --git a/debian/wit-hypervisor-config.install b/debian/wit-hypervisor-config.install index 6371005..2473510 100644 --- a/debian/wit-hypervisor-config.install +++ b/debian/wit-hypervisor-config.install @@ -6,7 +6,6 @@ files/rc.local etc files/10-frr.conf etc/sysctl.d files/11-mgmt1.conf etc/sysctl.d files/wit-gc usr/bin -files/resolv.conf etc files/bashrc-witaddon etc files/qemu-ifdown etc/libvirt/hooks files/qemu-ifup-public etc/libvirt/hooks diff --git a/debian/wit-hypervisor-config.postinst b/debian/wit-hypervisor-config.postinst index 6f3b6b8..dbd7eff 100755 --- a/debian/wit-hypervisor-config.postinst +++ b/debian/wit-hypervisor-config.postinst @@ -28,24 +28,19 @@ case "$1" in [ -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 DOMAINNAME=${HOSTNAME#*.} 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 $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 - + [ $HOSTTYPE != hypervisor -a $HOSTTYPE != datanode ] && sed -ie "s/^TIER_ID.*/TIER_ID=$TIER_ID/; t; $ s/$/\nTIER_ID=$TIER_ID/" /etc/environment if [ -z "$TIER_ID" ]; then echo "Unable to autodetect TIER_ID, looks like we deal with a special node, please set in environment" @@ -82,8 +77,8 @@ case "$1" in 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 + sed -i -e "s/HOSTNAME\.DOMAINNAME/${HOSTNAME}/" /etc/ipsec.conf.wit + echo ": RSA ${HOSTNAME}.key" >/etc/ipsec.secrets chmod 600 /etc/ipsec.secrets @@ -100,8 +95,9 @@ case "$1" in sed -i "/$MGMT_MAC.*feth./d" /etc/udev/rules.d/70-persistent-net.rules - sed -i -e "/.*debcore1/d" -e "/.*${HOSTNAME}/d" /etc/hosts - echo -e "${LOOPBACKv4}\t${HOSTNAME}${DOMAINNAME}\t${HOSTNAME}" >>/etc/hosts + sed -i -e "/debcore1/d" -e "/${HOSTNAME%%.*}/d" -e "/${LOOPBACKv4}/d" /etc/hosts + echo -e "${LOOPBACKv4}\t${HOSTNAME}\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 diff --git a/debian/wit-hypervisor-config.transform b/debian/wit-hypervisor-config.transform index 0ca00bf..70f0b54 100644 --- a/debian/wit-hypervisor-config.transform +++ b/debian/wit-hypervisor-config.transform @@ -1,3 +1,3 @@ /etc/systemd/timesyncd.conf.wit sed -e 's/#NTP=.*/NTP=ipv6.ntp.ubuntu.com/g' -/etc/bash.bashrc.wit sed -e '/.*bashrc-witaddon.*/d' -e '$ s/$/\nsource \/etc\/bashrc-witaddon/' /etc/frr/daemons.wit sed -e 's/bgpd=no/bgpd=yes/' -e 's/zebra=no/zebra=yes/' +/etc/bash.bashrc.wit sed -e 's/.*witaddon/source \/etc\/bashrc-witaddon/; t; $ s/$/\nsource \/etc\/bashrc-witaddon/' diff --git a/files/dhcp-sethostname b/files/dhcp-sethostname index 346dab7..5277b6c 100644 --- a/files/dhcp-sethostname +++ b/files/dhcp-sethostname @@ -1,8 +1,5 @@ if [ ! -z $new_host_name ]; then - hostname $new_host_name - echo $new_host_name >/etc/hostname -fi -if [ ! -z $new_domain_name ]; then - host_name=$(hostname) - sed -i "s/\([0-9]*\.[0-9]*\.[0-9]*\.[0-9]*\).*$host_name.*/\1 $host_name.${new_domain_name:-local} $host_name/" /etc/hosts + hostname $new_host_name.${new_domain_name:-local} + hostname >/etc/hostname + sed -i "s/\([0-9]*\.[0-9]*\.[0-9]*\.[0-9]*\).*$old_host_name\.$old_domain_name.*/\1 $new_host_name.${new_domain_name:-local} $new_host_name/" /etc/hosts fi diff --git a/files/resolv.conf b/files/resolv.conf deleted file mode 100644 index bde3fb0..0000000 --- a/files/resolv.conf +++ /dev/null @@ -1,2 +0,0 @@ -nameserver 2001:4860:4860::8888 -nameserver 2001:4860:4860::8844