#!/bin/bash # Init : initialise une machine et la met en conformité # Copyright (c) 2021 Geoffray Levasseur export VERSION="0.95.1" # Stocke le chemin du script MYPATH=$(dirname $0) # Charge les bibliothèques for lib in $MYPATH/lib/*.sh; do . $lib done # Check if a function exists function_exists() { declare -f -F $1 > /dev/null return $? } function_exists prnt || ( echo "Il manque des fonctions vitales dans les bibliothèques !" exit 2 ) # Vérifie qu'on soit root if [[ $EUID -ne 0 ]]; prnt E "Ce script doit être démarré en tant que root. Arrêt." exit 1 fi # Variables globales importantes export HOSTNAME=$(hostname) export LOGFILE=${LOGFILE:-"$MYPATH/log/init-$(uname -n)-$(stdtime).log"} prnt I "Création du répertoire d'accueil du fichier log..." [[ ! -d $(dirname $LOGFILE) ]] && mkdir -pv $(dirname $LOGFILE) # Log toute les sortie dans le fichier de log exec 3>&1 4>&2 trap 'exec 2>&4 1>&3' 0 1 2 3 exec 1>$LOGFILE 2>&1 # Récupère la configuration prnt I "Chargement de la configuration..." if [[ -e $MYPATH/conf/$HOSTNAME.conf ]]; then prnt I "Une configuration spécifique sera utilisé." . $MYPATH/conf/$HOSTNAME.conf else prnt I "Une configuration générique sera utilisé." [[ -e $MYPATH/conf/init.conf.sh ]] && . $MYPATH/conf/init.conf.sh || ( prnt E "Aucune configuration trouvée, impossible de continuer." fi # Additionnal packages (some are necessary to that script to end successfully) install_pkg() { apt install -y $INSTLIST } # Profile install_profile() { installfile ansi_shadow.flf /usr/share/figlet/ansi_shadow.flf for usr in /root /home/*; do backupdist $usr/{,.}profile $usr/.bashrc installfile {{.,}profile,.bashrc} $usr/ done backupdist /etc/motd installfile motd /etc/motd } # Supervision patch_snmp() { backupdist /etc/snmp/snmpd.conf /etc/default/snmpd /lib/systemd/system/snmpd.service \ /etc/init.d/snmpd installfile snmpd.conf /etc/snmp/snmpd.conf installfile snmpd.init /etc/init.d/snmpd [[ -e /lib/systemd/system/snmpd.service ]] && installfile snmpd.service /lib/systemd/system/snmpd.service /etc/init.d/snmpd restart || true # error on systemd systems requiring reboot wich we'll do anyway after that script } install_mk-agent() { apt install -y $BASEGPDIR/mk_agents/check-mk-agent_${MKVERSION}_all.deb backupdist /etc/xinetd.d/check_mk installfile check_mk /etc/xinetd.d/check_mk /etc/init.d/xinetd restart } # Syslog conf_syslog() { backupdist /etc/rsyslog.conf installfile rsyslog.conf /etc/rsyslog.conf /etc/init.d/rsyslog restart } # Mail conf_mail() { installfile postfix.cf /etc/postfix/main.cf sed -i -e "s/#HOSTNAME#/$HOSTNAME/g" /etc/postfix/main.cf /etc/init.d/postfix restart } # ====================== # ==== Main Program ==== # ====================== upgrade_dist [[ ! $PVEHST ]] && install_ceph && conf_ceph [[ ! $PVEHST ]] && apt_blacklist #[[ ! $PVEHST ]] && authnz #[[ ! $PVEHST ]] && add_users conf_locale install_pkg conf_ntp conf_ssh install_profile patch_snmp install_mk-agent conf_syslog conf_mail echo "That's all folks !" echo "Après vérification des logs, il est recommandé de redémarrer la machine..."