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
# 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)
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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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
}

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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()

View File

@@ -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

View File

@@ -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

View File

@@ -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
}