removed [[ TEST ]] && action form for if [[ TEST ]]; then action; fi for compatibility

This commit is contained in:
levasseur
2021-09-08 17:52:16 +02:00
parent bec63a5304
commit d8c1dfddd6
13 changed files with 61 additions and 42 deletions

View File

@@ -1,4 +1,4 @@
#!/bin/bash #!/usr/bin/env bash
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Init.sh: initialise a computer and conform it # Init.sh: initialise a computer and conform it
# Copyright (c) 2019-2021 Geoffray Levasseur <fatalerrors@geoffray-levasseur.org> # Copyright (c) 2019-2021 Geoffray Levasseur <fatalerrors@geoffray-levasseur.org>

View File

@@ -85,7 +85,9 @@ function backtrace
# Test and exit if not root (or any UID 0 user) # Test and exit if not root (or any UID 0 user)
check_root() check_root()
{ {
[[ $NO_ROOT_CHECK == true ]] && return 0 if [[ $NO_ROOT_CHECK == true ]]; then
return 0
fi
if [[ $EUID -ne 0 ]]; then if [[ $EUID -ne 0 ]]; then
prnt E "Ce script doit être démarré en tant que root. Arrêt." prnt E "Ce script doit être démarré en tant que root. Arrêt."
die 4 --force die 4 --force

View File

@@ -23,9 +23,10 @@ export -f stdtime
# (or any old files if runned several time on same file) # (or any old files if runned several time on same file)
backupdist() backupdist()
{ {
[[ $# -lt 1 ]] && if [[ $# -lt 1 ]]; then
prnt E "backupdist(): At least one argument is required." && prnt E "backupdist(): At least one argument is required."
exit 11 exit 11
fi
for file in $@; do for file in $@; do
if [[ -f ${file} ]]; then if [[ -f ${file} ]]; then
@@ -53,14 +54,14 @@ installfile()
local filelist="" local filelist=""
local i=0 local i=0
[[ $# -lt 2 ]] && ( if [[ $# -lt 2 ]]; then
prnt E "installfile(): At least two arguments are required." prnt E "installfile(): At least two arguments are required."
die 11 die 11
) fi
[[ $(echo $@ | grep "\*\|\?") ]] && ( if [[ $(echo $@ | grep "\*\|\?") ]]; then
prnt E "installfile(): Wildcards are not authorized." prnt E "installfile(): Wildcards are not authorized."
die 7 die 7
) fi
for arg in $@; do for arg in $@; do
if [[ -f $MYPATH/repo/hosts/$HOSTNAME/$arg ]]; then if [[ -f $MYPATH/repo/hosts/$HOSTNAME/$arg ]]; then

View File

@@ -24,7 +24,10 @@ export -f pkgupdt
pkginst() pkginst()
{ {
prnt I "Installation de paquets..." 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 if [[ ! $INSTALL_MODE == dev ]]; then
$PKG_MAN $COM_INSTALL $@ $PKG_MAN $COM_INSTALL $@
else else
@@ -51,7 +54,10 @@ export -f pkgupgd
pkgrem() pkgrem()
{ {
prnt I "Désinstallation de paquets..." 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 if [[ ! $INSTALL_MODE == dev ]]; then
$PKG_MAN $COM_REMOVE $@ $PKG_MAN $COM_REMOVE $@
else else

View File

@@ -14,10 +14,10 @@
# Syntax exec_serv svcname command # Syntax exec_serv svcname command
exec_serv() exec_serv()
{ {
[[ $# -lt 2 ]] && ( if [[ $# -lt 2 ]]; then
prnt E "exec_serv(): Erreur de syntaxe !" prnt E "exec_serv(): Erreur de syntaxe !"
exit 11 exit 11
) fi
local svcname=$1 command=$2 local svcname=$1 command=$2
shift 2 shift 2

View File

@@ -76,8 +76,9 @@ show_version()
local version=VER_$modname local version=VER_$modname
echo -e "\t$BWhite$modname${DEFAULTCOL}: $BGreen${!version}$DEFAULTCOL" echo -e "\t$BWhite$modname${DEFAULTCOL}: $BGreen${!version}$DEFAULTCOL"
done 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." echo -e "\n${BYellow}Attention :$DEFAULTCOL Ce script requiert les droits d'administration pour fonctionner."
fi
} }

View File

@@ -101,7 +101,8 @@ read_commandline()
done done
# If those var are true at that point, something is wrong # 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 syntax_error
fi fi
} }
@@ -149,28 +150,28 @@ process_commandline_and_vars()
{ {
# Check unconsistant parameters # Check unconsistant parameters
if [[ $CHECK_ONLY == true ]]; then if [[ $CHECK_ONLY == true ]]; then
[[ $JUMP == true ]] && ( if [[ $JUMP == true ]]; then
prnt E "Les options --check-only et --jump s'excluent mutuellement !" prnt E "Les options --check-only et --jump s'excluent mutuellement !"
die 1 --force die 1 --force
) fi
[[ $KEEPGOING == true ]] && ( if [[ $KEEPGOING == true ]]; then
prnt E "Les options --keep-going et --check-only sont incompatible !" prnt E "Les options --keep-going et --check-only sont incompatible !"
die 1 --force die 1 --force
) fi
fi fi
if [[ $RESUME == true ]]; then if [[ $RESUME == true ]]; then
[[ $CHECK_ONLY == true ]] && ( if [[ $CHECK_ONLY == true ]]; then
prnt E "La reprise n'a pas de sens avec --check-only." prnt E "La reprise n'a pas de sens avec --check-only."
die 1 --force die 1 --force
) fi
[[ $MANUAL_MODULE_LIST ]] && ( if [[ $MANUAL_MODULE_LIST ]]; then
prnt E "Le mode reprise ne fonctionne pas avec une liste de modules passé manuellement." prnt E "Le mode reprise ne fonctionne pas avec une liste de modules passé manuellement."
die 1 --force die 1 --force
) fi
fi fi
# Configure module list # Configure module list
if [[ $MANUAL_MODULE_LIST ]]; then if [[ -n $MANUAL_MODULE_LIST ]]; then
prnt W "Une liste de modules manuelle sera utilisé." prnt W "Une liste de modules manuelle sera utilisé."
export MODULE_LIST=$(echo $MANUAL_MODULE_LIST | sed "s/,/ /g") export MODULE_LIST=$(echo $MANUAL_MODULE_LIST | sed "s/,/ /g")
fi fi

View File

@@ -1,4 +1,4 @@
#!/bin/bash #!/usr/bin/env bash
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# That script is used to create an archive for init.sh deployment # That script is used to create an archive for init.sh deployment
# This file is part of the init.sh project # This file is part of the init.sh project

View File

@@ -29,10 +29,10 @@ conf_mail()
precheck_conf_mail() precheck_conf_mail()
{ {
[[ -n $MAINDOM ]] && ( if [[ -n $MAINDOM ]]; then
prnt E "Aucun domaine principal renseigné." prnt E "Aucun domaine principal renseigné."
die 158 die 158
) fi
} }
export -f conf_mail export -f conf_mail

View File

@@ -19,12 +19,14 @@ export VER_install_desktop="0.0.2"
install_desktop() install_desktop()
{ {
[[ $X11_DRV ]] && if [[ -n $X11_DRV ]]; then
prnt I "Installation de pilotes supplémentaires X11..." && prnt I "Installation de pilotes supplémentaires X11..."
pkginst $X11_DRV pkginst $X11_DRV
[[ $UBUNTU_FLAVOR ]] && fi
prnt I "Installation de l'environnement $UBUNTU_FLAVOR..." && if [[ $UBUNTU_FLAVOR ]]; then
prnt I "Installation de l'environnement $UBUNTU_FLAVOR..."
pkginst ${UBUNTU_FLAVOR}-desktop pkginst ${UBUNTU_FLAVOR}-desktop
fi
} }
precheck_install_desktop() precheck_install_desktop()

View File

@@ -25,14 +25,14 @@ install_mkagent()
precheck_install_mkagent() precheck_install_mkagent()
{ {
[[ -n $MKVERSION ]] && ( if [[ -n $MKVERSION ]]; then
prnt E "Undeclared check_mk version of the agent to install." prnt E "Undeclared check_mk version of the agent to install."
die 162 die 162
) fi
[[ -n $MK_SERVER ]] && ( if [[ -n $MK_SERVER ]]; then
prnt E "Undeclared check_mk server." prnt E "Undeclared check_mk server."
die 162 die 162
) fi
} }
export -f install_mkagent export -f install_mkagent

View File

@@ -18,9 +18,10 @@ export VER_install_pkg="0.1.1"
install_pkg() install_pkg()
{ {
# Remove unnecessary packages # Remove unnecessary packages
[[ -n $PKGS_RMLIST ]] && if [[ -n $PKGS_RMLIST ]]; then
prnt I "Suppression de paquets supperflus..." && prnt I "Suppression de paquets supperflus..."
pkgrem $PKGS_RMLIST pkgrem $PKGS_RMLIST
fi
# Blacklist some anoying packages (and remove them if needed) # Blacklist some anoying packages (and remove them if needed)
if [[ -n PKGS_BLACKLIST ]]; then if [[ -n PKGS_BLACKLIST ]]; then
@@ -36,10 +37,11 @@ install_pkg()
fi fi
# Install all the configured packages # Install all the configured packages
[[ -n $PKGSEL ]] && if [[ -n $PKGSEL ]]; then
prnt I "Installation de la sélection de paquets..." && prnt I "Installation de la sélection de paquets..."
pkginst $PKGSEL pkginst $PKGSEL
fi
# Cleaning # Cleaning
prnt I "Suppression des paquets résiduels le cas échéant..." prnt I "Suppression des paquets résiduels le cas échéant..."
pkgautorem pkgautorem
@@ -52,8 +54,11 @@ precheck_install_pkg()
else else
prnt I "$(echo $PKGS_RMLIST | wc -w) paquets à supprimer." prnt I "$(echo $PKGS_RMLIST | wc -w) paquets à supprimer."
fi fi
[[ -z PKGS_BLACKLIST ]] &&
if [[ -z PKGS_BLACKLIST ]]; then
prnt W "Les paquets $pkg seront placés en liste noire !" prnt W "Les paquets $pkg seront placés en liste noire !"
fi
if [[ -z $PKGSEL ]]; then if [[ -z $PKGSEL ]]; then
prnt W "Pas de paquet additionel à installer !" prnt W "Pas de paquet additionel à installer !"
else else

View File

@@ -16,9 +16,10 @@ patch_snmp()
/lib/systemd/system/snmpd.service /etc/init.d/snmpd /lib/systemd/system/snmpd.service /etc/init.d/snmpd
installfile snmpd.conf /etc/snmp/snmpd.conf installfile snmpd.conf /etc/snmp/snmpd.conf
installfile snmpd.init /etc/init.d/snmpd installfile snmpd.init /etc/init.d/snmpd
[[ -e /lib/systemd/system/snmpd.service ]] && if [[ -e /lib/systemd/system/snmpd.service ]]; then
installfile snmpd.service /lib/systemd/system/snmpd.service && installfile snmpd.service /lib/systemd/system/snmpd.service
systemctl daemon-reload systemctl daemon-reload
fi
svc_restart snmpd svc_restart snmpd
} }