added support for email addresses ending with univ-rennes.fr (without the 1) to add_backup_host.sh
- also made add_backup_host.sh exit with a exit code different from 0 if anything goes wrong fixes [https://bugzilla.ipr.univ-rennes.fr/show_bug.cgi?id=4359]
This commit is contained in:
parent
67c2881029
commit
23fd956f06
|
|
@ -12,9 +12,19 @@
|
|||
# scp file.pl backuppc.ipr.univ-rennes1.fr:
|
||||
# ssh backuppc.ipr.univ-rennes1.fr
|
||||
# cd /etc/backuppc
|
||||
# sudo ./add_backuppc_host.sh ~/pt-gilles.spm.univ-rennes1.fr.pl
|
||||
# sudo ./add_backuppc_host.sh ~/pt-gilles.spm.univ-rennes.fr.pl
|
||||
|
||||
EXIT_CODE_SUCCES=0
|
||||
EXIT_CODE_ERROR=1
|
||||
|
||||
function debug_message()
|
||||
{
|
||||
msg="$1"
|
||||
# echo "DEBUG: ${msg}"
|
||||
}
|
||||
|
||||
#### DÉPENDANCES ####
|
||||
debug_message "DÉPENDANCES"
|
||||
# ldapsearch (pkg ldap-utils)
|
||||
if [ ! $(command -v ldapsearch) ]; then
|
||||
aptitude install dos2unix ldap-utils
|
||||
|
|
@ -32,15 +42,16 @@ config_pl_path="${1}"
|
|||
config_pl_name=$(basename -- "${config_pl_path}")
|
||||
|
||||
#### VÉRIFIER QUE L’ON A BIEN LES DROITS ADMIN ####
|
||||
debug_message "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"
|
||||
exit
|
||||
exit ${EXIT_CODE_ERROR}
|
||||
fi
|
||||
|
||||
#### VÉRIFIER QUE LE FICHIER EXISTE BIEN ####
|
||||
if [ ! -f "${config_pl_path}" ]; then
|
||||
printf '\e[1;31m%-6s\e[m' "Installation annulée, le fichier n'existe pas !"
|
||||
exit
|
||||
printf '\e[1;31m%-6s\e[m' "Installation annulée, le fichier ${config_pl_path} n'existe pas !"
|
||||
exit ${EXIT_CODE_ERROR}
|
||||
fi
|
||||
|
||||
#### VÉRIFIER QUE LE FICHIER EST BIEN EN UTF-8 ####
|
||||
|
|
@ -68,29 +79,34 @@ backup_username=$(grep "# username:" ${config_pl_path} | cut -d':' -f 2)
|
|||
|
||||
#### TESTS ####
|
||||
# Check IP
|
||||
debug_message "Check IP"
|
||||
if [[ ${ip_ur1} != "129.20" ]]; then
|
||||
printf "La machine cliente n'était pas sur le réseau UR1\n"
|
||||
exit 1
|
||||
exit ${EXIT_CODE_ERROR}
|
||||
fi
|
||||
|
||||
# Check mail
|
||||
if [[ ${mail_ur1} != "univ-rennes1.fr" ]]; then
|
||||
printf "Le client n'a pas renseigné une adresse UR1\n"
|
||||
exit 1
|
||||
debug_message "Check mail"
|
||||
if [ ${mail_ur1} != "univ-rennes1.fr" ] && [ ${mail_ur1} != "univ-rennes.fr" ]; then
|
||||
printf "Le client n'a pas renseigné une adresse email valide (${mail_ur1} doit etre univ-rennes1.fr ou univ-rennes.fr)\n"
|
||||
exit ${EXIT_CODE_ERROR}
|
||||
fi
|
||||
|
||||
#### AJOUTER L HÔTE DANS ${BACKUPPC_CONFIG_DIR}/HOSTS ####
|
||||
# jfade.pr079076.spm.univ-rennes1.fr 0 jfade
|
||||
debug_message "AJOUTER L HÔTE DANS ${BACKUPPC_CONFIG_DIR}/HOSTS"
|
||||
# jfade.pr079076.spm.univ-rennes.fr 0 jfade
|
||||
if [[ ! $(grep "${username}.${hostname}" "${backuppc_host_file}") ]]; then
|
||||
echo "${username}.${hostname} 0 ${username}" >> "${backuppc_host_file}"
|
||||
#echo "WRITE TO ${backuppc_host_file}: ${username}.${hostname} 0 ${username}"
|
||||
else
|
||||
printf '\e[1;31m%-6s\e[m' "Installation annulée, la ligne ${username}.${hostname} existe déjà dans ${backuppc_host_file} !"
|
||||
exit
|
||||
exit ${EXIT_CODE_ERROR}
|
||||
fi
|
||||
|
||||
|
||||
#### AJOUTER LA CLEF SSH DE LA MACHINE DE L'UTILISATEUR ####
|
||||
# pr079076.spm.univ-rennes1.fr ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBIFkIxzrMTZ/m9AgA7Jc+XnKdayDwUtehGOPo5m4i9yK5mCMM/iOrTOPxubey3YcQBuuqHNNRWbDV6n0z5KGvBU=
|
||||
debug_message "AJOUTER LA CLEF SSH DE LA MACHINE DE L'UTILISATEUR"
|
||||
# pr079076.spm.univ-rennes.fr ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBIFkIxzrMTZ/m9AgA7Jc+XnKdayDwUtehGOPo5m4i9yK5mCMM/iOrTOPxubey3YcQBuuqHNNRWbDV6n0z5KGvBU=
|
||||
if [[ $(grep "# hostkeycontent:" "${config_pl_path}") ]]; then
|
||||
hostkey=$(grep "# hostkeycontent:" ${config_pl_path} | cut -d':' -f 2)
|
||||
else
|
||||
|
|
@ -105,9 +121,12 @@ else
|
|||
#### NO EXIT !!! #### NEED ${fqdn} and NOT ${username}.${fqdn}
|
||||
fi
|
||||
|
||||
|
||||
#### DÉFINIR L'HÔTE DANS LA CONFIGURATION SSH ####
|
||||
debug_message "DÉFINIR L'HÔTE DANS LA CONFIGURATION SSH"
|
||||
|
||||
# Host jfade.pr079076
|
||||
# hostname pr079076.spm.univ-rennes1.fr
|
||||
# hostname pr079076.spm.univ-rennes.fr
|
||||
if [[ ! $(grep "${username}.${hostname}" "${backuppc_ssh_config_file}") ]]; then
|
||||
cat << EOF >> "${backuppc_ssh_config_file}"
|
||||
Host ${username}.${hostname}
|
||||
|
|
@ -129,6 +148,8 @@ EOF
|
|||
fi
|
||||
|
||||
#### DÉFINIR LE NOM D'HOTE POUR LE SYSTEME ####
|
||||
debug_message "DÉFINIR LE NOM D'HOTE POUR LE SYSTEME"
|
||||
|
||||
if [[ ! $(grep "${ip} ${username}.${hostname}" "${system_hosts}") ]]; then
|
||||
echo "${ip} ${username}.${hostname}" >> "${system_hosts}"
|
||||
#echo "WRITE TO ${system_hosts}: ${ip} ${username}.${hostname}"
|
||||
|
|
@ -143,9 +164,10 @@ if [ ! -f "${backuppc_config_dir}/${username}.hostname" ]; then
|
|||
#printf "TODO||TOREMOVE: mv ${config_pl_path}" "${backuppc_config_dir}/${username}.${hostname}.pl"
|
||||
else
|
||||
printf '\e[1;31m%-6s\e[m' "Installation annulée, le fichier ${username}.${hostname}.pl existe déjà dans ${backuppc_config_dir}/ !"
|
||||
exit
|
||||
exit ${EXIT_CODE_ERROR}
|
||||
fi
|
||||
|
||||
#### recharger la configuration de backuppc ####
|
||||
debug_message "reloading backuppc configuration"
|
||||
service backuppc reload
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue