Add a tested DEBUG var before print debug messages
This commit is contained in:
		
							parent
							
								
									049f47910f
								
							
						
					
					
						commit
						5a7c3ff5a2
					
				|  | @ -23,7 +23,7 @@ function AllowUserToConnectToThisMachineUsingSsh() | |||
| 	local userLogin="$1" | ||||
| 	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) | ||||
| 	printf '\e[1;33m%-6s\e[m\n' "DEBUG : Autoriser les accès SSH pour ${userLogin}." | ||||
| [[ "${DEBUG}" == "0" ]] && 	printf '\e[1;33m%-6s\e[m\n' "DEBUG : Autoriser les accès SSH pour ${userLogin}." | ||||
| } | ||||
| ## }}} | ||||
| 
 | ||||
|  | @ -31,7 +31,7 @@ function AllowUserToConnectToThisMachineUsingSsh() | |||
| function EnsurePingIsAllowed() | ||||
| { | ||||
| 	sudo /usr/libexec/ApplicationFirewall/socketfilterfw --setstealthmode off | ||||
| 	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)." | ||||
| 	if [ $? != 0 ]; then | ||||
| 		printf '\e[1;31m%-6s\e[m\n' "ERREUR : La désactivation du mode furtif a échoué" | ||||
| 		return "$ERROR" | ||||
|  | @ -43,14 +43,14 @@ function EnsurePingIsAllowed() | |||
| function EnsureSshdIsRunning() | ||||
| { | ||||
| 	sudo launchctl list | grep 'com.openssh.sshd' &> /dev/null | ||||
| 	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." | ||||
| 	if [ $? != 0 ]; then | ||||
| 		# enable 'Remote login' in 'system preferences' | ||||
| 		sudo launchctl enable system/com.openssh.sshd &> /dev/null | ||||
| 		sudo launchctl load /System/Library/LaunchDaemons/ssh.plist &> /dev/null | ||||
| 	fi | ||||
| 	sudo launchctl list | grep 'com.openssh.sshd' &> /dev/null | ||||
| 	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." | ||||
| 	if [ $? != 0 ]; then | ||||
| 		printf '\e[1;31m%-6s\e[m\n' "ERREUR : L'activation du serveur ssh a échoué"; | ||||
| 		return "$ERROR" | ||||
|  | @ -132,11 +132,11 @@ function AddUserBackuppc() { | |||
| 	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;33m%-6s\e[m\n' "DEBUG : Création de l'utilisateur ${userLogin}." | ||||
| [[ "${DEBUG}" == "0" ]] && 	printf '\e[1;33m%-6s\e[m\n' "DEBUG : Création de l'utilisateur ${userLogin}." | ||||
| 
 | ||||
| 	# Homedir permissions | ||||
| 	chown -R "$userLogin:$groupId" "$homeDir" | ||||
| 	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" | ||||
| 
 | ||||
| 	AllowUserToConnectToThisMachineUsingSsh "${userLogin}" | ||||
| 
 | ||||
|  | @ -154,7 +154,7 @@ function AllowBackuppcSudo() { | |||
| 			printf "%b\n" "Configuration de sudo pour BackupPC." | ||||
| 		else | ||||
| 				echo "#includedir /etc/sudoers.d" >> /etc/sudoers | ||||
| 				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 de ${sudoersDir} dans le fichier sudoers." | ||||
| 		fi | ||||
| 	elif [ -f /private/etc/sudoers ]; then | ||||
| 		local sudoersDir=$(grep "^#includedir " /private/etc/sudoers | cut -d" " -f2) | ||||
|  | @ -162,7 +162,7 @@ function AllowBackuppcSudo() { | |||
| 			printf "%b\n" "Configuration de sudo pour BackupPC." | ||||
| 		else | ||||
| 			echo "#includedir /private/etc/sudoers.d" >> /private/etc/sudoers | ||||
| 			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 de ${sudoersDir} dans le fichier sudoers." | ||||
| 		fi | ||||
| 	else | ||||
| 		printf '\e[1;31m%-6s\e[m\n' "ERREUR : Impossible de trouver un fichier de configuratio pour sudo." | ||||
|  | @ -171,25 +171,25 @@ function AllowBackuppcSudo() { | |||
| 
 | ||||
| # Ensure to create the sudoers directory | ||||
| 	sudo mkdir -p -- "${sudoersDir}" | ||||
| 	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 | ||||
| 	sudo sh -c "echo '${userLogin} ALL=(ALL:ALL)  NOEXEC:NOPASSWD: /usr/bin/rsync' > ${sudoersDir}/backuppc_noexec" | ||||
| 	printf '\e[1;33m%-6s\e[m\n' "DEBUG : ajout de '${userLogin} ALL=(ALL:ALL)  NOEXEC:NOPASSWD: /usr/bin/rsync'" | ||||
| 	printf '\e[1;33m%-6s\e[m\n' "DEBUG : dans le fichier ${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 : dans le fichier ${sudoersDir}/backuppc_noexec." | ||||
| } | ||||
| ## }}} | ||||
| # }}} | ||||
| 
 | ||||
| #### VÉRIFIER QUE L’ON A BIEN LES DROITS ADMIN #### | ||||
| printf '\e[1;35m%-6s\e[m\n' "DEBUG : Partie - Vérification des droits admin" | ||||
| [[ "${DEBUG}" == "0" ]] && printf '\e[1;35m%-6s\e[m\n' "DEBUG : Partie - Vérification des droits admin" | ||||
| if [ "$EUID" -ne 0 ]; then | ||||
| 	printf '\e[1;31m%-6s\e[m\n' "ERREUR : À lancer avec les droits administrateur " | ||||
| 	exit | ||||
| fi | ||||
| 
 | ||||
| #### NOM DU COMPTE À SAUVEGARDER #### | ||||
| printf '\e[1;35m%-6s\e[m\n' "DEBUG : Partie - Nom du compte à sauvegarder" | ||||
| [[ "${DEBUG}" == "0" ]] && printf '\e[1;35m%-6s\e[m\n' "DEBUG : Partie - Nom du compte à sauvegarder" | ||||
| default_user=$(GetDefaultUser) | ||||
| printf "%b\n" "Liste des comptes détectés sur cette machine : $(ListUsers)" | ||||
| printf '\e[1;34m%-6s\e[m' "Login de l’utilisateur dont les données sont à sauvegarder ? [${default_user}] : " | ||||
|  | @ -201,7 +201,7 @@ else | |||
| fi | ||||
| 
 | ||||
| #### VÉRIFIER QUE LE COMPTE EST BIEN DANS LA LISTE DES USER ID #### | ||||
| printf '\e[1;35m%-6s\e[m\n' "DEBUG : Partie - Vérification du compte" | ||||
| [[ "${DEBUG}" == "0" ]] && printf '\e[1;35m%-6s\e[m\n' "DEBUG : Partie - Vérification du compte" | ||||
| if ! id "${usr}" &> /dev/null; then | ||||
| 	printf '\e[1;34m%-6s\e[m' "${usr} n’apparait pas dans la liste des user ids. Continuer tout de même ? [o/N] : " | ||||
| 	read input_continue | ||||
|  | @ -212,7 +212,7 @@ if ! id "${usr}" &> /dev/null; then | |||
| fi | ||||
| 
 | ||||
| #### DOSSIER À SAUVEGARDER #### | ||||
| printf '\e[1;35m%-6s\e[m\n' "DEBUG : Partie - Dossier à sauvegarder" | ||||
| [[ "${DEBUG}" == "0" ]] && printf '\e[1;35m%-6s\e[m\n' "DEBUG : Partie - Dossier à sauvegarder" | ||||
| default_dir=$(eval echo ~"${usr}") | ||||
| if [ ! -d "${default_dir}" ]; then | ||||
| 	default_dir="" | ||||
|  | @ -228,13 +228,13 @@ fi | |||
| 
 | ||||
| #### DOSSIER À SAUVEGARDER INTROUVABLE, ANNULATION #### | ||||
| if [ ! -d "${dir1}" ]; then | ||||
| printf '\e[1;35m%-6s\e[m\n' "DEBUG : Partie - Dossier introuvable" | ||||
| [[ "${DEBUG}" == "0" ]] && printf '\e[1;35m%-6s\e[m\n' "DEBUG : Partie - Dossier introuvable" | ||||
| 	printf '\e[1;31m%-6s\e[m\n' "ERREUR : Dossier ${dir1} introuvable, installation annulée." | ||||
| 	exit | ||||
| fi | ||||
| 
 | ||||
| #### DOSSIER SUPPLÉMENTAIRE #### | ||||
| printf '\e[1;35m%-6s\e[m\n' "DEBUG : Partie - Dossier supplémentaire" | ||||
| [[ "${DEBUG}" == "0" ]] && printf '\e[1;35m%-6s\e[m\n' "DEBUG : Partie - Dossier supplémentaire" | ||||
| printf '\e[1;34m%-6s\e[m' "Si vous avez un dossier supplémentaire à sauvegarder (/mnt/data par exemple) entrer-le maintenant, sinon laissez vide. [] : " | ||||
| read input_dir2 | ||||
| if [[ "${input_dir2}" != "" ]]; then | ||||
|  | @ -250,11 +250,11 @@ else | |||
| fi | ||||
| 
 | ||||
| #### AUTORISER LE PING #### | ||||
| printf '\e[1;35m%-6s\e[m\n' "DEBUG : Partie - Configuration du poste" | ||||
| [[ "${DEBUG}" == "0" ]] && printf '\e[1;35m%-6s\e[m\n' "DEBUG : Partie - Configuration du poste" | ||||
| EnsurePingIsAllowed | ||||
| 
 | ||||
| #### INSTALLATION DE OPENSSH-SERVER #### | ||||
| printf '\e[1;35m%-6s\e[m\n' "DEBUG : Partie - Installation de Openssh-server" | ||||
| [[ "${DEBUG}" == "0" ]] && printf '\e[1;35m%-6s\e[m\n' "DEBUG : Partie - Installation de Openssh-server" | ||||
| EnsureSshdIsRunning | ||||
| if [ "$?" != "$SUCCESS" ]; then | ||||
| 	printf '\e[1;31m%-6s\e[m\n' "ERREUR : L'installation du serveur ssh a échoué, installation annulée." | ||||
|  | @ -268,14 +268,14 @@ if [ "$?" != "$SUCCESS" ]; then | |||
| fi | ||||
| 
 | ||||
| #### CRÉATION DU FICHIER DE CONFIGURATION #### | ||||
| printf '\e[1;35m%-6s\e[m\n' "DEBUG : Partie - Création du fichier de configuration" | ||||
| [[ "${DEBUG}" == "0" ]] && printf '\e[1;35m%-6s\e[m\n' "DEBUG : Partie - Création du fichier de configuration" | ||||
| fqdn="$(MyFqdn)" | ||||
| filepl="${fqdn}.pl" | ||||
| exclude="['ownCloud','.local/share/Trash','.cache','.Play*','.steam','.wine','Perso','temp','tmp','.Trash*','.DS_Store','._*', '.thumbnails','.ssh/id_*','.xsession-*']" | ||||
| echo "\$Conf{XferMethod} = 'rsync';" > "${filepl}" | ||||
| echo "\$Conf{RsyncShareName} = [${directories}];" >> "${filepl}" | ||||
| echo "\$Conf{BackupFilesExclude} = {'*' => ${exclude} };" >> "${filepl}" | ||||
| printf '\e[1;33m%-6s\e[m\n' "DEBUG : Fichier de configuration créé (${filepl})" | ||||
| [[ "${DEBUG}" == "0" ]] && printf '\e[1;33m%-6s\e[m\n' "DEBUG : Fichier de configuration créé (${filepl})" | ||||
| 
 | ||||
| #### LE SERVEUR DOIT CONNAITRE #### | ||||
| # Les commandes à exécuter avec sudo | ||||
|  | @ -283,7 +283,7 @@ printf '\e[1;33m%-6s\e[m\n' "DEBUG : Fichier de configuration créé (${filepl | |||
| # L’ADRESSE MAIL | ||||
| # L'IP | ||||
| # Le nom d'utilisateur | ||||
| printf '\e[1;35m%-6s\e[m\n' "DEBUG : Partie - Informations complémentaires dans le fichier de configuration" | ||||
| [[ "${DEBUG}" == "0" ]] && printf '\e[1;35m%-6s\e[m\n' "DEBUG : Partie - Informations complémentaires dans le fichier de configuration" | ||||
| 
 | ||||
| printf '\e[1;34m%-6s\e[m' "Votre adresse e-mail : " | ||||
| read input_mail | ||||
|  | @ -301,18 +301,18 @@ echo "# ip:$(IpAddress)" >> "${filepl}" | |||
| mv -f -- "${filepl}" "${dir1}" | ||||
| 
 | ||||
| #### CRÉATION DE L’UTILISATEUR BACKUPPC #### | ||||
| 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' | ||||
| AddUserBackuppc "${input_login}" "${homebackuppc}" | ||||
| mkdir -p -- "${homebackuppc}"/.ssh | ||||
| 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 : ${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 | ||||
| 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/ | ||||
| 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/" | ||||
| 
 | ||||
| #### END #### | ||||
| printf '\e[1;35m%-6s\e[m\n' "DEBUG : Partie - FIN" | ||||
| [[ "${DEBUG}" == "0" ]] && printf '\e[1;35m%-6s\e[m\n' "DEBUG : Partie - FIN" | ||||
| printf "%b\n" "Configuration du poste terminée." | ||||
| printf '\e[1;31m%-6s\e[m\n' "Envoyez bien votre fichier de configuration situé dans votre répertoire personnel (${dir1}/${filepl}) à Jérémy GARDAIS (jeremy.gardai@univ-rennes1.fr)." | ||||
| printf "%b\n" "Vous pourrez affiner la configuration de votre sauvegarde depuis https://backuppc.ipr.univ-rennes1.fr" | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue