diff --git a/init.sh b/init.sh index 85df625..99b42d9 100755 --- a/init.sh +++ b/init.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # ------------------------------------------------------------------------------ # Init.sh: initialise a computer and conform it # Copyright (c) 2019-2021 Geoffray Levasseur diff --git a/lib/aaa_errors.sh b/lib/aaa_errors.sh index 3909ed1..8050a7b 100644 --- a/lib/aaa_errors.sh +++ b/lib/aaa_errors.sh @@ -85,7 +85,9 @@ function backtrace # Test and exit if not root (or any UID 0 user) check_root() { - [[ $NO_ROOT_CHECK == true ]] && return 0 + if [[ $NO_ROOT_CHECK == true ]]; then + return 0 + fi if [[ $EUID -ne 0 ]]; then prnt E "Ce script doit être démarré en tant que root. Arrêt." die 4 --force diff --git a/lib/filefct.sh b/lib/filefct.sh index 9fcc108..ecbd8b7 100644 --- a/lib/filefct.sh +++ b/lib/filefct.sh @@ -23,9 +23,10 @@ export -f stdtime # (or any old files if runned several time on same file) backupdist() { - [[ $# -lt 1 ]] && - prnt E "backupdist(): At least one argument is required." && + if [[ $# -lt 1 ]]; then + prnt E "backupdist(): At least one argument is required." exit 11 + fi for file in $@; do if [[ -f ${file} ]]; then @@ -53,14 +54,14 @@ installfile() local filelist="" local i=0 - [[ $# -lt 2 ]] && ( + if [[ $# -lt 2 ]]; then prnt E "installfile(): At least two arguments are required." die 11 - ) - [[ $(echo $@ | grep "\*\|\?") ]] && ( + fi + if [[ $(echo $@ | grep "\*\|\?") ]]; then prnt E "installfile(): Wildcards are not authorized." die 7 - ) + fi for arg in $@; do if [[ -f $MYPATH/repo/hosts/$HOSTNAME/$arg ]]; then diff --git a/lib/pkgman.sh b/lib/pkgman.sh index f462f0d..8a44692 100644 --- a/lib/pkgman.sh +++ b/lib/pkgman.sh @@ -24,7 +24,10 @@ export -f pkgupdt pkginst() { prnt I "Installation de paquets..." - [[ $# -lt 1 ]] && prnt E "pkginst(): des paramètres sont requis." && exit 11 + if [[ $# -lt 1 ]]; then + prnt E "pkginst(): des paramètres sont requis." + exit 11 + fi if [[ ! $INSTALL_MODE == dev ]]; then $PKG_MAN $COM_INSTALL $@ else @@ -51,7 +54,10 @@ export -f pkgupgd pkgrem() { prnt I "Désinstallation de paquets..." - [[ $# -lt 1 ]] && prnt E "pkgrem(): des paramètres sont requis." && exit 11 + if [[ $# -lt 1 ]]; then + prnt E "pkgrem(): des paramètres sont requis." + exit 11 + fi if [[ ! $INSTALL_MODE == dev ]]; then $PKG_MAN $COM_REMOVE $@ else diff --git a/lib/services.sh b/lib/services.sh index 2450f41..19126ef 100644 --- a/lib/services.sh +++ b/lib/services.sh @@ -14,10 +14,10 @@ # Syntax exec_serv svcname command exec_serv() { - [[ $# -lt 2 ]] && ( + if [[ $# -lt 2 ]]; then prnt E "exec_serv(): Erreur de syntaxe !" exit 11 - ) + fi local svcname=$1 command=$2 shift 2 diff --git a/lib/support.sh b/lib/support.sh index 8e91033..e3969ec 100644 --- a/lib/support.sh +++ b/lib/support.sh @@ -76,8 +76,9 @@ show_version() local version=VER_$modname echo -e "\t$BWhite$modname${DEFAULTCOL}: $BGreen${!version}$DEFAULTCOL" done - [[ $EUID -ne 0 ]] && + if [[ $(id -u) -ne 0 ]]; then echo -e "\n${BYellow}Attention :$DEFAULTCOL Ce script requiert les droits d'administration pour fonctionner." + fi } diff --git a/lib/zzz_main_fct.sh b/lib/zzz_main_fct.sh index 5d01785..4c613dc 100644 --- a/lib/zzz_main_fct.sh +++ b/lib/zzz_main_fct.sh @@ -101,7 +101,8 @@ read_commandline() done # If those var are true at that point, something is wrong - if [[ $want_logfile == true ]] || [[ $want_module == true ]] || [[ $want_conffile == true ]]; then + if [[ $want_logfile == true ]] || [[ $want_module == true ]] || + [[ $want_conffile == true ]]; then syntax_error fi } @@ -149,28 +150,28 @@ process_commandline_and_vars() { # Check unconsistant parameters if [[ $CHECK_ONLY == true ]]; then - [[ $JUMP == true ]] && ( + if [[ $JUMP == true ]]; then prnt E "Les options --check-only et --jump s'excluent mutuellement !" die 1 --force - ) - [[ $KEEPGOING == true ]] && ( + fi + if [[ $KEEPGOING == true ]]; then prnt E "Les options --keep-going et --check-only sont incompatible !" die 1 --force - ) + fi fi if [[ $RESUME == true ]]; then - [[ $CHECK_ONLY == true ]] && ( + if [[ $CHECK_ONLY == true ]]; then prnt E "La reprise n'a pas de sens avec --check-only." die 1 --force - ) - [[ $MANUAL_MODULE_LIST ]] && ( + fi + if [[ $MANUAL_MODULE_LIST ]]; then prnt E "Le mode reprise ne fonctionne pas avec une liste de modules passé manuellement." die 1 --force - ) + fi fi # Configure module list - if [[ $MANUAL_MODULE_LIST ]]; then + if [[ -n $MANUAL_MODULE_LIST ]]; then prnt W "Une liste de modules manuelle sera utilisé." export MODULE_LIST=$(echo $MANUAL_MODULE_LIST | sed "s/,/ /g") fi diff --git a/mk_archive.sh b/mk_archive.sh index 55f66ce..bd77992 100755 --- a/mk_archive.sh +++ b/mk_archive.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # ------------------------------------------------------------------------------ # That script is used to create an archive for init.sh deployment # This file is part of the init.sh project diff --git a/modules/conf_mail.sh b/modules/conf_mail.sh index 2edb150..c991fa5 100644 --- a/modules/conf_mail.sh +++ b/modules/conf_mail.sh @@ -29,10 +29,10 @@ conf_mail() precheck_conf_mail() { - [[ -n $MAINDOM ]] && ( + if [[ -n $MAINDOM ]]; then prnt E "Aucun domaine principal renseigné." die 158 - ) + fi } export -f conf_mail diff --git a/modules/install_desktop.sh b/modules/install_desktop.sh index 0be24a4..5846ad5 100644 --- a/modules/install_desktop.sh +++ b/modules/install_desktop.sh @@ -19,12 +19,14 @@ export VER_install_desktop="0.0.2" install_desktop() { - [[ $X11_DRV ]] && - prnt I "Installation de pilotes supplémentaires X11..." && + if [[ -n $X11_DRV ]]; then + prnt I "Installation de pilotes supplémentaires X11..." pkginst $X11_DRV - [[ $UBUNTU_FLAVOR ]] && - prnt I "Installation de l'environnement $UBUNTU_FLAVOR..." && + fi + if [[ $UBUNTU_FLAVOR ]]; then + prnt I "Installation de l'environnement $UBUNTU_FLAVOR..." pkginst ${UBUNTU_FLAVOR}-desktop + fi } precheck_install_desktop() diff --git a/modules/install_mkagent.sh b/modules/install_mkagent.sh index 6d7b84d..c8e51ce 100644 --- a/modules/install_mkagent.sh +++ b/modules/install_mkagent.sh @@ -25,14 +25,14 @@ install_mkagent() precheck_install_mkagent() { - [[ -n $MKVERSION ]] && ( + if [[ -n $MKVERSION ]]; then prnt E "Undeclared check_mk version of the agent to install." die 162 - ) - [[ -n $MK_SERVER ]] && ( + fi + if [[ -n $MK_SERVER ]]; then prnt E "Undeclared check_mk server." die 162 - ) + fi } export -f install_mkagent diff --git a/modules/install_pkg.sh b/modules/install_pkg.sh index c3b0821..aecb492 100644 --- a/modules/install_pkg.sh +++ b/modules/install_pkg.sh @@ -18,9 +18,10 @@ export VER_install_pkg="0.1.1" install_pkg() { # Remove unnecessary packages - [[ -n $PKGS_RMLIST ]] && - prnt I "Suppression de paquets supperflus..." && + if [[ -n $PKGS_RMLIST ]]; then + prnt I "Suppression de paquets supperflus..." pkgrem $PKGS_RMLIST + fi # Blacklist some anoying packages (and remove them if needed) if [[ -n PKGS_BLACKLIST ]]; then @@ -36,10 +37,11 @@ install_pkg() fi # Install all the configured packages - [[ -n $PKGSEL ]] && - prnt I "Installation de la sélection de paquets..." && + if [[ -n $PKGSEL ]]; then + prnt I "Installation de la sélection de paquets..." pkginst $PKGSEL - + fi + # Cleaning prnt I "Suppression des paquets résiduels le cas échéant..." pkgautorem @@ -52,8 +54,11 @@ precheck_install_pkg() else prnt I "$(echo $PKGS_RMLIST | wc -w) paquets à supprimer." fi - [[ -z PKGS_BLACKLIST ]] && + + if [[ -z PKGS_BLACKLIST ]]; then prnt W "Les paquets $pkg seront placés en liste noire !" + fi + if [[ -z $PKGSEL ]]; then prnt W "Pas de paquet additionel à installer !" else diff --git a/modules/patch_snmp.sh b/modules/patch_snmp.sh index e13d24c..c6c4f2a 100644 --- a/modules/patch_snmp.sh +++ b/modules/patch_snmp.sh @@ -16,9 +16,10 @@ patch_snmp() /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 && + if [[ -e /lib/systemd/system/snmpd.service ]]; then + installfile snmpd.service /lib/systemd/system/snmpd.service systemctl daemon-reload + fi svc_restart snmpd }