21662: Refine distro detection in jenkins-image-common main
authorBrett Smith <brett.smith@curii.com>
Fri, 19 Apr 2024 20:06:05 +0000 (16:06 -0400)
committerBrett Smith <brett.smith@curii.com>
Fri, 19 Apr 2024 20:12:07 +0000 (16:12 -0400)
* Use ID_LIKE to identify distros rather than having whole lists.
* Only install buster-backports when we're actually on buster.

Refs #21662.

Arvados-DCO-1.1-Signed-off-by: Brett Smith <brett.smith@curii.com>

jenkins/packer-images/jenkins-image-common.sh

index e68b092c0779fd178f3c757787f52ab09cc8f28e..9f3c4616fd61029704c12d5c188e639325b3aed8 100755 (executable)
@@ -11,29 +11,31 @@ sudo su -c "echo ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQCfRJenfxGPFuJ/W2KUs6Wf0wa
 sudo su -c "echo ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQDH8swFWEfEfHhA+C5ezV8SXO/PkzGD1SH5VAQP/XDIrtnUocBZ3CE30lSyqYJI/EVKVqVa/ICQ0YpUwiMK6+3Jr9QQJwVyTmPji2nY3InL+1XAucN6HFJGKY9bYSsNOuKooj22GwBWw3gfJNLg/8qtpVykEq1yRpyh6pGsXT+J5nUZ723vZZTh//sxdN4CM8D8zoDgHc4RbL+zvESnCDrDbtMhg2u1h14RWiFOBAnzYuWcgtVDy2HA9iS0hJFB2UOV50byXLrEetxJ84PTwRsV2irq1y63g58VxwYOUrVZ08MY5qFvHExBjPqeqhRMzE7GufWM5F1CcUuGviOGFWfqMnfG4VOirPkFtRoK2oKRxH+NVPoUXWWxItJQ1dZ9hLDDWgAbxAvLS4Nnl2hvOVAbC7RVpXfoAhIPpL48oS1UprbsZIMxk2ZmRSJB1ykD3aLUvoO4zoD6xADt8uLiPvVYgFWUy1doLxHZqdY1Omc91owgQVPKvQ4vhqsJehQl4ZDS+O+8S7aC5m8sQ/V+NqiiXLH22vN58K7qNrkHWdb1n+rhilMbA5zp3cSKBgwmmNdupyPkJOKvf3IS7i4El+c8RFmRQv4FzGrdjGXAP8LPtt1dWPgHTFYjmrkOHLmfWM/y8cuyPWW/HEp3Y/msPQRlS3Gymce//vAWgN4T9yN46w== lucas@notebook" >> /home/jenkins/.ssh/authorized_keys
 
 # Install a few dependency packages
-# First, let's figure out the OS we're working on
-OS_ID=$(grep ^ID= /etc/os-release |cut -f 2 -d \" | cut -f 2 -d = )
-echo "Detected distro: ${OS_ID}"
-
-case ${OS_ID} in
-  centos)
-    PREINSTALL_CMD="/bin/true"
-    INSTALL_CMD="yum install -y"
-    POSTINSTALL_CMD="/bin/true"
-    PKGS="git nmap-ncat java-11-openjdk"
-    ;;
-  debian|ubuntu)
-    if [ ${OS_ID} = "debian" ]; then
-      echo "deb http://deb.debian.org/debian buster-backports main" | sudo tee /etc/apt/sources.list.d/buster-backports.list
-    fi
-    PREINSTALL_CMD="DEBIAN_FRONTEND=noninteractive apt-get update"
-    INSTALL_CMD="DEBIAN_FRONTEND=noninteractive apt-get install -y"
-    POSTINSTALL_CMD="DEBIAN_FRONTEND=noninteractive apt-get purge --autoremove -y"
-    # SUFFIX packages with - to remove them
-    # Remove unattended-upgrades so that it doesn't interfere with our nodes at startup
-    PKGS="git netcat-traditional default-jdk unattended-upgrades-"
-    ;;
-esac
+. /etc/os-release
+PREINSTALL_CMD='echo "error: unknown distro" >&2; false'
+for OS_ID in ${ID:-} ${ID_LIKE:-}; do
+  case ${OS_ID} in
+    rhel)
+      PREINSTALL_CMD="/bin/true"
+      INSTALL_CMD="yum install -y"
+      POSTINSTALL_CMD="/bin/true"
+      PKGS="git nmap-ncat java-11-openjdk"
+      break
+      ;;
+    debian)
+      if [[ "$VERSION_CODENAME" == buster ]]; then
+        echo "deb http://deb.debian.org/debian buster-backports main" | sudo tee /etc/apt/sources.list.d/buster-backports.list
+      fi
+      PREINSTALL_CMD="DEBIAN_FRONTEND=noninteractive apt-get update"
+      INSTALL_CMD="DEBIAN_FRONTEND=noninteractive apt-get install -y"
+      POSTINSTALL_CMD="DEBIAN_FRONTEND=noninteractive apt-get purge --autoremove -y"
+      # SUFFIX packages with - to remove them
+      # Remove unattended-upgrades so that it doesn't interfere with our nodes at startup
+      PKGS="git netcat-traditional default-jdk unattended-upgrades-"
+      break
+      ;;
+  esac
+done
 
 sudo su -c "${PREINSTALL_CMD}"
 sudo su -c "${INSTALL_CMD} ${PKGS}"