From cc4109c11df046361270d61f2ea40ca02fedf455 Mon Sep 17 00:00:00 2001 From: nemo Date: Sun, 23 Jun 2019 15:12:15 +0200 Subject: [PATCH] Add portage check : CHOST, GRUB_PLATFORMS, CPU_FLAGS_X86 and if GENTOO_MIRRORS includes organization mirror --- README.md | 5 +- recipes/recipe_check_portage.sh | 131 +++++++++++++++++++++++++++++--- vars.example | 4 + 3 files changed, 127 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 917111a..b2a05e4 100644 --- a/README.md +++ b/README.md @@ -15,9 +15,8 @@ Not finished, in progress.... TO DO : - Check if borgbackup is configured (OK, need to be fully tested) - Check if auto-update script is configured -- Add other check to Portage configuration (CHOST, GRUB_PLATFORMS, GENTOO_MIRRORS and CPU_FLAGS_X86 for VM and Physical hosts support) - Others (script design, documentation...) - + Checked point : - User is root to run the script - Check requirements @@ -34,7 +33,7 @@ Checked point : - Mail alias configuration (root and operator mail alias configured) - Check postfix config (inet_protocols, mail_owner) - Add to check service if they are enabled -- Check portage configuration (FEATURES, PORTAGE_BINHOST, ACCEPT_LICENSE and USE for VM) +- Check portage configuration (FEATURES, PORTAGE_BINHOST, ACCEPT_LICENSE, USE, CHOST, GRUB_PLATFORMS, CPU_FLAGS_X86 and if GENTOO_MIRRORS includes organization mirror) - Check if IPs (scope global) are recorded in IPAM - Check if the selected Gentoo profile is the expected profile - Print additional manuel verification (send reporting mail, if /etc conf file need to be updated, if a new kernel can be installed, if server-side for Icinga, SNMP and Munin are configured) diff --git a/recipes/recipe_check_portage.sh b/recipes/recipe_check_portage.sh index 1b75293..d883781 100644 --- a/recipes/recipe_check_portage.sh +++ b/recipes/recipe_check_portage.sh @@ -11,12 +11,12 @@ RC=$? if [ $RC -ne 0 ] then PORTAGE_CONFIG_CHECK_FAILED="${PORTAGE_CONFIG_CHECK_FAILED} Portage binpkg feature not configured, add FEATURES=\"getbinpkg\" in /etc/portage/make.conf ;" - echo -e "${RED}Portage getbinpkg feature NOT CONFIGURED in /etc/portage/make.conf : check KO${NC}\n" + echo -e "${RED}Portage getbinpkg feature is NOT CONFIGURED in /etc/portage/make.conf : check KO${NC}\n" # Portage conf includes getbinpkg FEATURE else # If there are multiple definitions of FEATURE variable, KO - FEATURE_DEFINITION_NUMBER="$(grep "^[[:space:]]*FEATURES" /etc/portage/make.conf | wc -l)" - if [ "${USE_DEFINITION_NUMBER}" -gt "1" ] + FEATURE_DEFINITION_NUMBER="$(grep \"^[[:space:]]*FEATURES\" /etc/portage/make.conf | wc -l)" + if [ "${FEATURE_DEFINITION_NUMBER}" -gt "1" ] then PORTAGE_CONFIG_CHECK_FAILED="${PORTAGE_CONFIG_CHECK_FAILED} Multiple definitions of FEATURE variable in /etc/portage/make.conf, define the variable FEATURE only once in /etc/portage/make.conf ;" echo -e "${RED}Multiple definitions of FEATURE variable in /etc/portage/make.conf : check KO${NC}\n" @@ -38,14 +38,14 @@ RC=$? if [ $RC -ne 0 ] then PORTAGE_CONFIG_CHECK_FAILED="${PORTAGE_CONFIG_CHECK_FAILED} Portage PORTAGE_BINHOST not configured, add PORTAGE_BINHOST=\"${BINPKGREPO}\" in /etc/portage/make.conf ;" - echo -e "${RED}Portage PORTAGE_BINHOST NOT well CONFIGURED in /etc/portage/make.conf : check KO${NC}\n" + echo -e "${RED}Portage PORTAGE_BINHOST is NOT well CONFIGURED in /etc/portage/make.conf : check KO${NC}\n" # Portage PORTAGE_BINHOST well CONFIGURED else # If there are multiple definitions of PORTAGE_BINHOST variable, KO PORTAGE_BINHOST_DEFINITION_NUMBER="$(grep "^[[:space:]]*PORTAGE_BINHOST" /etc/portage/make.conf | wc -l)" if [ "${PORTAGE_BINHOST_DEFINITION_NUMBER}" -gt "1" ] then - PORTAGE_CONFIG_CHECK_FAILED="${PORTAGE_CONFIG_CHECK_FAILED} Multiple definitions of PORTAGE_BINHOST variable in /etc/portage/make.conf, define he variable PORTAGE_BINHOST only once in /etc/portage/make.conf ;" + PORTAGE_CONFIG_CHECK_FAILED="${PORTAGE_CONFIG_CHECK_FAILED} Multiple definitions of PORTAGE_BINHOST variable in /etc/portage/make.conf, define the variable PORTAGE_BINHOST only once in /etc/portage/make.conf ;" echo -e "${RED}Multiple definitions of PORTAGE_BINHOST variable in /etc/portage/make.conf : check KO${NC}\n" # Else it's OK else @@ -65,18 +65,18 @@ RC=$? if [ $RC -ne 0 ] then PORTAGE_CONFIG_CHECK_FAILED="${PORTAGE_CONFIG_CHECK_FAILED} Portage ACCEPT_LICENSE not configured, add ACCEPT_LICENSE=\"$(echo ${PORTAGE_ACCEPTLICENSE} | tr -d '\\')\" in /etc/portage/make.conf ;" - echo -e "${RED}Portage ACCEPT_LICENSE feature NOT well CONFIGURED in /etc/portage/make.conf : check KO${NC}\n" + echo -e "${RED}Portage ACCEPT_LICENSE feature is NOT well CONFIGURED in /etc/portage/make.conf : check KO${NC}\n" # Portage ACCEPT_LICENSE well CONFIGURED else # If there are multiple definitions of ACCEPT_LICENSE variable, KO ACCEPT_LICENSE_DEFINITION_NUMBER="$(grep "^[[:space:]]*ACCEPT_LICENSE" /etc/portage/make.conf | wc -l)" if [ "${ACCEPT_LICENSE_DEFINITION_NUMBER}" -gt "1" ] then - PORTAGE_CONFIG_CHECK_FAILED="${PORTAGE_CONFIG_CHECK_FAILED} Multiple definitions of ACCEPT_LICENSE variable in /etc/portage/make.conf, define he variable ACCEPT_LICENSE only once in /etc/portage/make.conf ;" + PORTAGE_CONFIG_CHECK_FAILED="${PORTAGE_CONFIG_CHECK_FAILED} Multiple definitions of ACCEPT_LICENSE variable in /etc/portage/make.conf, define the variable ACCEPT_LICENSE only once in /etc/portage/make.conf ;" echo -e "${RED}Multiple definitions of ACCEPT_LICENSE variable in /etc/portage/make.conf : check KO${NC}\n" # Else it's OK else - echo -e "${GREEN}Portage ACCEPT_LICENSE feature well CONFIGURED in /etc/portage/make.conf : check OK${NC}\n" + echo -e "${GREEN}Portage ACCEPT_LICENSE variable well CONFIGURED in /etc/portage/make.conf : check OK${NC}\n" fi fi @@ -91,14 +91,14 @@ USE_DEFINITION_NUMBER="$(grep "^[[:space:]]*USE" /etc/portage/make.conf | wc -l) if [ "${USE_DEFINITION_NUMBER}" -eq "1" ] then # Get actual global USE flags in /etc/portage/make.conf and format to compare - ACTUAL_PORTAGE_USE="$(sed -n '/^USE=\"/,/\"/p' /etc/portage/make.conf | tr -d '\n' | cut -d'"' -f2 | sed 's/ /\n/g' | sort | tr '\n' ' ' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')" + ACTUAL_PORTAGE_USE="$(sed -n '/^[[:space:]]*USE=\"/,/\"/p' /etc/portage/make.conf | tr -d '\n' | cut -d'"' -f2 | sed 's/ /\n/g' | sort | tr '\n' ' ' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')" PORTAGE_USE_SORTED="$(echo ${PORTAGE_USE} | sed 's/ /\n/g' | sort | tr '\n' ' ' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')" # Global USE flags in /etc/portage/make.conf is well configured if [ "$ACTUAL_PORTAGE_USE" == "$PORTAGE_USE_SORTED" ] then echo -e "${GREEN}Global USE flags in /etc/portage/make.conf is well configured : check OK${NC}\n" - # Global USE flags in NOT /etc/portage/make.conf is well configured + # Global USE flags in /etc/portage/make.conf is NOT well configured else PORTAGE_CONFIG_CHECK_FAILED="${PORTAGE_CONFIG_CHECK_FAILED} Global USE flags in /etc/portage/make.conf is NOT well CONFIGURED, set USE=\"${PORTAGE_USE_SORTED}\" in /etc/portage/make.conf ;" echo -e "${RED}Global USE flags in /etc/portage/make.conf is NOT well CONFIGURED : check KO${NC}\n" @@ -109,3 +109,114 @@ else fi +# Check if make.conf includes well configured CHOST +echo "Check if /etc/portage/make.conf includes well configured CHOST" +grep -q "^[[:space:]]*CHOST=\"${PORTAGE_CHOST}\"[[:space:]]*$" /etc/portage/make.conf + +# Return Code +RC=$? + +# Portage CHOST NOT well CONFIGURED +if [ $RC -ne 0 ] +then + PORTAGE_CONFIG_CHECK_FAILED="${PORTAGE_CONFIG_CHECK_FAILED} Portage CHOST not configured, add CHOST=\"${PORTAGE_CHOST}\" in /etc/portage/make.conf ;" + echo -e "${RED}Portage CHOST feature is NOT well CONFIGURED in /etc/portage/make.conf : check KO${NC}\n" +# Portage CHOST well CONFIGURED +else + # If there are multiple definitions of CHOST variable, KO + CHOST_DEFINITION_NUMBER="$(grep "^[[:space:]]*CHOST" /etc/portage/make.conf | wc -l)" + if [ "${CHOST_DEFINITION_NUMBER}" -gt "1" ] + then + PORTAGE_CONFIG_CHECK_FAILED="${PORTAGE_CONFIG_CHECK_FAILED} Multiple definitions of CHOST variable in /etc/portage/make.conf, define the variable CHOST only once in /etc/portage/make.conf ;" + echo -e "${RED}Multiple definitions of CHOST variable in /etc/portage/make.conf : check KO${NC}\n" + # Else it's OK + else + echo -e "${GREEN}Portage CHOST variable well CONFIGURED in /etc/portage/make.conf : check OK${NC}\n" + fi +fi + + +# Check if make.conf includes well configured GRUB_PLATFORMS +echo "Check if /etc/portage/make.conf includes well configured GRUB_PLATFORMS" +grep -q "^[[:space:]]*GRUB_PLATFORMS=\"${PORTAGE_GRUB_PLATFORMS}\"[[:space:]]*$" /etc/portage/make.conf + +# Return Code +RC=$? + +# Portage GRUB_PLATFORMS NOT well CONFIGURED +if [ $RC -ne 0 ] +then + PORTAGE_CONFIG_CHECK_FAILED="${PORTAGE_CONFIG_CHECK_FAILED} Portage CHOST not configured, add GRUB_PLATFORMS=\"${PORTAGE_GRUB_PLATFORMS}\" in /etc/portage/make.conf ;" + echo -e "${RED}Portage GRUB_PLATFORMS feature is NOT well CONFIGURED in /etc/portage/make.conf : check KO${NC}\n" +# Portage GRUB_PLATFORMS well CONFIGURED +else + # If there are multiple definitions of CHOST variable, KO + GRUB_PLATFORMS_DEFINITION_NUMBER="$(grep "^[[:space:]]*GRUB_PLATFORMS" /etc/portage/make.conf | wc -l)" + if [ "${GRUB_PLATFORMS_DEFINITION_NUMBER}" -gt "1" ] + then + PORTAGE_CONFIG_CHECK_FAILED="${PORTAGE_CONFIG_CHECK_FAILED} Multiple definitions of GRUB_PLATFORMS variable in /etc/portage/make.conf, define the variable GRUB_PLATFORMS only once in /etc/portage/make.conf ;" + echo -e "${RED}Multiple definitions of GRUB_PLATFORMS variable in /etc/portage/make.conf : check KO${NC}\n" + # Else it's OK + else + echo -e "${GREEN}Portage GRUB_PLATFORMS variable well CONFIGURED in /etc/portage/make.conf : check OK${NC}\n" + fi +fi + + +# Check if portage organization mirror is configured in /etc/portage/make.conf +echo "Check if portage oragnization mirror is configured in /etc/portage/make.conf" + +# Check if GENTOO_MIRRORS variable has multiple definiton +GENTOO_MIRRORS_DEFINITION_NUMBER="$(grep "^[[:space:]]*GENTOO_MIRRORS" /etc/portage/make.conf | wc -l)" + +# If there is only one definition, it's OK +if [ "${GENTOO_MIRRORS_DEFINITION_NUMBER}" -eq "1" ] +then + # Check if GENTOO_MIRRORS value in /etc/portage/make.conf includes organization mirror + sed -n '/^[[:space:]]*GENTOO_MIRRORS=\"/,/\"/p' /etc/portage/make.conf | grep -q "${PORTAGE_ORGANIZATION_MIRROR}" + + # Return Code + RC=$? + + # GENTOO_MIRRORS in /etc/portage/make.conf includes organization mirror + if [ $RC -eq 0 ] + then + echo -e "${GREEN}GENTOO_MIRRORS in /etc/portage/make.conf includes organization mirror : check OK${NC}\n" + # GENTOO_MIRRORS in /etc/portage/make.conf does NOT includes organization mirror + else + PORTAGE_CONFIG_CHECK_FAILED="${PORTAGE_CONFIG_CHECK_FAILED} GENTOO_MIRRORS in /etc/portage/make.conf does NOT includes organization mirror, add ${PORTAGE_ORGANIZATION_MIRROR} mirror in GENTOO_MIRRORS variable in /etc/portage/make.conf ;" + echo -e "${RED}GENTOO_MIRRORS in /etc/portage/make.conf does NOT includes organization mirror : check KO${NC}\n" + fi +else + PORTAGE_CONFIG_CHECK_FAILED="${PORTAGE_CONFIG_CHECK_FAILED} GENTOO_MIRRORS in /etc/portage/make.conf has multiple definitions OR there is NO GENTOO_MIRRORS variable, define GENTOO_MIRRORS variable and only once in /etc/portage/make.conf ;" + echo -e "${RED}GENTOO_MIRRORS in /etc/portage/make.conf has multiple definitions OR GENTOO_MIRRORS variable is not defined : check KO${NC}\n" +fi + + + +# Check if global CPU_FLAGS_X86 flags is well configured in /etc/portage/make.conf +echo "Check if global CPU_FLAGS_X86 flags is well configured in /etc/portage/make.conf" + +# Check if CPU_FLAGS_X86 variable has multiple definiton +CPU_FLAGS_X86_DEFINITION_NUMBER="$(grep "^[[:space:]]*CPU_FLAGS_X86" /etc/portage/make.conf | wc -l)" + +# If there is only one definition, it's OK +if [ "${CPU_FLAGS_X86_DEFINITION_NUMBER}" -eq "1" ] +then + # Get actual global CPU_FLAGS_X86 flags in /etc/portage/make.conf and format to compare + ACTUAL_PORTAGE_CPU_FLAGS_X86="$(sed -n '/^[[:space:]]*CPU_FLAGS_X86=\"/,/\"/p' /etc/portage/make.conf | tr -d '\n' | cut -d'"' -f2 | sed 's/ /\n/g' | sort | tr '\n' ' ' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')" + PORTAGE_CPU_FLAGS_X86_SORTED="$(echo ${PORTAGE_CPU_FLAGS_X86} | sed 's/ /\n/g' | sort | tr '\n' ' ' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')" + + # Global CPU_FLAGS_X86 flags in /etc/portage/make.conf is well configured + if [ "$ACTUAL_PORTAGE_CPU_FLAGS_X86" == "$PORTAGE_CPU_FLAGS_X86_SORTED" ] + then + echo -e "${GREEN}Global CPU_FLAGS_X86 flags in /etc/portage/make.conf is well configured : check OK${NC}\n" + # Global CPU_FLAGS_X86 flags in /etc/portage/make.conf is NOT well configured + else + PORTAGE_CONFIG_CHECK_FAILED="${PORTAGE_CONFIG_CHECK_FAILED} Global CPU_FLAGS_X86 flags in /etc/portage/make.conf is NOT well CONFIGURED, set CPU_FLAGS_X86=\"${PORTAGE_CPU_FLAGS_X86_SORTED}\" in /etc/portage/make.conf ;" + echo -e "${RED}Global CPU_FLAGS_X86 flags in /etc/portage/make.conf is NOT well CONFIGURED : check KO${NC}\n" + fi +else + PORTAGE_CONFIG_CHECK_FAILED="${PORTAGE_CONFIG_CHECK_FAILED} Global CPU_FLAGS_X86 flags in /etc/portage/make.conf has multiple definitions OR there is NO CPU_FLAGS_X86 variable, define CPU_FLAGS_X86 variable and only once in /etc/portage/make.conf ;" + echo -e "${RED}Global CPU_FLAGS_X86 flags in /etc/portage/make.conf has multiple definitions OR CPU_FLAGS_X86 variable is not defined : check KO${NC}\n" +fi diff --git a/vars.example b/vars.example index 60648a5..9cedba6 100755 --- a/vars.example +++ b/vars.example @@ -145,4 +145,8 @@ export PORTAGE_USE='bash-completion threads vim-pager vim-syntax' +export PORTAGE_CHOST="x86_64-pc-linux-gnu" +export PORTAGE_CPU_FLAGS_X86="mmx mmxext sse sse2 sse3" +export PORTAGE_ORGANIZATION_MIRROR="http://mirror.example.com/gentoo" +export PORTAGE_GRUB_PLATFORMS="pc"