summaryrefslogtreecommitdiffstats
path: root/modules.d/dnbd3-rootfs/hooks/copy-openslx-configuration-into-newroot.sh
blob: 7e2b74e36063940b425956549c3928d4ee2fba50 (plain) (blame)
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
#!/usr/bin/env bash
# -*- coding: utf-8 -*-
type emergency_shell >/dev/null 2>&1 || source /lib/dracut-lib.sh

source "/etc/openslx"

# Merge search domain from server and from dhcp
(
	search="$SLX_NET_SEARCH"
	source /run/openslx/network.conf
	search="$SLX_NET_SEARCH $search" # DHCP > config vars
	declare -a uniq
	declare -A dups # Don't use keys for output later as order is undefined
	for i in $search; do
		[ -n "${dups["$i"]}" ] && continue
		dups["$i"]=1
		uniq+=( "$i" )
	done
	sed -i 's/^SLX_NET_SEARCH=/# &/' "/etc/openslx" "/run/openslx/network.conf"
	echo "SLX_NET_SEARCH='${uniq[*]}'" >> "/run/openslx/network.conf"
	if grep -q '^search' "/etc/resolv.conf"; then
		sed -i "s/^search.*$/search ${uniq[*]}/" "/etc/resolv.conf"
	else
		echo "search ${uniq[*]}" "/etc/resolv.conf"
	fi
)


mkdir --parents "${NEWROOT}/opt/openslx"
cp "/etc/openslx" "${NEWROOT}/opt/openslx/config"

echo "## Generated by '$0' in stage3" >> "${NEWROOT}/opt/openslx/config"
cat "/run/openslx/network.conf" >> "${NEWROOT}/opt/openslx/config"

# Set root/demo password for stage4, if set
if [ -n "${SLX_ROOT_PASS}" ]; then
	sed -i "s#^root:[^:]*:#root:$SLX_ROOT_PASS:#" "$NEWROOT/etc/shadow"
fi
if [ -n "${SLX_DEMO_PASS}" ] && grep -q '^demo' "$NEWROOT/etc/shadow"; then
	sed -i "s#^demo:[^:]*:#demo:$SLX_DEMO_PASS:#" "$NEWROOT/etc/shadow"
fi