From 134c18ff048da871f6a49ef66e033a899468c969 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gardais=20J=C3=A9r=C3=A9my?= Date: Mon, 6 May 2019 17:13:28 +0200 Subject: [PATCH] Create user for backuppc --- .../install_backuppc_windows_bash_on_linux.sh | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/client/install_backuppc_windows_bash_on_linux.sh b/client/install_backuppc_windows_bash_on_linux.sh index 888932c..efccad5 100755 --- a/client/install_backuppc_windows_bash_on_linux.sh +++ b/client/install_backuppc_windows_bash_on_linux.sh @@ -15,6 +15,10 @@ ## Valeur de fin SUCCESS=0 ERROR=1 + +backuppc_user="backuppc" +backuppc_homedir="/var/lib/backuppc" + ## Couleur {{{ BLACK='\033[49;30m' BLACKB='\033[49;90m' @@ -31,7 +35,17 @@ RESET='\033[0m' ## }}} # }}} # Fonctions {{{ - +function addUserForBackuppc() ## {{{ +{ + local userLogin="${1}" ### eg. 'backuppc' + local userHomedir="${2}" ### eg. '/var/lib/backuppc' + if ! getent passwd "${userLogin}" > /dev/null 2>&1; then + printf '%b\n' "${BOLD}L'utilisateur ${userLogin} n'existe pas, tentative de création.${RESET}\\n" + useradd --system --shell /bin/sh --home-dir "${userHomedir}/" --create-home -- "${userLogin}" + fi + chown -R -- "${userLogin}:" "${userHomedir}" +} +## }}} function ensureSshdIsInstalled() ## {{{ { ### `command -v sshd` still return old value even after openssh-server was removed @@ -64,6 +78,14 @@ apt install -y -- aptitude > /dev/null 2>&1 ## Mettre à jour le système aptitude full-upgrade -y --quiet=5 > /dev/null +# }}} +# Gestion de l'utilisateur pour BackupPC {{{ +addUserForBackuppc "${backuppc_user}" "${backuppc_homedir}" +if [ "$?" != "${SUCCESS}" ]; then + printf '%b' "${REDB}La création de l'utilisateur ${backuppc_user} a échouée, installation annulée.${RESET}\\n" + exit "${ERROR}" +fi + # }}} # Gestion de SSH {{{ ensureSshdIsInstalled