aboutsummaryrefslogtreecommitdiff
blob: 9b810cea8579a24a0dc32911aee4cfe5c2f44654 (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
#!/bin/bash

source /tmp/chroot-functions.sh

if [[ $(readlink /etc/portage/make.profile) == *systemd* ]] ; then

# We are using systemd.

# Types of bootable disk images planned for (diskimage/type):
# cloud-init - an image that starts cloud-init for configuration and then can be
#              used out of the box
# console    - an image that has an empty root password and allows passwordless
#              login on the console only
# ssh        - an image that populates /root/.ssh/authorized_keys and starts dhcp
#              as well as sshd; obviously not fit for public distribution
# generic    - an image with no means of logging in... needs postprocessing
#              no services are started

configure_dhcp() {
	echo "Configuring DHCP on all ethernet devices"
	cat > /etc/systemd/network/default.network <<'END'
[Match]
Name=en*

[Network]
DHCP=yes
END
}

configure_sshd() {
	echo "Configuring sshd"
	mkdir -vp /root/.ssh
	chown root:root /root/.ssh
	echo "${clst_diskimage_sshkey}" > /root/.ssh/authorized_keys
}

echo "Generating /etc/locale.gen"
cat > /etc/locale.gen <<END
# en_US ISO-8859-1
# en_US.UTF-8 UTF-8
C.UTF-8 UTF-8
END

echo "Running systemctl preset-all"
systemctl preset-all || die "Running systemctl preset-all failed"

echo "Setting locale"
echo 'LANG="C.UTF-8"' > /etc/locale.conf || die "Failed to set locale"
env-update || die "Failed to run env-update"

echo "Setting keymap"
echo "KEYMAP=us" > /etc/vconsole.conf || die "Failed to set keymap"

echo "Disk image type is ${clst_diskimage_type}"
case ${clst_diskimage_type} in
	generic)
		echo "Setting up generic image (warning, not very useful on its own)"
		echo "Running systemd-firstboot"
		systemd-firstboot --timezone=UTC || die "Failed running systemd-firstboot"
		;;
	console)
		echo "Setting up console log-in image. Please set the root password ASAP."
		echo "Removing root password"
		passwd -d root || die "Failed removing root password"
		echo "Running systemd-firstboot"
		systemd-firstboot --timezone=UTC || die "Failed running systemd-firstboot"
		configure_dhcp
		;;
	ssh)
		echo "Setting up ssh log-in image, using the following key"
		echo "  ${clst_diskimage_sshkey}"
		echo "Running systemd-firstboot"
		systemd-firstboot --timezone=UTC || die "Failed running systemd-firstboot"
		configure_dhcp
		configure_sshd
		echo "Adding sshd service"
		systemctl enable sshd
		;;
	cloud-init|cloudinit)
		echo "Setting up cloud-init image"
		echo "Running systemd-firstboot"
		systemd-firstboot --timezone=UTC || die "Failed running systemd-firstboot"
		;;
	*)
		die "As yet unsupported image type"
		;;
esac

else

# We are using OpenRC.

die "OpenRC is as yet unsupported."

fi

# all done
# (we can't install the boot loader here because nothing is mounted)