-
Notifications
You must be signed in to change notification settings - Fork 0
/
40-inside-running-vm-prepare-vm-from-stage3.sh
executable file
·74 lines (60 loc) · 1.6 KB
/
40-inside-running-vm-prepare-vm-from-stage3.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
67
68
69
70
71
72
73
#!/bin/bash
#
# create virtual machine from stage3 image
# this must be run inside running VM with systemd
LANG=C
# check if we are really inside the virtual server
if [ -e /40-inside-running-vm-prepare-vm-from-stage3.sh ]; then
if lscpu | grep -e "BIOS Vendor.*QEMU" -q
then
echo "inside virtual machine, start working"
else
echo "not inside virtual machine, exit"
exit 1
fi
else
echo "not inside chroot/vm, exit"
exit 1
fi
# source the config file
DIR=$(dirname $0); [ -e "$DIR/00-config.sh" ] && source "$DIR/00-config.sh"
# determine $Arch and $Variant from filename
STAGE3=$(ls /stage3-*.tar.*)
Arch=$(echo "$STAGE3" | cut -d"-" -f2)
Variant=$(echo "$STAGE3" | cut -d"-" -f3- | rev | cut -d"-" -f2- | rev)
echo "Arch: $Arch - Variant $Variant"
set -e -x -v
INIT=unknown
# check for systemd/openrc
if which systemctl >/dev/null 2>&1
then
INIT=systemd
fi
if which openrc >/dev/null 2>&1
then
INIT=openrc
fi
case $INIT in
systemd)
# configure hostname
hostnamectl set-hostname "pkgtester-$Arch"
# configure keyboard layout
localectl set-keymap "$VM_KEYBOARD_KEYMAP"
# configure timezone
timedatectl set-timezone "$VM_TIMEZONE"
# create machine id, VERY important for networking
systemd-machine-id-setup
;;
openrc)
# configure hostname
sed -i -e "s|localhost|pkgtester-$Arch|" /etc/conf.d/hostname
# configure keyboard layout
sed -i -e "s|keymap=\"us\"|keymap=\"$VM_KEYBOARD_KEYMAP\"|" /etc/conf.d/keymaps
# configure timezone
echo "$VM_TIMEZONE" >/etc/timezone
emerge --config sys-libs/timezone-data >/dev/null 2>&1
;;
*)
echo "unknonw init system, do nothing"
;;
esac