-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy_r10k_env.sh
66 lines (54 loc) · 2.13 KB
/
deploy_r10k_env.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/bin/bash
# ------------------------------------------------------------------------------
# Variables
# ------------------------------------------------------------------------------
TMP_DIR=/tmp/$(basename ${0})
LOG_FILE=${TMP_DIR}/$(basename ${0}).log
R10K_ENV_DIR=/etc/puppetlabs/code/environments/
# ------------------------------------------------------------------------------
# Fonctions
# ------------------------------------------------------------------------------
function on_error {
echo -e "\033[91m[!] $@\033[0m"
exit 1
}
function notify {
echo -e "\033[96m[+] $@\033[0m"
}
function on_warning {
echo -e "\033[93m[?] $@\033[0m"
}
function item {
echo -e "\033[95m '-> $@\033[0m"
}
# ------------------------------------------------------------------------------
# Main
# ------------------------------------------------------------------------------
notify "Création du répertoire temporaire ${TMP_DIR}"
mkdir -p ${TMP_DIR}
RET_VAL=$?
if [ ! ${RET_VAL} -eq 0 ]; then
on_error "Erreur lors de la création du répertoire temporaire" >> ${LOG_FILE}
fi
notify "Purge du répertoire temporaire ${TMP_DIR}" >> ${LOG_FILE}
rm -Rf ${TMP_DIR}/*
RET_VAL=$?
if [ ! ${RET_VAL} -eq 0 ]; then
on_error "Erreur lors de la purge" >> ${LOG_FILE}
fi
notify "Sauvegarde des environnements dans ${TMP_DIR}" >> ${LOG_FILE}
find ${R10K_ENV_DIR} -maxdepth 1 -type d \( -not -name "production" -and -not -name "$(basename ${R10K_ENV_DIR})" \) -exec cp -R {} ${TMP_DIR} \;
if [ ! ${RET_VAL} -eq 0 ]; then
on_error "Erreur lors de la copie des environnements" >> ${LOG_FILE}
fi
notify "Déploiement de l'environnement 'production'" >> ${LOG_FILE}
/usr/local/bin/r10k deploy environment production -pv
if [ ! ${RET_VAL} -eq 0 ]; then
on_error "Erreur lors du déploiement" >> ${LOG_FILE}
fi
notify "Restauration des environnements depuis ${TMP_DIR}" >> ${LOG_FILE}
find ${TMP_DIR} -maxdepth 1 -type d -type d \( -not -name "production" -and -not -name "$(basename ${TMP_DIR})" \) -exec cp -R {} ${R10K_ENV_DIR} \;
if [ ! ${RET_VAL} -eq 0 ]; then
on_error "Erreur lors de la copie des environnements" >> ${LOG_FILE}
fi
notify "Fin(0)" >> ${LOG_FILE}