File: debconf-set-selections

package info (click to toggle)
preseed 1.102
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 812 kB
  • sloc: sh: 435; perl: 153; makefile: 5
file content (94 lines) | stat: -rwxr-xr-x 2,033 bytes parent folder | download | duplicates (6)
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
#!/bin/sh
set -e

OLDIFS="$IFS"
CR=$(echo -en "\r")
NL="
"

export DEBIAN_FRONTEND=none
. /usr/share/debconf/confmodule
. /lib/preseed/preseed.sh

SEEN=1
if [ "$1" = --unseen ]; then
	SEEN=
	shift
fi

file="$1"

parse_error() {
	echo "$1" >> $logfile
	log "Error parsing preconfiguration file; see '$logfile' for details"
	exit 1
}

# Returns the first field in the current line
first_field() {
	echo "$line" | grep -q "[[:space:]]" || return 1
	echo "$line" | sed -r 's/^([^[:space:]]*).*/\1/'
}
# Returns any fields after the first field in the current line
rest_line() {
	if echo "$line" | grep -q "[[:space:]]"; then
		echo "$line" | sed 's/^[^[:space:]]*[[:space:]]*//'
	fi
}

IFS="$NL"
multiline=""
# TODO: this squashes \r elsewhere in the line too
for line in $(grep -v '^#\|^[[:space:]]*$' "$file" | sed "s/$CR//g"); do
	IFS="$OLDIFS"
	
	line="$(echo "$line" | sed 's/^[[:space:]]*//')"
	if echo "$line" | grep -q '\\$'; then
		multiline="${multiline:+$multiline }$(echo "$line" | \
			sed 's/[[:space:]]*\\$//')"
		continue
	elif [ -n "$multiline" ]; then
		line="$multiline $line"
		multiline=""
	fi
	
	echo "$line" >> $logfile

	package=""
	var=""
	type=""
	val=""
	if ! package="$(first_field)"; then
		parse_error "Syntax error: unable to determine template owner"
	fi
	line="$(rest_line)"
	if ! var="$(first_field)"; then
		parse_error "Syntax error: unable to determine template name"
	fi
	line="$(rest_line)"
	if ! type="$(first_field)"; then
		# Allow for lines without separator before an empty value
		if [ "$line" ]; then
			type="$line"
		else
			parse_error "Syntax error: unable to determine template type"
		fi
	fi
	line="$(rest_line)"
	val="$line"

	if [ "$type" = seen ]; then
		# Set seen flag.
		db_fset "$var" "$type" "$val" || true # how to handle this error?
	else
		if ! db_set "$var" "$val"; then
			# Question does not exist yet.
			db_register debian-installer/dummy "$var"
			db_set "$var" "$val"
			db_subst "$var" ID "$var"
		fi
		if [ "$SEEN" ]; then
			db_fset "$var" seen true
		fi
	fi
done