summaryrefslogtreecommitdiff
path: root/testing/scripts/build-sshkeys
blob: 799078557cdd127ba5d21f3d9a6e85cee10550b3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/bin/bash
# build the hosts configuration directory with the actual IP addresses
#
# Copyright (C) 2004  Eric Marchionni, Patrik Rayo
# Zuercher Hochschule Winterthur
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 2 of the License, or (at your
# option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
# for more details.

DIR=`dirname $0`

source $DIR/function.sh

[ -f $DIR/../testing.conf ] || die "!! Configuration file 'testing.conf' not found"
[ -d $DIR/../hosts ]        || die "!! Directory 'hosts' not found"

source $DIR/../testing.conf

if [ ! -d $BUILDDIR ]
then
    cecho " * Creating directory '$BUILDDIR'"
    mkdir $BUILDDIR
fi

LOGFILE=${BUILDDIR}/testing.log

if [ ! -f $LOGFILE ]
then
    cecho-n " * Logfile '$LOGFILE' does not exist..creating.."
    touch $LOGFILE
    cgecho "done"
fi

if [ ! -d ~/.ssh ]
then
    cecho-n " * Creating directory '~/.ssh'.."
    mkdir ~/.ssh
    cgecho "done"
fi

if [ -f ~/.ssh/known_hosts ]
then
    cecho-n " * Backing up ~/.ssh/known_hosts to '~/.ssh/known_hosts.before_uml'.."
    cp -fp ~/.ssh/known_hosts ~/.ssh/known_hosts.before_uml
    cgecho "done"
else
    cecho-n " * Creating '~/.ssh/known_hosts'"
    touch ~/.ssh/known_hosts
    cgecho "done"
fi

for host in $HOSTNAMEIPV4
do
    HOSTNAME=`echo $host | awk -F, '{ print $1 }'`
    IP=`echo $host | awk -F, '{ print $2 }'`
    if [ `grep "$IP " ~/.ssh/known_hosts | wc -l` != "0" ]
    then
        cecho "!! Warning: An entry exists for the following IP address: $IP"
    else
	cecho-n " * Adding uml host $HOSTNAME ($IP) to '~/.ssh/known_hosts'.."
	echo "$HOSTNAME,$IP `cat $DIR/../hosts/ssh_host_rsa_key.pub`" >> ~/.ssh/known_hosts
	cgecho "done"
    fi
done

#####################################
# preparing ssh for PK authentication
#

cecho-n " * Checking for ssh rsa key '~/.ssh/id_rsa.pub'.."
if [ -f ~/.ssh/id_rsa.pub ]
then
    cecho "already exists"
else
    cecho "not found"
    cecho-n " * Generating ssh rsa key pair.."
    echo "" | ssh-keygen -N "" -t rsa -f ~/.ssh/id_rsa >> $LOGFILE 2>&1
    cgecho "done"
fi