update changelog
[debian6500.git] / master / opt / cluster / bin / sync_master.sh
CommitLineData
58b0c870
LM
1#!/bin/bash
2
3# ============================================================================
4# Copyright (C) THALES. All rights reserved
5# Author: Laurent Mazet
6# Date : 08/12/2014
7# ============================================================================
8
9# TODO
10# *
11
12HOST=
13PROGNAME=$(basename $0)
14VER=1.0
15
16# help function
17
18function usage () {
19 echo "usage: $PROGNAME [-h] [-v] host"
20 echo " -h: help message"
21 echo " -v: version message"
22 exit $@
23}
24
25# formating functions
26
27function title () { echo -e "\033[0;1m$*\033[0;0m"; }
28function pass () { echo -e "\033[1;32m$*\033[0;0m"; }
29function warn () { echo -e "\033[1;33m$*\033[0;0m"; }
30function fail () { echo -e "\033[1;31m$*\033[0;0m"; }
31
32# check command
33
34function check () {
35 echo -n "$@: "
36 { eval $@; } && pass OK || { fail KO; ERR=yes; }
37 test ! "$TEST" = yes
38}
39
40# argument processing
41
42while [ $# -gt 0 ]; do
43 case "$1" in
44 -h) usage 0;;
45 -v) echo "$PROGNAME: version $VER"; exit;;
46 *) HOST=$1;;
47 esac
48 shift
49done
50
51# find master directory
52mydir=$(dirname $0)
53mydir=$(cd $mydir; pwd)
54
55MASTERREP=$(cd $mydir/../../..; pwd)
56[ -d $MASTERREP ] || { echo "can't find master repository"; exit 1; }
57
58# check host
59[ "$HOST" ] || { echo "Need a hosname/ip to synchronize master"; exit 1; }
60
61# action
62check chmod g-w -R $MASTERREP
63check chmod go-rwx $MASTERREP/root/.ssh
64check chmod go-rwx $MASTERREP/root/.ssh/id_rsa
65check chmod go-rwx $MASTERREP/opt/cluster/slave/root/.ssh
66check chmod go-rwx $MASTERREP/opt/cluster/slave/root/.ssh/id_rsa
67check chmod a+rwx $MASTERREP/opt/tftp
0871e51f
TPVT
68if [ "$(hostname)" = 'clovis53' ]; then
69 REMOTE_FS="root@$HOST:/"
70else
71 REMOTE_FS="/tmp/$USERNAME$$"
72 mkdir $REMOTE_FS
73 case "$HOST" in
74 alpha) SENSOR_PORT="2222";;
75 gamma) SENSOR_PORT="2224";;
76 clovis) SENSOR_PORT="2223";;
77 *) fail "Incorrect name of sensor"; exit 1;;
78 esac
79 sshfs -p $SENSOR_PORT root@clovis53:/ $REMOTE_FS
80fi
81check rsync -va --no-o --no-g $MASTERREP/ $REMOTE_FS
82fusermount -u $REMOTE_FS 2>/dev/null && rmdir $REMOTE_FS
58b0c870
LM
83
84exit 0