Move install/* to .
[debian6500.git] / cluster / bin / init_cluster_repository.sh
diff --git a/cluster/bin/init_cluster_repository.sh b/cluster/bin/init_cluster_repository.sh
new file mode 100755 (executable)
index 0000000..d0e4cbd
--- /dev/null
@@ -0,0 +1,82 @@
+#!/bin/bash
+
+# ============================================================================
+# Copyright (C) THALES. All rights reserved
+# Author: Laurent Mazet
+# Date : 02/05/2014
+# ============================================================================
+
+# TODO
+# *
+
+PROGNAME=$(basename $0)
+CLUSTER=/opt/cluster
+ETH0MASTER=$(ip add show dev eth0 |awk '$1=="inet" {sub(/\/.*/, ""); print $2; exit}')
+ETH1MASTER=$(ip add show dev eth1 |awk '$1=="inet" {sub(/\/.*/, ""); print $2; exit}')
+MASTER=$(hostname -s)
+TMPLOG=/tmp/$PROGNAME-$$.log
+VER=1.0
+
+# help function
+
+function usage () {
+    echo "usage: $PROGNAME [-h] [-v]"
+    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 $@ >&$TMPLOG && pass OK || { fail KO; cat $TMPLOG; ERR=yes; }
+    rm -f $TMPLOG
+    test ! "$TEST" = yes
+}
+
+# argument processing
+
+while [ $# -gt 0 ]; do
+    case "$1" in
+    -h) usage 0;;
+    -v) echo "$PROGNAME: version $VER"; exit;;
+    *) echo "unknown argument ($1)"; exit 1;;
+    esac
+    shift
+done
+
+# create root private key
+[ -d /root/.ssh ] || check mkdir /root/.ssh
+[ -f /root/.ssh/id_rsa ] && check rm -f /root/.ssh/id_rsa
+[ -f /root/.ssh/id_rsa.pub ] && check rm -f /root/.ssh/id_rsa.pub
+[ -f /root/.ssh/authorized_keys ] && check rm -f /root/.ssh/authorized_keys
+check ssh-keygen -t rsa -N '""' -f /root/.ssh/id_rsa
+check cp /root/.ssh/id_rsa.pub /root/.ssh/authorized_keys
+check chmod go-w /root /root/.ssh /root/.ssh/authorized_keys
+
+# create slave repository
+slaveroot=$CLUSTER/slave
+[ -d $slaveroot ] || check mkdir $slaveroot
+[ -d $slaveroot/root ] || check mkdir $slaveroot/root
+[ -d $slaveroot/root/.ssh ] || check mkdir $slaveroot/root/.ssh
+
+# copy ssh id
+check cp -a /root/.ssh/{id_rsa,id_rsa.pub,authorized_keys} $slaveroot/root/.ssh
+check chmod go-w $slaveroot/{root,root/.ssh,root/.ssh/authorized_keys}
+
+# create user homedir
+[ -d $slaveroot/home ] || check mkdir $slaveroot/home
+[ -d $slaveroot/home/trc6500 ] || check mkdir $slaveroot/home/trc6500
+check chown trc6500 $slaveroot/home/trc6500
+
+# copy config files
+check cp -a /root/{.bashrc,.profile,.screenrc,.vimrc} $slaveroot/root
+
+# vim:set tabstop=4 expandtab shiftwidth=4: