-
Notifications
You must be signed in to change notification settings - Fork 0
/
configure-hyperv-guest.sh
66 lines (59 loc) · 1.03 KB
/
configure-hyperv-guest.sh
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
#!/bin/bash
set -euxo pipefail
# bail when not running over hyperv.
dmi_sys_vendor=$(cat /sys/devices/virtual/dmi/id/sys_vendor)
if [ "$dmi_sys_vendor" != 'Microsoft Corporation' ]; then
exit 0
fi
if [ -f /etc/network/interfaces ]; then
# debian.
cat >/etc/network/interfaces <<EOF
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet dhcp
auto vmbr0
iface vmbr0 inet manual
EOF
n=0
for ip in "$@"; do
((n=n+1))
cat >>/etc/network/interfaces <<EOF
auto eth$n
iface eth$n inet static
address $ip/24
EOF
ifup eth$n
done
else
# ubuntu.
cat >/etc/netplan/02-hyperv.yaml <<EOF
network:
version: 2
renderer: networkd
ethernets:
EOF
n=0
for ip in "$@"; do
((n=n+1))
cat >>/etc/netplan/02-hyperv.yaml <<EOF
eth$n:
addresses:
- $ip/24
EOF
done
netplan apply
fi
# show resulting configuration.
ip addr
# wait until we can resolve addresses.
python3 <<'EOF'
import socket
import time
while True:
try:
socket.gethostbyname("ruilopes.com")
break
except:
time.sleep(1)
EOF