update gitignore
[debian6500.git] / master / opt / cluster / bin / sync_master.sh
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
12 HOST=
13 PROGNAME=$(basename $0)
14 VER=1.0
15
16 # help function
17
18 function 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
27 function title () { echo -e "\033[0;1m$*\033[0;0m"; }
28 function pass () { echo -e "\033[1;32m$*\033[0;0m"; }
29 function warn () { echo -e "\033[1;33m$*\033[0;0m"; }
30 function fail () { echo -e "\033[1;31m$*\033[0;0m"; }
31
32 # check command
33
34 function check () {
35 echo -n "$@: "
36 { eval $@; } && pass OK || { fail KO; ERR=yes; }
37 test ! "$TEST" = yes
38 }
39
40 # argument processing
41
42 while [ $# -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
49 done
50
51 # find master directory
52 mydir=$(dirname $0)
53 mydir=$(cd $mydir; pwd)
54
55 MASTERREP=$(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
62 check chmod g-w -R $MASTERREP
63 check chmod go-rwx $MASTERREP/root/.ssh
64 check chmod go-rwx $MASTERREP/root/.ssh/id_rsa
65 check chmod go-rwx $MASTERREP/opt/cluster/slave/root/.ssh
66 check chmod go-rwx $MASTERREP/opt/cluster/slave/root/.ssh/id_rsa
67 check chmod a+rwx $MASTERREP/opt/tftp
68 if [ "$(hostname)" = 'clovis53' ]; then
69 REMOTE_FS="root@$HOST:/"
70 else
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
80 fi
81 check rsync -va --no-o --no-g $MASTERREP/ $REMOTE_FS
82 fusermount -u $REMOTE_FS 2>/dev/null && rmdir $REMOTE_FS
83
84 exit 0