From 32d0fa6d62aed6d218191cccb4600085e9b8df07 Mon Sep 17 00:00:00 2001 From: GARDAIS Jeremy Date: Wed, 25 Apr 2018 16:03:23 +0200 Subject: [PATCH] Fix some type and printf --- install_backuppc_mac.sh | 62 ++++++++++++++++++++--------------------- 1 file changed, 30 insertions(+), 32 deletions(-) diff --git a/install_backuppc_mac.sh b/install_backuppc_mac.sh index 85705bf..9106e25 100755 --- a/install_backuppc_mac.sh +++ b/install_backuppc_mac.sh @@ -7,8 +7,8 @@ SUCCESS=0 ERROR=1 # Functions {{{ -## getDefaultUser {{{ -function getDefaultUser() { +## GetDefaultUser {{{ +function GetDefaultUser() { for user in $(ListUsers); do echo $user return @@ -16,9 +16,9 @@ function getDefaultUser() { } ## }}} -## allowUserToConnectToThisMachineUsingSsh {{{ +## AllowUserToConnectToThisMachineUsingSsh {{{ # this performs the equivalent as adding a remote login user in system preferences using the gui -function allowUserToConnectToThisMachineUsingSsh() +function AllowUserToConnectToThisMachineUsingSsh() { local userLogin="$1" #dscl . append '/Groups/com.apple.access_ssh' user "${userLogin}" @@ -27,19 +27,19 @@ function allowUserToConnectToThisMachineUsingSsh() } ## }}} -## ensurePingIsAllowed {{{ -function ensurePingIsAllowed() +## EnsurePingIsAllowed {{{ +function EnsurePingIsAllowed() { #sudo /usr/libexec/ApplicationFirewall/socketfilterfw --setstealthmode off printf '\e[1;31m%-6s\e[m\n' "DEBUG : Désactivation du mode furtif (ping)." if [ $? != 0 ]; then - printf '\e[1;31m%-6s\e[m' "La désactivation du mode furtif a échoué"; return "$ERROR" + printf '\e[1;31m%-6s\e[m\n' "ERREUR : La désactivation du mode furtif a échoué"; return "$ERROR" fi } ## }}} -## ensureSshdIsRunning {{{ -function ensureSshdIsRunning() +## EnsureSshdIsRunning {{{ +function EnsureSshdIsRunning() { #sudo launchctl list | grep 'com.openssh.sshd' &> /dev/null printf '\e[1;31m%-6s\e[m\n' "DEBUG : Vérification si sshd est déjà en cours." @@ -51,18 +51,19 @@ function ensureSshdIsRunning() #sudo launchctl list | grep 'com.openssh.sshd' &> /dev/null printf '\e[1;31m%-6s\e[m\n' "DEBUG : Activation du serveur ssh." if [ $? != 0 ]; then - printf '\e[1;31m%-6s\e[m' "L'activation du serveur ssh a échoué"; return "$ERROR" + printf '\e[1;31m%-6s\e[m\n' "ERREUR : L'activation du serveur ssh a échoué"; + return "$ERROR" fi } ## }}} -## getMyHostKey {{{ -function getMyHostKey() { +## GetMyHostKey {{{ +function GetMyHostKey() { hostkey="/etc/ssh_host_rsa_key.pub" if [ ! -f "${hostkey}" ]; then hostkey="/etc/ssh/ssh_host_rsa_key.pub" if [ ! -f "${hostkey}" ]; then - printf '\e[1;31m%-6s\e[m' "Impossible de trouver la clef ssh publique ce cette machine, SSH est-il bien installé?\n Installation annulée." + printf '\e[1;31m%-6s\e[m\n' "ERREUR : Impossible de trouver la clef ssh publique ce cette machine, SSH est-il bien installé?\n Installation annulée." return "$ERROR" fi fi @@ -137,7 +138,7 @@ function AddUserBackuppc() { #chown -R "$userLogin:$groupId" "$homeDir" printf '\e[1;31m%-6s\e[m\n' "DEBUG : chown -R $userLogin:$groupId $homeDir" - allowUserToConnectToThisMachineUsingSsh "${userLogin}" + AllowUserToConnectToThisMachineUsingSsh "${userLogin}" AllowBackuppcSudo } @@ -168,14 +169,13 @@ function AllowBackuppcSudo() { #### 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 " + printf '\e[1;31m%-6s\e[m\n' "ERREUR : À lancer avec les droits administrateur " exit fi #### NOM DU COMPTE À SAUVEGARDER #### -default_user=$(getDefaultUser) -printf '\e[1;34m%-6s\e[m' "liste des comptes détectés sur cette machine : $(ListUsers)" -printf "\n" +default_user=$(GetDefaultUser) +printf '\e[1;34m%-6s\e[m\n' "liste des comptes détectés sur cette machine : $(ListUsers)" printf "login de l’utilisateur dont les données sont à sauvegarder ?\n [${default_user}] : " read input_login if [[ ${input_login} != "" ]]; then @@ -186,10 +186,10 @@ fi #### VÉRIFIER QUE LE COMPTE EST BIEN DANS LA LISTE DES USER ID #### if ! id "${usr}" &> /dev/null; then - printf '\e[1;35m%-6s\e[m' "${usr} n’apparait pas dans la liste des user ids. Continuer tout de même ? [o/N] : " + printf '\e[1;35m%-6s\e[m\n' "${usr} n’apparait pas dans la liste des user ids. Continuer tout de même ? [o/N] : " read input_continue if [[ "${input_continue}" != "o" ]]; then - printf '\e[1;31m%-6s\e[m' "Installation annulée." + printf '\e[1;31m%-6s\e[m\n' "Installation annulée." exit fi fi @@ -210,8 +210,7 @@ fi #### DOSSIER À SAUVEGARDER INTROUVABLE, ANNULATION #### if [ ! -d "${dir1}" ]; then printf "\n" - printf '\e[1;31m%-6s\e[m' "Dossier ${dir1} introuvable, installation annulée." - printf "\n" + printf '\e[1;31m%-6s\e[m\n' "ERREUR : Dossier ${dir1} introuvable, installation annulée." exit fi @@ -222,8 +221,7 @@ if [[ "${input_dir2}" != "" ]]; then #### DOSSIER SUPPLÉMENTAIRE INTROUVABLE, ANNULATION DE CELUI-CI #### if [ ! -d "${input_dir2}" ]; then printf "\n" - printf '\e[1;35m%-6s\e[m' "Dossier supplémentaire introuvable, non ajouté." - printf "\n" + printf '\e[1;35m%-6s\e[m\n' "Dossier supplémentaire introuvable, non ajouté." else directories="'${dir1}','${input_dir2}'" fi @@ -232,17 +230,17 @@ else fi #### AUTORISER LE PING #### -ensurePingIsAllowed +EnsurePingIsAllowed #### INSTALLATION DE OPENSSH-SERVER #### -ensureSshdIsRunning +EnsureSshdIsRunning if [ "$?" != "$SUCCESS" ]; then - printf '\e[1;31m%-6s\e[m' "L'installation du serveur ssh a échoué, installation annulée."; exit + printf '\e[1;31m%-6s\e[m\n' "ERREUR : L'installation du serveur ssh a échoué, installation annulée."; exit fi -hostkey=$(getMyHostKey) +hostkey=$(GetMyHostKey) #printf "hostkey=$hostkey" if [ "$?" != "$SUCCESS" ]; then - printf '\e[1;31m%-6s\e[m' "Clé inaccessible, merci de contacter votre administrateur réseau, installation annulée."; exit + printf '\e[1;31m%-6s\e[m\n' "ERREUR : Clé inaccessible, merci de contacter votre administrateur réseau, installation annulée."; exit fi #### CRÉATION DU FICHIER DE CONFIGURATION #### @@ -253,8 +251,7 @@ echo "\$Conf{XferMethod} = 'rsync';" > "${filepl}" echo "\$Conf{RsyncShareName} = [${directories}];" >> "${filepl}" echo "\$Conf{BackupFilesExclude} = {'*' => ${exclude} };" >> "${filepl}" printf "\n" -printf '\e[1;34m%-6s\e[m' "Fichier de configuration serveur créé (${filepl})" -printf "\n" +printf '\e[1;34m%-6s\e[m\n' "Fichier de configuration créé (${filepl})" #### ADRESSE MAIL DE L’UTILISATEUR #### printf "Votre adresse e-mail ?\n : " @@ -292,5 +289,6 @@ printf '\e[1;31m%-6s\e[m\n' "DEBUG : chown -R backuppc ${homebackuppc}/.ssh/" printf "\n" printf '\e[1;34m%-6s\e[m\n' "Configuration du poste terminée." printf '\e[1;34m%-6s\e[m\n' "Envoyez bien votre fichier de configuration (${dir1}/${filepl}) à Jérémy GARDAIS (jeremy.gardai@univ-rennes1.fr)." -printf "\n" printf '\e[1;34m%-6s\e[m\n' "Vous pourrez affiner la configuration de votre sauvegarde depuis https://backuppc.ipr.univ-rennes1.fr" + +exit 0