add a script to synchronize master
authorLaurent Mazet <laurent.mazet@thalesgroup.com>
Mon, 8 Dec 2014 17:58:58 +0000 (18:58 +0100)
committerLaurent Mazet <laurent.mazet@thalesgroup.com>
Tue, 9 Dec 2014 09:21:54 +0000 (10:21 +0100)
master/opt/cluster/bin/sync_master.sh [new file with mode: 0755]

diff --git a/master/opt/cluster/bin/sync_master.sh b/master/opt/cluster/bin/sync_master.sh
new file mode 100755 (executable)
index 0000000..08298ad
--- /dev/null
@@ -0,0 +1,70 @@
+#!/bin/bash
+
+# ============================================================================
+# Copyright (C) THALES. All rights reserved
+# Author: Laurent Mazet
+# Date : 08/12/2014
+# ============================================================================
+
+# TODO
+# *
+
+HOST=
+PROGNAME=$(basename $0)
+VER=1.0
+
+# help function
+
+function usage () {
+    echo "usage: $PROGNAME [-h] [-v] host"
+    echo "   -h: help message"
+    echo "   -v: version message"
+    exit $@
+}
+
+# formating functions
+
+function title () { echo -e "\033[0;1m$*\033[0;0m"; }
+function pass () { echo -e "\033[1;32m$*\033[0;0m"; }
+function warn () { echo -e "\033[1;33m$*\033[0;0m"; }
+function fail () { echo -e "\033[1;31m$*\033[0;0m"; }
+
+# check command
+
+function check () {
+    echo -n "$@: "
+    { eval $@; } && pass OK || { fail KO; ERR=yes; }
+    test ! "$TEST" = yes
+}
+        
+# argument processing
+        
+while [ $# -gt 0 ]; do
+    case "$1" in
+    -h) usage 0;;
+    -v) echo "$PROGNAME: version $VER"; exit;;
+    *) HOST=$1;;
+    esac
+    shift
+done
+
+# find master directory
+mydir=$(dirname $0)
+mydir=$(cd $mydir; pwd)
+
+MASTERREP=$(cd $mydir/../../..; pwd)
+[ -d $MASTERREP ] || { echo "can't find master repository"; exit 1; }
+
+# check host
+[ "$HOST" ] || { echo "Need a hosname/ip to synchronize master"; exit 1; }
+
+# action
+check chmod g-w -R $MASTERREP
+check chmod go-rwx $MASTERREP/root/.ssh
+check chmod go-rwx $MASTERREP/root/.ssh/id_rsa
+check chmod go-rwx $MASTERREP/opt/cluster/slave/root/.ssh
+check chmod go-rwx $MASTERREP/opt/cluster/slave/root/.ssh/id_rsa
+check chmod a+rwx $MASTERREP/opt/tftp
+check rsync -va --no-o --no-g ~/debian6500/master/ root@$HOST:/
+
+exit 0