summaryrefslogtreecommitdiffstats
path: root/builder/modules.d/conf-tgz/hooks/unpack-config-tgz.sh
blob: 1516ed3edd0d5d255d137f0cf9eff160f32cc97a (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
42
43
44
45
46
47
48
49
#!/usr/bin/env bash
# -*- coding: utf-8 -*-

type emergency_shell >/dev/null 2>&1 || source /lib/dracut-lib.sh

# tarcopy <source_dir> <target_dir>
tarcopy() {
	[ -d "$1" -a -d "$2" ] || return 1
	cd "$1"
	local filelist="$(mktemp)"
	find . \! -type d > "$filelist"
	tar -c -p -T "$filelist" | tar -xp -C "$2"
	rm -f -- "$filelist"
	cd - &>/dev/null
}

unpack_config_tgz() {
	local config_tgz="/etc/config.tgz"
	[ -e "$config_tgz" ] || return 1
	local extract_dir="$(mktemp -d)"
	tar --extract --preserve-permissions \
		--file="/etc/config.tgz" \
		--directory="$extract_dir"
	if [ "$?" -ne 0 ]; then
		warn "Failed to extract '$config_tgz' to '$extract_dir'."
		return 1
	fi
	# check SLX_LOCAL_CONFIGURATION
	source "/etc/openslx"
	if [ -n "$SLX_LOCAL_CONFIGURATION" ]; then
		if [ ! -d "${extract_dir}/openslx-configs/${SLX_LOCAL_CONFIGURATION}" ]; then
			logging.warn "Ignoring missing SLX_LOCAL_CONFIGURATION in '/etc/config.tgz'."
		else
			tarcopy \
				"${temporary_extract_directory}/openslx-configs/${SLX_LOCAL_CONFIGURATION}" \
				"${temporary_extract_directory}"
		fi
	fi
	# always purge openslx-configs/
	rm -rf "${temporary_extract_directory}/openslx-configs"

	# finally copy the rest into stage4
	if ! tarcopy "${temporary_extract_directory}" "$NEWROOT"; then
		warn "'tarcopy' from '$temporary_extract_directory' to '$NEWROOT' failed."
	fi
}

unpack_config_tgz
: