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 | |
12 | PROGNAME=$(basename $0) |
13 | CLUSTER=/opt/cluster |
14 | ETH0MASTER=$(ip add show dev eth0 |awk '$1=="inet" {sub(/\/.*/, ""); print $2; exit}') |
15 | ETH1MASTER=$(ip add show dev eth1 |awk '$1=="inet" {sub(/\/.*/, ""); print $2; exit}') |
16 | MASTER=$(hostname -s) |
17 | TMPLOG=/tmp/$PROGNAME-$$.log |
18 | VER=1.0 |
19 | |
20 | # help function |
21 | |
22 | function 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 | |
31 | function title () { echo -e "\033[0;1m$*\033[0;0m"; } |
32 | function pass () { echo -e "\033[1;32m$*\033[0;0m"; } |
33 | function warn () { echo -e "\033[1;33m$*\033[0;0m"; } |
34 | function fail () { echo -e "\033[1;31m$*\033[0;0m"; } |
35 | # check command |
36 | |
37 | function 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 | |
46 | while [ $# -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 |
53 | done |
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 |
60 | check ssh-keygen -t rsa -N '""' -f /root/.ssh/id_rsa |
61 | check cp /root/.ssh/id_rsa.pub /root/.ssh/authorized_keys |
62 | check chmod go-w /root /root/.ssh /root/.ssh/authorized_keys |
63 | |
64 | # create slave repository |
65 | slaveroot=$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 |
71 | check cp -a /root/.ssh/{id_rsa,id_rsa.pub,authorized_keys} $slaveroot/root/.ssh |
72 | check 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 |
77 | check chown trc6500 $slaveroot/home/trc6500 |
78 | |
79 | # copy config files |
80 | check cp -a /root/{.bashrc,.profile,.screenrc,.vimrc} $slaveroot/root |
81 | |
82 | # vim:set tabstop=4 expandtab shiftwidth=4: |