summarylogtreecommitdiffstats
path: root/fulfill_template.sh
blob: 21c3010f901007c7f2e86a276a60beda2481691f (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
#!/bin/sh
#
# Usage:
#	./fulfill_template.sh OEM_FILE TEMPLATE_FILE OUTPUT_FILE
#

_OEMFILE_="${1}"
_TEMPLATE_="${2}"
_OUTPUT_="${3}"

[ -z "${_TEMPLATE_}" -o -z "${_OUTPUT_}" -o -z "${_OEMFILE_}" ] && return 1


# Taken from uld/noarch/package_utils -> get_oem_field()

_get_oem_field() {
	[ -z "${1}" ] && return 1
	grep "^${1}=" "${_OEMFILE_}" 2>/dev/null | sed 's/\"//g' | sed "s/${1}=\(.*\)/\1/"
}


# Template files can use tab() function to insert '\t' symbol
# Taken from uld/noarch/scanner-script.pkg -> fill_full_template()

tab2() {
	# ${1} - number of tabs inserted
	local amount=${1}
	if [ -z "${amount}" ] ; then
		amount="1";
	fi
	for i in $(seq 1 ${amount}) ; do
		echo -n "    "
	done
}

tab() {
	# ${1} - number of tabs inserted
	local amount=${1}
	if [ -z "${amount}" ] ; then
		amount="1";
	fi
	for i in $(seq 1 ${amount}) ; do
		echo -n "    "
	done
}


# Callback variables

VID="$(_get_oem_field 'VID')"
PIDS="$(_get_oem_field 'PIDS')"


# Other variables

_TMP_FILE_="$(mktemp -t 'tmp_file.XXXX')"


# Script body

while read line; do
	eval echo \"${line}\" >> "${_TMP_FILE_}"
done < "${_TEMPLATE_}"

install -Dm755 "${_TMP_FILE_}" "${_OUTPUT_}"
rm "${_TMP_FILE_}"


# EOF