aboutsummaryrefslogtreecommitdiffstats
path: root/testing/scripts/build-umlrootfs
blob: f321463db68de7cbc18e58e14aa2b89f83a5db93 (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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#!/bin/bash
# Create UML root filesystem
#
# 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"

source $DIR/../testing.conf

cecho-n " * Looking for root image at '$ROOTFS'.."
if [ -f "$ROOTFS" ]
then
    cgecho "found it"
else
    cecho "none"
    exit
fi

[ -d $BUILDDIR ] || die "!! Directory '$BUILDDIR' does not exist"

ROOTFSDIR=$BUILDDIR/root-fs

if [ ! -d $ROOTFSDIR ]
then
    cecho-n " * Root file system directory '$ROOTFSDIR' does not exist..creating.."
    mkdir $ROOTFSDIR
    cgecho "done"
fi

cd $ROOTFSDIR

if [ ! -d $LOOPDIR ]
then
    mkdir $LOOPDIR
fi

######################################################
# mount root image
#
BASE=$BUILDDIR/base.img
cecho-n " * Mounting base image $BASE.."
cp $ROOTFS $BASE
mount -o loop $BASE $LOOPDIR >> $LOGFILE 2>&1
mount -t proc none $LOOPDIR/proc >> $LOGFILE 2>&1
cgecho "done"

######################################################
# install software from source using 'recipes'
#
mkdir -p $ROOTFSCOMPILEDIR
cecho " * Mounting $ROOTFSCOMPILEDIR as /root/compile.."
mkdir -p $LOOPDIR/root/compile
mount -o bind $ROOTFSCOMPILEDIR $LOOPDIR/root/compile >> $LOGFILE 2>&1

cecho " * Installing software from source.."
RECPDIR=$UMLTESTDIR/testing/scripts/recipes
RECIPES=`ls $RECPDIR/*.mk | xargs -n1 basename`
cp -r $RECPDIR/patches $LOOPDIR/root/compile
for r in $RECIPES
do
	cecho-n "   - $r.."
	cp $RECPDIR/$r ${LOOPDIR}/root/compile
	chroot ${LOOPDIR} make -C /root/compile -f $r >>$LOGFILE 2>&1
	if [ $? != 0 ]; then
		cecho "failed"
	else
		cgecho "done"
	fi
done

umount $LOOPDIR/root/compile

cecho " * Setting up shared build tree at /root/compile"
echo "" >> $LOOPDIR/etc/fstab
echo "none /root/compile hostfs $ROOTFSCOMPILEDIR" >> $LOOPDIR/etc/fstab

######################################################
# remove /etc/resolv.conf
#
cecho " * Removing /etc/resolv.conf"
rm -f $LOOPDIR/etc/resolv.conf

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

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

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"
fi
rm ~/.ssh/known_hosts
cecho-n " * Creating new '~/.ssh/known_hosts'.."
touch ~/.ssh/known_hosts
cgecho "done"

for host in $HOSTNAMEIPV4
do
	HOSTNAME=`echo $host | awk -F, '{ print $1 }'`
	IP=`echo $host | awk -F, '{ print $2 }'`
	cecho-n " * Adding uml host $HOSTNAME ($IP) to '~/.ssh/known_hosts'.."
	echo "$HOSTNAME,$IP `cat $LOOPDIR/etc/ssh/ssh_host_rsa_key.pub`" >> ~/.ssh/known_hosts
	cgecho "done"
done

######################################################
# copying the host's ssh public key
#
if [ ! -d $LOOPDIR/root/.ssh ]
then
    mkdir $LOOPDIR/root/.ssh
fi
cp ~/.ssh/id_rsa.pub $LOOPDIR/root/.ssh/authorized_keys

######################################################
# setup public key based login among all hosts
#
cp $LOOPDIR/etc/ssh/ssh_host_rsa_key $LOOPDIR/root/.ssh/id_rsa

for host in $STRONGSWANHOSTS
do
    eval ip="`echo $HOSTNAMEIPV4 | sed -n -e "s/^.*${host},//gp" | awk -F- '{ print $1 }' | awk '{ print $1 }'`"
    echo "$host,$ip `cat $LOOPDIR/etc/ssh/ssh_host_rsa_key.pub`" >> $LOOPDIR/root/.ssh/known_hosts
    echo "`cat $LOOPDIR/etc/ssh/ssh_host_rsa_key.pub` root@$host" >> $LOOPDIR/root/.ssh/authorized_keys
done

umount $LOOPDIR/proc
umount $LOOPDIR