From febfa4ecc47dc75b2c496a74b14c33103fc05b10 Mon Sep 17 00:00:00 2001 From: GARDAIS Jeremy Date: Wed, 25 Apr 2018 15:31:14 +0200 Subject: [PATCH] Add functions for backuppc user Create the user. Allow the backuppc user to use rsync with sudo without password. --- install_backuppc_mac.sh | 57 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/install_backuppc_mac.sh b/install_backuppc_mac.sh index aee529b..5c37519 100755 --- a/install_backuppc_mac.sh +++ b/install_backuppc_mac.sh @@ -94,6 +94,63 @@ function ListUsers() { echo $users } +# AddUserBackuppc {{{ +function AddUserBackuppc() { + local userToBackup="$1" # the login of the user to backup + local homeDir="$2" # par exemple '/var/lib/backuppc' + local userLogin='backuppc' + local groupId=$(id -g $userToBackup) + maxid=$(dscl . -list /Users UniqueID | awk '$2 < 1000 {print $2}' | sort -ug | tail -1) + newid=$((maxid+1)) + mkdir -p "$homeDir" + id "$newid" &> /dev/null + if [ $? = 0 ]; then + echo "unable to find a suitable uid for user backuppc ($newid is already used)" + exit $ERROR + fi + + # Create user + #dscl . -create "/Users/$userLogin" + #dscl . -create "/Users/$userLogin" UserShell /bin/bash + #dscl . -create "/Users/$userLogin" RealName "backuppc" + #dscl . -create "/Users/$userLogin" UniqueID "$newid" + #dscl . -create "/Users/$userLogin" PrimaryGroupID "$groupId" + #dscl . -create "/Users/$userLogin" NFSHomeDirectory "$homeDir" + #dscl . -create "/Users/$userLogin" IsHidden 1 # hide from login window + printf '\e[1;31m%-6s\e[m\n' "DEBUG : Création de l'utilisateur ${userLogin}." + + # Homedir permissions + #chown -R "$userLogin:$groupId" "$homeDir" + printf '\e[1;31m%-6s\e[m\n' "DEBUG : chown -R $userLogin:$groupId $homeDir" + + allowUserToConnectToThisMachineUsingSsh "${userLogin}" + + AllowBackuppcSudo +} +# }}} + +# AllowBackuppcSudo {{{ +function AllowBackuppcSudo() { + # Get the configuration directory for sudoers + if [ -f /etc/sudoers ]; then + local sudoersDir=$(grep "^#includedir " /etc/sudoers | cut -d" " -f2) + elif [ -f /private/etc/sudoers ]; then + local sudoersDir=$(grep "^#includedir " /private/etc/sudoers | cut -d" " -f2) + else + printf '\e[1;31m%-6s\e[m\n' "Unable to find sudo configuration file." + return "$ERROR" + fi + + #sudo mkdir -p -- "${sudoersDir}" + printf '\e[1;31m%-6s\e[m\n' "DEBUG : Création du dossier ${sudoersDir}." + + # Allow user to use rsync with sudo + #sudo sh -c "echo '${userLogin} ALL=(ALL:ALL) NOEXEC:NOPASSWD: /usr/bin/rsync' > ${sudoersDir}/backuppc_noexec" + printf '\e[1;31m%-6s\e[m\n' "DEBUG : ajout de '${userLogin} ALL=(ALL:ALL) NOEXEC:NOPASSWD: /usr/bin/rsync'" + printf '\e[1;31m%-6s\e[m\n' "DEBUG : dans le fichier ${sudoersDir}/backuppc_noexec." +} +# }}} + #### VÉRIFIER QUE L’ON A BIEN LES DROITS ADMIN #### if [ "$EUID" -ne 0 ]; then printf '\e[1;31m%-6s\e[m' "À lancer avec les droits administrateur "