2019-03-24 15:56:17 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
# Recipe script for a Gentoo system to check basic configuration
|
|
|
|
|
|
|
|
# Define colors
|
2019-03-31 10:57:45 +02:00
|
|
|
export RED='\033[1;31m'
|
|
|
|
export BLUE='\033[1;34m'
|
|
|
|
export GREEN='\033[1;32m'
|
|
|
|
# No Color
|
|
|
|
export NC='\033[0m'
|
2019-03-24 15:56:17 +01:00
|
|
|
|
2019-03-31 10:57:45 +02:00
|
|
|
REQUIREMENTS="CURL GREP ECHO EMERGE NSLOOKUP IP HOSTNAME AWK SED CUT TR PING JQ CURL"
|
2019-03-29 20:16:50 +01:00
|
|
|
|
2019-03-31 18:32:28 +02:00
|
|
|
# Be sure only root can run the script
|
|
|
|
if [ "$(id -u)" != "0" ]; then
|
|
|
|
echo "ERROR : This script must be run as root" 1>&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
VARS_FILE='./vars.sh'
|
|
|
|
if [ -f ${VARS_FILE} ]; then
|
|
|
|
source ${VARS_FILE}
|
|
|
|
else
|
|
|
|
echo "ERROR : vars file ${VARS_FILE} not found" 1>&2
|
|
|
|
exit 1
|
|
|
|
fi
|
2019-03-24 15:56:17 +01:00
|
|
|
|
2019-03-29 20:16:50 +01:00
|
|
|
# Check requirements
|
|
|
|
for requirement in $REQUIREMENTS
|
|
|
|
do
|
|
|
|
# Check if requirement tool exit on the system
|
|
|
|
which $(eval echo "\$${requirement}") &>/dev/null
|
|
|
|
|
|
|
|
# Return Code
|
|
|
|
RC=$?
|
|
|
|
|
|
|
|
if [ ${RC} -ne 0 ]
|
|
|
|
then
|
2019-05-01 17:16:58 +02:00
|
|
|
echo "ERROR : ${requirement} ($(eval echo "\$${requirement}")) is required to use this script. Requirements are : ${REQUIREMENTS}."
|
2019-03-29 20:16:50 +01:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-03-24 15:56:17 +01:00
|
|
|
# Print packages not installed or with error at end script
|
2019-03-31 10:57:45 +02:00
|
|
|
export PACKAGES_TO_CHECK=""
|
|
|
|
export RESOLV_FAILED=""
|
|
|
|
export RESOLVER_NOT_IN_ETC_RESOLVCONF=""
|
|
|
|
export IP_NOT_RECORDED_IN_DNS=""
|
|
|
|
export PING_FAILED=""
|
2019-03-24 15:56:17 +01:00
|
|
|
|
|
|
|
# Get ALL locales IPs except loopback
|
2019-03-31 10:57:45 +02:00
|
|
|
export LOCALES_IP_WITHOUT_LOOPBACK=$(ip addr show scope global | awk '/inet/ { sub(/\/.*$/, "", $2); print $2 }' | sort | uniq)
|
2019-03-24 15:56:17 +01:00
|
|
|
|
2019-05-01 17:16:58 +02:00
|
|
|
export IPV6_ADMIN_LAN_IP=$(echo ${LOCALES_IP_WITHOUT_LOOPBACK} | tr " " "\n" | grep ^${IPV6_ADMIN_NETWORK})
|
|
|
|
export IPV4_ADMIN_LAN_IP=$(echo ${LOCALES_IP_WITHOUT_LOOPBACK} | tr " " "\n" | grep ^${IPV4_ADMIN_NETWORK})
|
|
|
|
|
2019-03-31 10:57:45 +02:00
|
|
|
export BOOL_ADMIN_IPV4_NOT_CONFIGURED=0
|
|
|
|
export BOOL_ADMIN_IPV6_NOT_CONFIGURED=0
|
2019-03-24 15:56:17 +01:00
|
|
|
|
|
|
|
# Print services not started or with error at end script
|
2019-03-31 10:57:45 +02:00
|
|
|
export SERVICES_NOT_STARTED_OR_ERROR=""
|
2019-03-24 15:56:17 +01:00
|
|
|
|
|
|
|
# Print message at end script if hostname *.grif or *.grifon.fr not configured
|
2019-03-31 10:57:45 +02:00
|
|
|
export BOOL_CHECK_HOSTNAME=0
|
2019-03-24 15:56:17 +01:00
|
|
|
|
2019-03-31 10:57:45 +02:00
|
|
|
export SSH_CONFIG_CHECK_FAILED=""
|
|
|
|
export NRPE_CONFIG_CHECK_FAILED=""
|
|
|
|
export MUNIN_CONFIG_CHECK_FAILED=""
|
|
|
|
export MAIL_ALIAS_CONFIG_CHECK_FAILED=""
|
|
|
|
export SNMP_CONFIG_CHECK_FAILED=""
|
2019-03-31 18:32:28 +02:00
|
|
|
export POSTFIX_CONFIG_CHECK_FAILED=""
|
2019-03-31 10:57:45 +02:00
|
|
|
export IPAM_CONFIG_CHECK_FAILED=""
|
2019-03-24 15:56:17 +01:00
|
|
|
|
|
|
|
usage() {
|
|
|
|
printf "Usage: ./recipe_gentoo.sh [--physical]\n"
|
|
|
|
printf "option : \t-P, --physical : if the current server is not a VM but a physical machine\n"
|
|
|
|
printf "option : \t-h, --help print this current message\n"
|
|
|
|
}
|
|
|
|
|
|
|
|
# Check parameters
|
|
|
|
if [ $1 ]; then
|
|
|
|
if [ $# -gt 1 ]; then
|
|
|
|
echo "ERROR : to much parameters (one MAX)"
|
|
|
|
usage
|
|
|
|
exit 0
|
|
|
|
# Print help
|
|
|
|
elif [ $1 = '-h' ] || [ $1 = '--help' ]; then
|
|
|
|
usage
|
|
|
|
exit 0
|
|
|
|
# Set boolean physical
|
|
|
|
elif [ $1 = '-P' ] || [ $1 = '--physical' ];then
|
|
|
|
PACKAGES+=(${PACKAGES_PHYSICAL[@]})
|
|
|
|
SERVICES_TO_CHECK+=(${SERVICES_TO_CHECK_PHYSICAL[@]})
|
|
|
|
# If unknown parameter
|
|
|
|
else
|
|
|
|
echo "ERROR : unknown parameter"
|
|
|
|
usage
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2019-05-01 17:16:58 +02:00
|
|
|
. recipes/common_functions.sh
|
|
|
|
|
|
|
|
print_config_title 'RECIPE GENTOO - CHECK BASIC CONFIG'
|
2019-03-24 15:56:17 +01:00
|
|
|
|
2019-03-29 20:16:50 +01:00
|
|
|
# Voir pour mettre ./ à la place de .
|
|
|
|
|
2019-03-31 10:57:45 +02:00
|
|
|
#. recipes/recipe_check_packages.sh
|
2019-03-24 15:56:17 +01:00
|
|
|
|
2019-05-01 17:16:58 +02:00
|
|
|
. recipes/recipe_check_hostname.sh
|
2019-03-24 15:56:17 +01:00
|
|
|
|
2019-03-31 10:57:45 +02:00
|
|
|
#. recipes/recipe_check_dns_config.sh
|
2019-03-24 15:56:17 +01:00
|
|
|
|
2019-03-31 10:57:45 +02:00
|
|
|
#. recipes/recipe_check_ping.sh
|
2019-03-24 15:56:17 +01:00
|
|
|
|
2019-03-31 10:57:45 +02:00
|
|
|
#. recipes/recipe_check_ip_admin.sh
|
2019-03-24 15:56:17 +01:00
|
|
|
|
2019-03-31 10:57:45 +02:00
|
|
|
#. recipes/recipe_check_services.sh
|
2019-03-24 15:56:17 +01:00
|
|
|
|
2019-05-01 17:16:58 +02:00
|
|
|
. recipes/recipe_check_ssh_config.sh
|
2019-03-24 15:56:17 +01:00
|
|
|
|
2019-03-31 10:57:45 +02:00
|
|
|
#. recipes/recipe_check_nrpe_config.sh
|
2019-03-24 15:56:17 +01:00
|
|
|
|
2019-03-31 10:57:45 +02:00
|
|
|
#. recipes/recipe_check_munin_config.sh
|
2019-03-24 15:56:17 +01:00
|
|
|
|
2019-03-31 10:57:45 +02:00
|
|
|
#. recipes/recipe_check_snmp_config.sh
|
2019-03-30 16:37:21 +01:00
|
|
|
|
2019-05-01 17:16:58 +02:00
|
|
|
#. recipes/recipe_check_mail_alias_config.sh
|
2019-03-24 15:56:17 +01:00
|
|
|
|
2019-05-01 17:16:58 +02:00
|
|
|
#. recipes/recipe_check_postfix_protocol_config.sh
|
2019-03-31 18:32:28 +02:00
|
|
|
|
2019-05-01 17:16:58 +02:00
|
|
|
#. recipes/recipe_check_ipam_config.sh
|
2019-03-31 10:57:45 +02:00
|
|
|
|
2019-03-24 15:56:17 +01:00
|
|
|
. recipes/recipe_final_summary.sh
|
|
|
|
|
|
|
|
exit 0
|