Increase the view of the vars in printf

This commit is contained in:
Jeremy Gardais 2018-04-26 15:00:38 +02:00
parent c21a895747
commit 725277623c
Signed by: jegardai
GPG Key ID: E759BAA22501AF32
1 changed files with 14 additions and 15 deletions

View File

@ -22,17 +22,17 @@ function AllowUserToConnectToThisMachineUsingSsh()
{ {
local userLogin local userLogin
userLogin="$1" userLogin="$1"
[[ "${DEBUG}" == "0" ]] && printf '\e[1;33m%-6s\e[m\n' "DEBUG: Autoriser les accès SSH pour l'utilisateur (${userLogin})."
dscl . append '/Groups/com.apple.access_ssh' user "${userLogin}" dscl . append '/Groups/com.apple.access_ssh' user "${userLogin}"
dscl . append /Groups/com.apple.access_ssh groupmembers $(dscl . read "/Users/${userLogin}" GeneratedUID | cut -d " " -f 2) dscl . append /Groups/com.apple.access_ssh groupmembers $(dscl . read "/Users/${userLogin}" GeneratedUID | cut -d " " -f 2)
[[ "${DEBUG}" == "0" ]] && printf '\e[1;33m%-6s\e[m\n' "DEBUG: Autoriser les accès SSH pour ${userLogin}."
} }
## }}} ## }}}
## EnsurePingIsAllowed {{{ ## EnsurePingIsAllowed {{{
function EnsurePingIsAllowed() function EnsurePingIsAllowed()
{ {
sudo /usr/libexec/ApplicationFirewall/socketfilterfw --setstealthmode off &> /dev/null
[[ "${DEBUG}" == "0" ]] && printf '\e[1;33m%-6s\e[m\n' "DEBUG: Désactivation du mode furtif (ping)." [[ "${DEBUG}" == "0" ]] && printf '\e[1;33m%-6s\e[m\n' "DEBUG: Désactivation du mode furtif (ping)."
sudo /usr/libexec/ApplicationFirewall/socketfilterfw --setstealthmode off &> /dev/null
if [ $? != 0 ]; then if [ $? != 0 ]; then
printf '\e[1;31m%-6s\e[m\n' "ERREUR: La désactivation du mode furtif a échoué" printf '\e[1;31m%-6s\e[m\n' "ERREUR: La désactivation du mode furtif a échoué"
return "$ERROR" return "$ERROR"
@ -43,15 +43,15 @@ function EnsurePingIsAllowed()
## EnsureSshdIsRunning {{{ ## EnsureSshdIsRunning {{{
function EnsureSshdIsRunning() function EnsureSshdIsRunning()
{ {
sudo launchctl list | grep 'com.openssh.sshd' &> /dev/null
[[ "${DEBUG}" == "0" ]] && printf '\e[1;33m%-6s\e[m\n' "DEBUG: Vérification si sshd est déjà en cours." [[ "${DEBUG}" == "0" ]] && printf '\e[1;33m%-6s\e[m\n' "DEBUG: Vérification si sshd est déjà en cours."
sudo launchctl list | grep 'com.openssh.sshd' &> /dev/null
if [ $? != 0 ]; then if [ $? != 0 ]; then
# enable 'Remote login' in 'system preferences' # enable 'Remote login' in 'system preferences'
sudo launchctl enable system/com.openssh.sshd &> /dev/null sudo launchctl enable system/com.openssh.sshd &> /dev/null
sudo launchctl load /System/Library/LaunchDaemons/ssh.plist &> /dev/null sudo launchctl load /System/Library/LaunchDaemons/ssh.plist &> /dev/null
fi fi
sudo launchctl list | grep 'com.openssh.sshd' &> /dev/null
[[ "${DEBUG}" == "0" ]] && printf '\e[1;33m%-6s\e[m\n' "DEBUG: Activation du serveur ssh." [[ "${DEBUG}" == "0" ]] && printf '\e[1;33m%-6s\e[m\n' "DEBUG: Activation du serveur ssh."
sudo launchctl list | grep 'com.openssh.sshd' &> /dev/null
if [ $? != 0 ]; then if [ $? != 0 ]; then
printf '\e[1;31m%-6s\e[m\n' "ERREUR: L'activation du serveur ssh a échoué"; printf '\e[1;31m%-6s\e[m\n' "ERREUR: L'activation du serveur ssh a échoué";
return "$ERROR" return "$ERROR"
@ -134,6 +134,7 @@ function AddUserBackuppc() {
fi fi
# Create user # Create user
[[ "${DEBUG}" == "0" ]] && printf '\e[1;33m%-6s\e[m\n' "DEBUG: Création de l'utilisateur ${userLogin}."
dscl . -create "/Users/$userLogin" dscl . -create "/Users/$userLogin"
dscl . -create "/Users/$userLogin" UserShell /bin/bash dscl . -create "/Users/$userLogin" UserShell /bin/bash
dscl . -create "/Users/$userLogin" RealName "backuppc" dscl . -create "/Users/$userLogin" RealName "backuppc"
@ -141,11 +142,10 @@ function AddUserBackuppc() {
dscl . -create "/Users/$userLogin" PrimaryGroupID "$groupId" dscl . -create "/Users/$userLogin" PrimaryGroupID "$groupId"
dscl . -create "/Users/$userLogin" NFSHomeDirectory "$homeDir" dscl . -create "/Users/$userLogin" NFSHomeDirectory "$homeDir"
dscl . -create "/Users/$userLogin" IsHidden 1 # hide from login window dscl . -create "/Users/$userLogin" IsHidden 1 # hide from login window
[[ "${DEBUG}" == "0" ]] && printf '\e[1;33m%-6s\e[m\n' "DEBUG: Création de l'utilisateur ${userLogin}."
# Homedir permissions # Homedir permissions
chown -R "$userLogin:$groupId" "$homeDir"
[[ "${DEBUG}" == "0" ]] && printf '\e[1;33m%-6s\e[m\n' "DEBUG: chown -R $userLogin:$groupId $homeDir" [[ "${DEBUG}" == "0" ]] && printf '\e[1;33m%-6s\e[m\n' "DEBUG: chown -R $userLogin:$groupId $homeDir"
chown -R "$userLogin:$groupId" "$homeDir"
AllowUserToConnectToThisMachineUsingSsh "${userLogin}" AllowUserToConnectToThisMachineUsingSsh "${userLogin}"
@ -163,8 +163,8 @@ function AllowBackuppcSudo() {
if [ ! "${sudoersDir}" == '' ]; then if [ ! "${sudoersDir}" == '' ]; then
printf '%b\n' "Configuration de sudo pour BackupPC." printf '%b\n' "Configuration de sudo pour BackupPC."
else else
[[ "${DEBUG}" == "0" ]] && printf '\e[1;33m%-6s\e[m\n' "DEBUG: Ajout du dossier sudoers (${sudoersDir}) dans la configuration sudo."
echo "#includedir /etc/sudoers.d" >> /etc/sudoers echo "#includedir /etc/sudoers.d" >> /etc/sudoers
[[ "${DEBUG}" == "0" ]] && printf '\e[1;33m%-6s\e[m\n' "DEBUG: Ajout de ${sudoersDir} dans le fichier sudoers."
fi fi
elif [ -f /private/etc/sudoers ]; then elif [ -f /private/etc/sudoers ]; then
sudoersDir=$(grep "^#includedir " /private/etc/sudoers | cut -d" " -f2) sudoersDir=$(grep "^#includedir " /private/etc/sudoers | cut -d" " -f2)
@ -172,7 +172,7 @@ function AllowBackuppcSudo() {
printf '%b\n' "Configuration de sudo pour BackupPC." printf '%b\n' "Configuration de sudo pour BackupPC."
else else
echo "#includedir /private/etc/sudoers.d" >> /private/etc/sudoers echo "#includedir /private/etc/sudoers.d" >> /private/etc/sudoers
[[ "${DEBUG}" == "0" ]] && printf '\e[1;33m%-6s\e[m\n' "DEBUG: Ajout de ${sudoersDir} dans le fichier sudoers." [[ "${DEBUG}" == "0" ]] && printf '\e[1;33m%-6s\e[m\n' "DEBUG: Ajout du dossier sudoers (${sudoersDir}) dans la configuration sudo."
fi fi
else else
printf '\e[1;31m%-6s\e[m\n' "ERREUR: Impossible de trouver un fichier de configuratio pour sudo." printf '\e[1;31m%-6s\e[m\n' "ERREUR: Impossible de trouver un fichier de configuratio pour sudo."
@ -181,12 +181,11 @@ function AllowBackuppcSudo() {
# Ensure to create the sudoers directory # Ensure to create the sudoers directory
sudo mkdir -p -- "${sudoersDir}" sudo mkdir -p -- "${sudoersDir}"
[[ "${DEBUG}" == "0" ]] && printf '\e[1;33m%-6s\e[m\n' "DEBUG: Création du dossier pour les sudoers ${sudoersDir}." [[ "${DEBUG}" == "0" ]] && printf '\e[1;33m%-6s\e[m\n' "DEBUG: Création du dossier pour les sudoers (${sudoersDir})."
# Allow backuppc user to use rsync with sudo # Allow backuppc user to use rsync with sudo
sudo sh -c "echo '${userLogin} ALL=(ALL:ALL) NOEXEC:NOPASSWD: /usr/bin/rsync' > ${sudoersDir}/backuppc_noexec" sudo sh -c "echo '${userLogin} ALL=(ALL:ALL) NOEXEC:NOPASSWD: /usr/bin/rsync' > ${sudoersDir}/backuppc_noexec"
[[ "${DEBUG}" == "0" ]] && printf '\e[1;33m%-6s\e[m\n' "DEBUG: ajout de '${userLogin} ALL=(ALL:ALL) NOEXEC:NOPASSWD: /usr/bin/rsync'" [[ "${DEBUG}" == "0" ]] && printf '\e[1;33m%-6s\e[m\n' "DEBUG: Ajout des autorisations sudo pour l'utilisateur (${userLogin}) dans le fichier (${sudoersDir}/backuppc_noexec)."
[[ "${DEBUG}" == "0" ]] && printf '\e[1;33m%-6s\e[m\n' "DEBUG: dans le fichier ${sudoersDir}/backuppc_noexec."
} }
## }}} ## }}}
# }}} # }}}
@ -313,12 +312,12 @@ mv -f -- "${filepl}" "${dir1}"
#### CRÉATION DE LUTILISATEUR BACKUPPC #### #### CRÉATION DE LUTILISATEUR BACKUPPC ####
[[ "${DEBUG}" == "0" ]] && printf '\e[1;35m%-6s\e[m\n' "DEBUG: Partie - Création du compte backuppc" [[ "${DEBUG}" == "0" ]] && printf '\e[1;35m%-6s\e[m\n' "DEBUG: Partie - Création du compte backuppc"
homebackuppc='/var/lib/backuppc' homebackuppc='/var/lib/backuppc'
[[ "${DEBUG}" == "0" ]] && printf '\e[1;33m%-6s\e[m\n' "DEBUG: Création de l'utilisateur backuppc (homebackuppc=${homebackuppc}) avec des droits sur l'utilisateur ${usr}." [[ "${DEBUG}" == "0" ]] && printf '\e[1;33m%-6s\e[m\n' "DEBUG: Création de l'utilisateur backuppc (homebackuppc=${homebackuppc}) avec des droits sur l'utilisateur (${usr})."
AddUserBackuppc "${input_login}" "${homebackuppc}" AddUserBackuppc "${usr}" "${homebackuppc}"
mkdir -p -- "${homebackuppc}"/.ssh mkdir -p -- "${homebackuppc}"/.ssh
[[ "${DEBUG}" == "0" ]] && printf '\e[1;33m%-6s\e[m\n' "DEBUG: Création du répertoire .ssh de l'utilisateur: ${homebackuppc}/.ssh" [[ "${DEBUG}" == "0" ]] && printf '\e[1;33m%-6s\e[m\n' "DEBUG: Création du répertoire .ssh de l'utilisateur backuppc (${homebackuppc}/.ssh)"
echo "from=\"129.20.203.16\" ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDIhMc8ixQXfWDACJy4q0v8T877UxahhCjO51PQFzylwVpf88LX3yWeDrWIW0NRu0zoSm396mig918OpD5ggqML/QbYbQsoDdAFUV/tK4JU6UJgEQIl25MOcUBCFepsFBGS09CH/V07xSUqSP/+beeTRLNO2CQzk3S2y3YfkXpM7KmOGfeLgoCaQAcxIkgLXeM3TpCZEzJDlZ8c8k/DjVvsgwCpQktYzNo2b37KHLLfgyW9KSo6N9sReUuNQjS6lu8rjrXfc6+J0pY2D6IxWptTWL/JVrhFCUqe4QQy+xYjoR41wqnAQyl/kOcyBNhSvojMKwQT6vlPwru6pOno16/X backuppc@backuppc.ipr.univ-rennes1.fr" > "${homebackuppc}"/.ssh/authorized_keys echo "from=\"129.20.203.16\" ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDIhMc8ixQXfWDACJy4q0v8T877UxahhCjO51PQFzylwVpf88LX3yWeDrWIW0NRu0zoSm396mig918OpD5ggqML/QbYbQsoDdAFUV/tK4JU6UJgEQIl25MOcUBCFepsFBGS09CH/V07xSUqSP/+beeTRLNO2CQzk3S2y3YfkXpM7KmOGfeLgoCaQAcxIkgLXeM3TpCZEzJDlZ8c8k/DjVvsgwCpQktYzNo2b37KHLLfgyW9KSo6N9sReUuNQjS6lu8rjrXfc6+J0pY2D6IxWptTWL/JVrhFCUqe4QQy+xYjoR41wqnAQyl/kOcyBNhSvojMKwQT6vlPwru6pOno16/X backuppc@backuppc.ipr.univ-rennes1.fr" > "${homebackuppc}"/.ssh/authorized_keys
[[ "${DEBUG}" == "0" ]] && printf '\e[1;33m%-6s\e[m\n' "DEBUG: Ajout de la clef SSH du serveur dans ${homebackuppc}/.ssh/authorized_keys" [[ "${DEBUG}" == "0" ]] && printf '\e[1;33m%-6s\e[m\n' "DEBUG: Ajout de la clef SSH du serveur dans (${homebackuppc}/.ssh/authorized_keys)."
chown -R backuppc "${homebackuppc}"/.ssh/ chown -R backuppc "${homebackuppc}"/.ssh/
[[ "${DEBUG}" == "0" ]] && printf '\e[1;33m%-6s\e[m\n' "DEBUG: chown -R backuppc ${homebackuppc}/.ssh/" [[ "${DEBUG}" == "0" ]] && printf '\e[1;33m%-6s\e[m\n' "DEBUG: chown -R backuppc ${homebackuppc}/.ssh/"