Ensure to install sshd

This commit is contained in:
Jeremy Gardais 2019-05-06 15:29:02 +02:00
parent 13e44b6661
commit 72e0dfed86
Signed by: jegardai
GPG Key ID: E759BAA22501AF32
1 changed files with 30 additions and 0 deletions

View File

@ -14,6 +14,29 @@
SUCCESS=0
ERROR=1
# Fonctions {{{
function ensureSshdIsInstalled() ## {{{
{
### `command -v sshd` still return old value even after openssh-server was removed
### So we can't be sure of openssh-server state.
if ! hash sshd 2>/dev/null; then
printf '%b\n' "openssh-server non installé, tentative d'installation."
if [ $(command -v aptitude) ]; then aptitude install -y openssh-server
elif [ $(command -v apt) ]; then apt install -y openssh-server
elif [ $(command -v yum) ]; then yum install -y openssh-server
elif [ $(command -v zypper) ]; then zypper install -y openssh-server
else
printf '\e[1;31m%-6s\e[m' "Merci dinstaller openssh-server sur votre machine, installation annulée."
return "$ERROR"
fi
fi
}
## }}}
# }}}
# Gestion des paquets {{{
## Mettre à jour les dépôts
apt update
@ -26,5 +49,12 @@ apt install -y aptitude
## Mettre à jour le système
aptitude full-upgrade -y
# }}}
# Gestion de SSH {{{
ensureSshdIsInstalled
if [ "$?" != "${SUCCESS}" ]; then
printf '\e[1;31m%-6s\e[m' "L'installation du serveur ssh a échoué, installation annulée."
exit "${ERROR}"
fi
# }}}
exit "${SUCCESS}"