From 7cd2a6c8d5359fdaa6b5780dccd76e35a7c03ad5 Mon Sep 17 00:00:00 2001 From: Alex-Welsh Date: Thu, 30 May 2024 16:57:34 +0100 Subject: [PATCH] Automate default user selection and OS evaluation --- a-seed-from-nothing.sh | 16 +++++----------- pull-retag-push-images.sh | 9 ++------- 2 files changed, 7 insertions(+), 18 deletions(-) diff --git a/a-seed-from-nothing.sh b/a-seed-from-nothing.sh index fe43806..db0b448 100644 --- a/a-seed-from-nothing.sh +++ b/a-seed-from-nothing.sh @@ -3,9 +3,6 @@ # Reset SECONDS SECONDS=0 -# Cloud User: cloud-user (CentOS) or ubuntu? -CLOUD_USER=ubuntu - ENABLE_OVN=true # Registry IP @@ -14,8 +11,7 @@ registry_ip=$1 echo "[INFO] Given docker registry IP: $registry_ip" # Disable the firewall. -if [[ "${CLOUD_USER}" = "ubuntu" ]] -then +if type apt; then grep -q $HOSTNAME /etc/hosts || (echo "$(ip r | grep -o '^default via.*src [0-9.]*' | awk '{print $NF}') $HOSTNAME" | sudo tee -a /etc/hosts) dpkg -l ufw && sudo systemctl is-enabled ufw && sudo systemctl stop ufw && sudo systemctl disable ufw else @@ -26,8 +22,7 @@ else fi # Useful packages -if [[ "${CLOUD_USER}" = "ubuntu" ]] -then +if type apt; then # Avoid the interactive dialog prompting for service restart: set policy to leave services unchanged echo "\$nrconf{restart} = 'l';" | sudo tee /etc/needrestart/conf.d/90-aufn.conf sudo apt update @@ -45,8 +40,7 @@ EOF sudo sysctl --load /etc/sysctl.d/70-ipv6.conf # CentOS Stream 8 requires network-scripts. Rocky Linux 9 and onwards use NetworkManager. -if [[ "${CLOUD_USER}" = "cloud-user" ]] -then +if type dnf; then case $(grep -o "[89]\.[0-9]" /etc/redhat-release) in "8.*") sudo dnf install -y network-scripts @@ -63,8 +57,7 @@ then exit -1 ;; esac -elif [[ "${CLOUD_USER}" = "ubuntu" ]] -then +elif type apt; then # Prepare for disabling of Netplan and enabling of systemd-networkd. # Netplan has an interaction with systemd and cloud-init to populate # systemd-networkd files, but ephemerally. If /etc/systemd/network is @@ -84,6 +77,7 @@ fi set -e # Ensure an ssh key is generated +CLOUD_USER=/home/$(ls /home | grep -v lab | grep -v stack | head -1) # NOTE: you might think ~${CLOUD_USER} would work but apparently not CLOUD_USER_DIR=/home/${CLOUD_USER} keyfile="$HOME/.ssh/id_rsa" diff --git a/pull-retag-push-images.sh b/pull-retag-push-images.sh index a9abdf0..eb8dfcb 100755 --- a/pull-retag-push-images.sh +++ b/pull-retag-push-images.sh @@ -5,11 +5,7 @@ set -e # Reset SECONDS SECONDS=0 -# DISTRO: CentOS or Ubuntu? -DISTRO=ubuntu - -if [[ "${DISTRO}" = "ubuntu" ]] -then +if type apt; then # Install and start docker [[ -f /usr/share/keyrings/docker-archive-keyring.gpg ]] || (curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg) echo \ @@ -43,8 +39,7 @@ fi registry=quay.io acct=openstack.kolla -if [[ "${DISTRO}" = "ubuntu" ]] -then +if type apt; then tag=${1:-2023.1-ubuntu-jammy} else tag=${1:-2023.1-rocky-9}