forked from timberland-sig/rh-linux-poc
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·282 lines (241 loc) · 7.94 KB
/
setup.sh
File metadata and controls
executable file
·282 lines (241 loc) · 7.94 KB
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
#!/usr/bin/env bash
# SPDX-License-Identifier: GPL-3.0+
# Copyright (C) 2023 John Meneghini <jmeneghi@redhat.com> All rights reserved.
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
#echo "DIR = $DIR"
. $DIR/defaults.sh
# Configuraiton
MODES="user|devel|virt|net|edk2"
MODE="user"
set -e
display_help() {
echo
echo " Usage: ${0##*/} [-h] <$MODES>"
echo
echo " -h : display this help"
echo ""
echo " quickstart : runs user, virt, net, edk2"
echo " user : setup basic user environment (default)"
echo " devel : setup development environment"
echo " virt : install qemu-kvm environment "
echo " edk2 : download the timberland-sig modified edk2 firmware"
echo " : - install build artifacts in the host-vm directory"
echo " : - use -s or --source to build from source instead of downloading the prebuilt zip"
echo " net : configure network environment "
echo " : - script prompts for \"bridged\" primary interface."
echo " : Enter \"none\" to skip primary interace reconfiguration."
echo ""
echo " Examples: "
echo " Install qemu and configure hypervisor networks"
echo " ./${0##*/} virt "
echo " ./${0##*/} net "
exit 1
}
install_user() {
echo " : Installing user environment"
if [ ! -f .usr ]; then
sudo dnf install -y vim git wget ethtool net-tools zip unzip NetworkManager \
lorax-lmc-novirt pykickstart openssl make python3-pytest python3-jsonschema \
python3 python3-blessed
touch .usr
else
echo " : Nothing to do!"
fi
git submodule update --init host-vm/nvmeof-utils
}
install_devel() {
echo " : Installing developer environment"
if [ ! -f .devel ]; then
sudo dnf group install -y development-tools
sudo dnf install -y asciidoc audit-libs-devel binutils-devel elfutils-devel java-devel kabi-dw libcap-devel \
libcap-ng-devel libmnl-devel llvm ncurses-devel newt-devel nss-tools numactl-devel pciutils-devel perl perl-generators \
pesign python3-devel python3-docutils xmlto rpm-build yum-utils sg3_utils dwarves libbabeltrace-devel libbpf-devel openssl-devel \
wget bison acpica-tools binutils gcc gcc-c++ meson cmake dbus-devel libuuid libuuid-devel \
json-c-devel json-c json-c-doc clang openssl kmod-devel python3-sphinx python3-sphinx_rtd_theme swig \
systemd-devel mock lorax tar gpg pciutils copr-cli nvme-cli nasm
sudo usermod -a -G mock $USER
if [ ! -f ~/.gitconfig ]; then
echo " : You must setup ~/.gitconfig"
exit 1
fi
if [ ! -d ~/.ssh ]; then
echo " : You must setup setup ~/.ssh"
exit 1
else
ssh -o StrictHostKeyChecking=no -T git@github.com
if [ $? -ne 1 ]; then
echo " : You must setup your ssh key for github.com"
exit 1
fi
fi
if [ ! -f ~/.config/copr ]; then
echo " : You must setup setup ~/.config/copr"
exit 1
fi
FOO="$(copr-cli whoami)"
if [ -z "$FOO" ]; then
echo " : No copr user found! "
exit 1
fi
touch .devel
fi
if [ ! -f .macaddr ]; then
FOO="$(./gen_macaddr.py)"
if [ -z "$FOO" ]; then
echo " : gen_macaddr.py failed! "
exit 1
else
sed -i "s/^TARGET_MAC1.*/TARGET_MAC1\=$FOO/" defaults.sh
fi
FOO="$(./gen_macaddr.py)"
if [ -z "$FOO" ]; then
echo " : gen_macaddr.py failed! "
exit 1
else
sed -i "s/^HOST_MAC1.*/HOST_MAC1\=$FOO/" defaults.sh
fi
touch .macaddr
fi
git submodule update --init --recursive
}
install_network() {
echo " : setup bridged network environment"
source $DIR/vm-lib/common.sh
bridge_iface 'br0' "$1" "$2"
ip -h -c -o -br address show ${br_name}
if ! nmcli dev show virbr1 &>/dev/null ; then
bridge_iface 'virbr1' "$3" "$4"
ip -h -c -o -br address show virbr1
fi
if ! nmcli dev show virbr2 &>/dev/null ; then
bridge_iface 'virbr2' "$5" "$6"
ip -h -c -o -br address show virbr2
fi
echo "Network interfaces configured!"
# Make SSH key for password-less login
make --makefile="$DIR/vm-lib/Makefile" .ssh/id_ecdsa
}
install_virt() {
if ! command -v qemu-system-x86_64 ; then
sudo dnf install -y qemu-kvm qemu-img
fi
echo "allow all" > /tmp/bridge.conf
sudo cp /tmp/bridge.conf /etc/qemu/bridge.conf
sudo chmod 4755 /usr/libexec/qemu-bridge-helper
}
install_edk2() {
pushd $DIR
if [ ! -d edk2 ]; then
mkdir -p edk2
pushd edk2
git clone -b timberland_upstream-dev-full git@github.com:timberland-sig/edk2.git
pushd edk2
git config url."ssh://git@github.com/timberland-sig".insteadOf https://github.com/timberland-sig
git submodule update --init --recursive
popd
popd
fi
pushd edk2/edk2
make -C BaseTools clean
rm -rf Build
make -C BaseTools
source edksetup.sh
build -t GCC5 -a X64 -p OvmfPkg/OvmfPkgX64.dsc
mkdir -p $DIR/ISO
rm -f $DIR/host-vm/OVMF_CODE.fd
rm -f $DIR/host-vm/vm_vars.fd
rm -f $DIR/host-vm/eficonfig/NvmeOfCli.efi
rm -f $DIR/host-vm/eficonfig/VConfig.efi
cp -fv Build/OvmfX64/DEBUG_GCC5/FV/OVMF_CODE.fd $DIR/host-vm/OVMF_CODE.fd
cp -fv Build/OvmfX64/DEBUG_GCC5/FV/OVMF_VARS.fd $DIR/host-vm/vm_vars.fd
cp -fv Build/OvmfX64/DEBUG_GCC5/FV/OVMF_VARS.fd $DIR/ISO/OVMF_VARS.fd
cp -fv Build/OvmfX64/DEBUG_GCC5/X64/VConfig.efi $DIR/host-vm/eficonfig/VConfig.efi
cp -fv Build/OvmfX64/DEBUG_GCC5/X64/NvmeOfCli.efi $DIR/host-vm/eficonfig/NvmeOfCli.efi
popd
}
install_edk2_zip() {
pushd $DIR
if [ ! -d ISO ]; then
mkdir -p ISO
fi
if [ ! -f ISO/$OVMF_ZIP ]; then
pushd ISO
wget --no-check-certificate $OVMF_URL/$OVMF_ZIP
unzip $OVMF_ZIP
popd
fi
if [ ! -f ISO/OVMF_CODE.fd ]; then
echo "file ISO/OVMF_CODE.fd not found!"
exit 1
fi
rm -f host-vm/OVMF_CODE.fd
rm -f host-vm/vm_vars.fd
rm -f host-vm/eficonfig/NvmeOfCli.efi
rm -f host-vm/eficonfig/VConfig.efi
cp -fv ISO/OVMF_CODE.fd host-vm/OVMF_CODE.fd
cp -fv ISO/OVMF_VARS.fd host-vm/vm_vars.fd
cp -fv ISO/NvmeOfCli.efi host-vm/eficonfig/NvmeOfCli.efi
cp -fv ISO/VConfig.efi host-vm/eficonfig/VConfig.efi
popd
}
while getopts "h" opt; do
case "${opt}" in
h)
display_help >&2
exit 0
;;
*)
echo " Invalid argument: -$OPTARG" >&2
echo " Try: \"$0 -h\"" >&2
exit 1
;;
esac
done
shift "$((OPTIND-1))" # Discard the options and sentinel --
MODE=$(echo "$@" | tr -t '/' ' ' | awk '{print $1}')
if [ -z "${MODE}" ]; then
echo "Try: \"$0 -h\"" >&2
fi
shift 1
NEWARGS="$@"
case "${MODE}" in
quick*)
install_user
install_virt
install_edk2_zip
install_network
;;
test)
pushd target-vm
make rh-start QEMU_ARGS="-vnc :0"
popd
pushd host-vm
make setup QEMU_ARGS="-vnc :1"
popd
;;
user)
install_user
;;
devel)
install_devel
;;
virt)
install_virt
;;
net)
install_network $NEWARGS
;;
edk2)
# Check for -s or --source flag
if [[ "$2" == "-s" || "$2" == "--source" ]]; then
install_edk2
else
install_edk2_zip
fi
;;
*)
echo " Invalid argument: $MODE" >&2
echo " Try: \"$0 -h\"" >&2
exit 1
;;
esac