From 7f929bab966c44334ae6374becde189f74fc5ec0 Mon Sep 17 00:00:00 2001 From: Michal Arbet Date: Thu, 19 Dec 2019 16:46:24 +0100 Subject: [PATCH] Fix diskimage-create.sh for Debian As Ubuntu is debian-like platform, there is no reason to not support building image on Debian platform. Currently diskimage-create.sh is using head -n 1 to read /etc/os-release to fill platform bash variable. Bash platform variable is filled with NAME="Ubuntu" string as it is first line of Ubuntu's /etc/os-release. In debian the first line is for example PRETTY_NAME="Debian GNU/Linux 10 (buster)". This commit is fixing this behavior and fill platform bash variable to exact NAME variable from /etc/os-release. Change-Id: If7b507c30720516dc8dfd181170476f9ef003748 --- diskimage-create/diskimage-create.sh | 32 +++++++++++++++++++--------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/diskimage-create/diskimage-create.sh b/diskimage-create/diskimage-create.sh index f751be5f6a..9c05b1ac9f 100755 --- a/diskimage-create/diskimage-create.sh +++ b/diskimage-create/diskimage-create.sh @@ -286,7 +286,7 @@ fi # Find out what platform we are on if [ -e /etc/os-release ]; then - platform=$(head -1 /etc/os-release) + platform=$(cat /etc/os-release | grep ^NAME= | sed -e 's/\(NAME="\)\(.*\)\("\)/\2/g') else platform=$(head -1 /etc/system-release | grep -e CentOS -e 'Red Hat Enterprise Linux' || :) if [ -z "$platform" ]; then @@ -295,7 +295,7 @@ else fi fi -if [ "$AMP_ROOTPW" ] && [ "$platform" != 'NAME="Ubuntu"' ]; then +if [[ "$AMP_ROOTPW" ]] && [[ "$platform" != 'Ubuntu' ]] && ! [[ "$platform" =~ "Debian" ]]; then if [ "$(getenforce)" == "Enforcing" ]; then echo "A root password cannot be enabled for images built on this platform while SELinux is enabled." exit 1 @@ -307,7 +307,7 @@ if [ "$AMP_ROOTPW" ]; then fi # Make sure we have the required packages installed -if [ "$platform" = 'NAME="Ubuntu"' ]; then +if [[ "$platform" = 'Ubuntu' || "$platform" =~ 'Debian' ]]; then PKG_LIST="qemu-utils git kpartx debootstrap" for pkg in $PKG_LIST; do if ! dpkg --get-selections 2> /dev/null | grep -q "^$pkg[[:space:]]*install$" >/dev/null; then @@ -317,13 +317,25 @@ if [ "$platform" = 'NAME="Ubuntu"' ]; then fi done - # Also check if we can build the BASEOS on this Ubuntu version - UBUNTU_VERSION=`lsb_release -r | awk '{print $2}'` - if [ "$AMP_BASEOS" != "ubuntu-minimal" ] && \ - [ 1 -eq $(echo "$UBUNTU_VERSION < 14.04" | bc) ]; then - echo "Ubuntu minimum version 14.04 required to build $AMP_BASEOS." - echo "Earlier versions don't support the extended attributes required." - exit 1 + if [[ "$platform" = 'Ubuntu' ]]; then + # Also check if we can build the BASEOS on this Ubuntu version + UBUNTU_VERSION=`lsb_release -r | awk '{print $2}'` + if [ "$AMP_BASEOS" != "ubuntu-minimal" ] && \ + [ 1 -eq $(echo "$UBUNTU_VERSION < 14.04" | bc) ]; then + echo "Ubuntu minimum version 14.04 required to build $AMP_BASEOS." + echo "Earlier versions don't support the extended attributes required." + exit 1 + fi + else + # Check if we can build the BASEOS on this Debian version + DEBIAN_VERSION=`lsb_release -r | awk '{print $2}'` + # As minimal Ubuntu version is 14.04, for debian it is Debian 8 Jessie + if [ "$AMP_BASEOS" != "ubuntu-minimal" ] && \ + [ 1 -eq $(echo "$DEBIAN_VERSION < 8" | bc) ]; then + echo "Debian minimum version 8 required to build $AMP_BASEOS." + echo "Earlier versions don't support the extended attributes required." + exit 1 + fi fi elif [[ $platform =~ "SUSE" ]]; then # OpenSUSE