Project

General

Profile

Download (3.77 KB) Statistics
| Branch: | Revision:

git_sitools_idoc / flarecast / workspace / tools / deploy.sh @ master

1 d2a8c3fd Marc NICOLAS
#! /bin/bash
2
3
# =========
4
# Fonctions
5
6
# -------------------------------------------------
7
# Trace toutes les operations dans un fichier "LOG"
8
_log() {
9
    [ "${1}" = "" ] && return 0
10
    mess="${1}"
11
    if [ ${DEBUG} -eq  1 ];then
12
        echo "${mess}" | tee -a ${LOG}
13
    else
14
        echo "${mess}" >> ${LOG}
15
    fi
16
}
17
18
# ----------------------------
19
# Arret du processus "sitools"
20
stopSitools() {
21
    _log "Arret de sitools sur ${TARGET_HOST}..."
22
    _log "ssh ${SSH_OPTIONS} ${TARGET_USER}@${TARGET_HOST} \"${TARGET_COM} stop\""
23
    _log "`ssh ${SSH_OPTIONS} ${TARGET_USER}@${TARGET_HOST} \"${TARGET_COM} stop\" 2>&1`"
24
}
25
26
# ----------------------------------------------------------
27
# Sauvegarde prealable puis effacement du repertoire sitools
28
purgeSitools() {
29
    if [ "${TARGET_PURGE_DIR}" != "" ];then
30
        local TD=`echo ${TARGET_PURGE_DIR} | tr -d [=*=] | tr -d [=?=] | tr -d '..'`
31
        if [ "${TD}" != "${TARGET_PURGE_DIR}" ];then
32
            _log "--- ERREUR ---"
33
            _log "les chemins relatifs ou avec meta-caracteres sont interdits"
34
            _log "--- ERREUR ---"
35
            exit 1
36
        else
37
            TARGET_PURGE_DIR="${TD}"
38
            _log "Purge de ${TARGET_PURGE_DIR} sur ${TARGET_HOST}"
39
            local dateBkp=`date +%Y%m%d`
40
            _log "   - Sauvegarde prealable, veuillez patienter..."
41
            _log "`ssh ${SSH_OPTIONS} ${TARGET_USER}@${TARGET_HOST} \"tar cvjf ${TARGET_DIR}/sitools-${dateBkp}.tar.bz2 ${TARGET_PURGE_DIR}\" 2>&1`"
42
            if [ "${TARGET_PURGE_DIR}" != "" ];then
43
                _log "   - Effacement du repertoire ${TARGET_PURGE_DIR} ..."
44
                _log "`ssh ${SSH_OPTIONS} ${TARGET_USER}@${TARGET_HOST} \"\rm -rf ${TARGET_PURGE_DIR}\" 2>&1`"
45
            fi
46
        fi
47
    else
48
        _log "la variable TARGET_PURGE_DIR n'est pas renseignee. Abandon."
49
        exit 1
50
    fi
51
    _log "Fin de la purge"
52
}
53
54
# -------------------------------------------------
55
# Copie du repertoire local vers le serveur distant
56
deploySitools() {
57
    if [ ! -d ${ROOT_DIR}/${SITOOLS_SRC} ];then
58
        _log "--- ERREUR ---"
59
        _log "Repertoire source ${ROOT_DIR}/${SITOOLS_SRC} introuvable. Abandon."
60
        _log "--- ERREUR ---"
61
        exit 1
62
    else
63
        _log "Deploiement en cours sur ${TARGET_HOST} ..."
64
        cd ${ROOT_DIR}
65
        _log "Creation du repertoire ${TARGET_DIR} ..."
66
        _log "`ssh ${SSH_OPTIONS} ${TARGET_USER}@${TARGET_HOST} \"mkdir -p ${TARGET_DIR}\" 2>&1`"
67
        _log "tar cvf - ${SITOOLS_SRC} | ssh ${TARGET_USER}@${TARGET_HOST} \"cd ${TARGET_DIR} ; tar xvf -\" 2>&1 >/dev/null"
68
        tar cvf - ${SITOOLS_SRC} | ssh ${TARGET_USER}@${TARGET_HOST} "cd ${TARGET_DIR} ; tar xvf -" 2>&1 >/dev/null
69
        _log "Deploiement termine."
70
    fi
71
}
72
73
# ------------------------------
74
# Demarrage distant de "sitools"
75
startSitools() {
76
    _log "Demarrage de sitools sur ${TARGET_HOST}..."
77
    _log "`ssh ${SSH_OPTIONS} ${TARGET_USER}@${TARGET_HOST} \"${TARGET_COM} start\" 2>&1`"
78
}
79
80
# =========
81
# Principal
82
DEBUG=1
83
84
prog=`basename ${0}`
85
myDir=`dirname ${0}`
86
myPid=${$}
87
88
startDate=`date +%Y%m%d`
89
90
LOG_DIR="${myDir}/LOG"
91
[ ! -d ${LOG_DIR} ] && mkdir -p ${LOG_DIR}
92
LOG="${LOG_DIR}/${prog}-${myPid}.log"
93
94
# ------------------------------------
95
# Parametres de deploiement de sitools
96
ROOT_DIR="${HOME}"
97
SITOOLS_SRC="sitools-distribution"
98
TARGET_USER="hudson"
99
TARGET_HOST="linux76.silogic.fr"
100
TARGET_DIR="${ROOT_DIR}/${SITOOLS_SRC}-${startDate}"
101
102
TARGET_PURGE_DIR="${TARGET_DIR}/${SITOOLS_SRC}"
103
mustPurge='no'
104
105
TARGET_COM="${ROOT_DIR}/${SITOOLS_SRC}/snapshot/prototype/sitools"
106
107
SSH_OPTIONS="-o BatchMode=yes -n -f"
108
# ---------------------------------
109
# Debut du processus de deploiement
110
#stopSitools
111
112
113
[ "${1}" = "-p" ] && mustPurge='yes'
114
115
[ "${mustPurge}" = "yes" ] && purgeSitools
116
117
deploySitools
118
119
#startSitools
120
121
exit 0
122
# =============
123
# Fin du script
124
# =============