From b3b68774ab956f9b9462753c1b0fe38718a47a2e Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Thu, 30 Apr 2020 17:28:40 -0400 Subject: [PATCH] Add prototype ubuntu initrd additions This sets the stage for Ubuntu deployment --- misc/ubuntu20.04deploy/conf/conf.d/confluent | 1 + .../hooks/casper-bottom.sh | 39 +++++++++++++++++++ .../custom-installation/pre.sh | 15 +++++++ .../scripts/init-premount/confluent | 19 +++++++++ 4 files changed, 74 insertions(+) create mode 100644 misc/ubuntu20.04deploy/conf/conf.d/confluent create mode 100755 misc/ubuntu20.04deploy/custom-installation/hooks/casper-bottom.sh create mode 100755 misc/ubuntu20.04deploy/custom-installation/pre.sh create mode 100755 misc/ubuntu20.04deploy/scripts/init-premount/confluent diff --git a/misc/ubuntu20.04deploy/conf/conf.d/confluent b/misc/ubuntu20.04deploy/conf/conf.d/confluent new file mode 100644 index 00000000..49772a41 --- /dev/null +++ b/misc/ubuntu20.04deploy/conf/conf.d/confluent @@ -0,0 +1 @@ +echo /scripts/init-premount/confluent >> /scripts/init-premount/ORDER diff --git a/misc/ubuntu20.04deploy/custom-installation/hooks/casper-bottom.sh b/misc/ubuntu20.04deploy/custom-installation/hooks/casper-bottom.sh new file mode 100755 index 00000000..7b45e498 --- /dev/null +++ b/misc/ubuntu20.04deploy/custom-installation/hooks/casper-bottom.sh @@ -0,0 +1,39 @@ +cd /root +cat /tls/*.0 > /root/etc/ssl/certs/ca-certificates.crt +mkdir -p /root/custom-installation/ssh +cp /ssh/* /root/custom-installation/ssh +NODENAME=$(grep ^NODENAME: /custom-installation/confluent/confluent.info|awk '{print $2}') +MGR=$(grep ^MANAGER: /custom-installation/confluent/confluent.info|head -n 1| awk '{print $2}') +chroot . custom-installation/confluent/bin/clortho $NODENAME $MGR > /root/custom-installation/confluent/confluent.apikey +MGR=[$MGR] +deploycfg=/root/custom-installation/confluent/confluent.deploycfg +chroot . usr/bin/curl -f -H "CONFLUENT_NODENAME: $NODENAME" -H "CONFLUENT_APIKEY: $(cat /root//custom-installation/confluent/confluent.apikey)" https://${MGR}/confluent-api/self/deploycfg > $deploycfg +nic=$(grep ^MANAGER /custom-installation/confluent/confluent.info|grep fe80::|sed -e s/.*%//|head -n 1) +nic=$(ip link |grep ^$nic:|awk '{print $2}') +DEVICE=${nic%:} +ipv4m=$(grep ^ipv4_method $deploycfg|awk '{print$2}') +. /scripts/functions +if [ "$ipv4m" = "dhcp" ]; then + IP=dhcp + configure_networking +elif [ "$ipv4m" = "static" ]; then + v4addr=$(grep ^ipv4_address: $deploycfg) + v4addr=${v4addr#ipv4_address: } + v4gw=$(grep ^ipv4_gateway: $deploycfg) + v4gw=${v4gw#ipv4_gateway: } + if [ "$v4gw" = "null" ]; then + v4gw="" + fi + v4nm=$(grep ipv4_netmask: $deploycfg) + v4nm=${v4nm#ipv4_netmask: } + dns=$(grep -A1 ^nameservers: $deploycfg|head -n 2|tail -n 1|sed -e 's/^- //'|sed -e "s/''//") + + IP=$v4addr::$v4gw:$v4nm:$nodename:$DEVICE:none:$dns:: + configure_networking +else + IP=off +fi +ipv4s=$(grep ^ipv4_server $deploycfg|awk '{print $2}') +osprofile=$(cat /custom-installation/confluent/osprofile) +echo 'ds=nocloud-net;s=https://'${ipv4s}'/confluent-public/os/'${osprofile}'/autoinstall/' > /custom-installation/confluent/fakecmdline +/scripts/casper-bottom/58server_network diff --git a/misc/ubuntu20.04deploy/custom-installation/pre.sh b/misc/ubuntu20.04deploy/custom-installation/pre.sh new file mode 100755 index 00000000..4d0daead --- /dev/null +++ b/misc/ubuntu20.04deploy/custom-installation/pre.sh @@ -0,0 +1,15 @@ +#!/bin/bash +deploycfg=/custom-installation/confluent/confluent.deploycfg +mgr=$(grep ^ipv4_server $deploycfg|awk '{print $2}') +cat /custom-installation/ssh/*.rootpubkey > /root/.ssh/authorized_keys +nodename=$(grep ^NODENAME: /custom-installation/confluent/confluent.info|awk '{print $2}') +apikey=$(cat /custom-installation/confluent/confluent.apikey) +for pubkey in /etc/ssh/ssh_host*key.pub; do + certfile=${pubkey/.pub/-cert.pub} + keyfile=${pubkey%.pub} + curl -f -X POST -H "CONFLUENT_NODENAME: $nodename" -H "CONFLUENT_APIKEY: $apikey" -d @$pubkey https://$mgr/confluent-api/self/sshcert > $certfile + echo HostKey $keyfile >> /etc/ssh/sshd_config.d/confluent.conf + echo HostCertificate $certfile >> /etc/ssh/sshd_config.d/confluent.conf +done +systemctl restart sshd +sleep 86400 diff --git a/misc/ubuntu20.04deploy/scripts/init-premount/confluent b/misc/ubuntu20.04deploy/scripts/init-premount/confluent new file mode 100755 index 00000000..dbca9d49 --- /dev/null +++ b/misc/ubuntu20.04deploy/scripts/init-premount/confluent @@ -0,0 +1,19 @@ +cd /sys/class/net +for nic in *; do + ip link set $nic up +done +mkdir -p /custom-installation +cp -a /opt/confluent /custom-installation +touch /custom-installation/confluent/confluent.info +while ! grep NODENAME /custom-installation/confluent/confluent.info; do + /opt/confluent/bin/copernicus -t > /custom-installation/confluent/confluent.info +done +MGR="[$(grep MANAGER: /custom-installation/confluent/confluent.info | head -n 1 | awk '{print $2}')]" +osprofile=$(sed -e 's/.*osprofile=//' -e 's/ .*//' /proc/cmdline) +echo "Deploying $osprofile from $MGR" +echo $osprofile > /custom-installation/confluent/osprofile +echo URL=http://${MGR}/confluent-public/os/$osprofile/distribution/live.iso >> /conf/param.conf +echo "url=http://${MGR}/confluent-public/os/$osprofile/distribution/live.iso" > /custom-installation/confluent/fakecmdline +mount -o bind /custom-installation/confluent/fakecmdline /proc/cmdline + +