From 58b0c870cbf6fbb627377924a6d180ef88e29dbd Mon Sep 17 00:00:00 2001 From: Laurent Mazet Date: Mon, 8 Dec 2014 18:58:58 +0100 Subject: [PATCH] add a script to synchronize master --- master/opt/cluster/bin/sync_master.sh | 70 +++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100755 master/opt/cluster/bin/sync_master.sh diff --git a/master/opt/cluster/bin/sync_master.sh b/master/opt/cluster/bin/sync_master.sh new file mode 100755 index 0000000..08298ad --- /dev/null +++ b/master/opt/cluster/bin/sync_master.sh @@ -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 -- 2.30.2