Import from Clearcase LIV_TRC6500_V2.2.3
[debian6500.git] / install / cluster / bin / init_cluster_repository.sh
CommitLineData
4e802319 1#!/bin/bash
2
3# ============================================================================
4# Copyright (C) THALES. All rights reserved
5# Author: Laurent Mazet
6# Date : 02/05/2014
7# ============================================================================
8
9# TODO
10# *
11
12PROGNAME=$(basename $0)
13CLUSTER=/opt/cluster
14ETH0MASTER=$(ip add show dev eth0 |awk '$1=="inet" {sub(/\/.*/, ""); print $2; exit}')
15ETH1MASTER=$(ip add show dev eth1 |awk '$1=="inet" {sub(/\/.*/, ""); print $2; exit}')
16MASTER=$(hostname -s)
17TMPLOG=/tmp/$PROGNAME-$$.log
18VER=1.0
19
20# help function
21
22function usage () {
23 echo "usage: $PROGNAME [-h] [-v]"
24 echo " -h: help message"
25 echo " -v: version message"
26 exit $@
27}
28
29# formating functions
30
31function title () { echo -e "\033[0;1m$*\033[0;0m"; }
32function pass () { echo -e "\033[1;32m$*\033[0;0m"; }
33function warn () { echo -e "\033[1;33m$*\033[0;0m"; }
34function fail () { echo -e "\033[1;31m$*\033[0;0m"; }
35# check command
36
37function check () {
38 echo -n "$@: "
39 eval $@ >&$TMPLOG && pass OK || { fail KO; cat $TMPLOG; ERR=yes; }
40 rm -f $TMPLOG
41 test ! "$TEST" = yes
42}
43
44# argument processing
45
46while [ $# -gt 0 ]; do
47 case "$1" in
48 -h) usage 0;;
49 -v) echo "$PROGNAME: version $VER"; exit;;
50 *) echo "unknown argument ($1)"; exit 1;;
51 esac
52 shift
53done
54
55# create root private key
56[ -d /root/.ssh ] || check mkdir /root/.ssh
57[ -f /root/.ssh/id_rsa ] && check rm -f /root/.ssh/id_rsa
58[ -f /root/.ssh/id_rsa.pub ] && check rm -f /root/.ssh/id_rsa.pub
59[ -f /root/.ssh/authorized_keys ] && check rm -f /root/.ssh/authorized_keys
60check ssh-keygen -t rsa -N '""' -f /root/.ssh/id_rsa
61check cp /root/.ssh/id_rsa.pub /root/.ssh/authorized_keys
62check chmod go-w /root /root/.ssh /root/.ssh/authorized_keys
63
64# create slave repository
65slaveroot=$CLUSTER/slave
66[ -d $slaveroot ] || check mkdir $slaveroot
67[ -d $slaveroot/root ] || check mkdir $slaveroot/root
68[ -d $slaveroot/root/.ssh ] || check mkdir $slaveroot/root/.ssh
69
70# copy ssh id
71check cp -a /root/.ssh/{id_rsa,id_rsa.pub,authorized_keys} $slaveroot/root/.ssh
72check chmod go-w $slaveroot/{root,root/.ssh,root/.ssh/authorized_keys}
73
74# create user homedir
75[ -d $slaveroot/home ] || check mkdir $slaveroot/home
76[ -d $slaveroot/home/trc6500 ] || check mkdir $slaveroot/home/trc6500
77check chown trc6500 $slaveroot/home/trc6500
78
79# copy config files
80check cp -a /root/{.bashrc,.profile,.screenrc,.vimrc} $slaveroot/root
81
82# vim:set tabstop=4 expandtab shiftwidth=4: