aboutsummaryrefslogtreecommitdiff
blob: 83a631344737d4c0b2ca061994c56861cd976644 (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
#!@PORTAGE_BASH@

# for expansion below we need some things to be defined
prefix="@prefix@"
exec_prefix="@exec_prefix@"

# For bug #279550 we have to do some nasty trick to make sure that sed
# doesn't strip the backslash in the replacement value (because it can
# be a backreference) and hence escape those.  Eventually in strings we
# need to escape the backslash too, such that the single backslash
# doesn't get lost when considered an invalid escape
rootuser='@rootuser@'
portagegroup='@portagegroup@'
portageuser='@portageuser@'
rootuser=${rootuser//\\/\\\\}
portagegroup=${portagegroup//\\/\\\\\\\\}
portageuser=${portageuser//\\/\\\\\\\\}

# there are many ways to do this all dynamic, but we only care for raw
# speed here, so let configure fill in this list and be done with it
at='@'
sedexp=(
	-e "s,${at}DEFAULT_PATH${at},@DEFAULT_PATH@,g"
	-e "s,${at}EXTRA_PATH${at},@EXTRA_PATH@,g"
	-e "s,${at}EGREP${at},@EGREP@,g"
	-e "s,${at}PORTAGE_BASE${at},@PORTAGE_BASE@,g"
	-e "s,${at}PORTAGE_BASENAME${at},@PORTAGE_BASENAME@,g"
	-e "s,${at}PORTAGE_BASH${at},@PORTAGE_BASH@,g"
	-e "s,${at}PORTAGE_DIRNAME${at},@PORTAGE_DIRNAME@,g"
	-e "s,${at}PORTAGE_EPREFIX${at},@PORTAGE_EPREFIX@,g"
	-e "s,${at}PORTAGE_FIND${at},@PORTAGE_FIND@,g"
	-e "s,${at}PORTAGE_GREP${at},@PORTAGE_GREP@,g"
	-e "s,${at}PORTAGE_MV${at},@PORTAGE_MV@,g"
	-e "s,${at}PORTAGE_RM${at},@PORTAGE_RM@,g"
	-e "s,${at}PORTAGE_SED${at},@PORTAGE_SED@,g"
	-e "s,${at}PORTAGE_WGET${at},@PORTAGE_WGET@,g"
	-e "s,${at}PORTAGE_XARGS${at},@PORTAGE_XARGS@,g"
	-e "s,${at}PREFIX_PORTAGE_PYTHON${at},@PREFIX_PORTAGE_PYTHON@,g"
	-e "s,${at}datadir${at},@datadir@,g"
	-e "s,${at}portagegroup${at},${portagegroup},g"
	-e "s,${at}portageuser${at},${portageuser},g"
	-e "s,${at}rootgid${at},@rootgid@,g"
	-e "s,${at}rootuid${at},@rootuid@,g"
	-e "s,${at}rootuser${at},${rootuser},g"
	-e "s,${at}sysconfdir${at},@sysconfdir@,g"
)

sources=( )
target=
args=( "$@" )

while [[ ${#@} != 0 ]] ; do
	case "$1" in
		-t)
			[[ -n ${target} ]] && sources=( "${sources[@]}" "${target##*/}" )
			shift
			target=":${1}"
		;;
		-*)
			shift
		;;
		*)
			if [[ -z ${target} ]] ; then
				target="${1}"
			elif [[ ${target} != ":"* ]] ; then
				sources=( "${sources[@]}" "${target##*/}" )
				target="${1}"
			else
				sources=( "${sources[@]}" "${1##*/}" )
			fi
		;;
	esac
	shift
done

target=${target#:}
INSTALL="@INSTALL@"
echo @INSTALL_DATA@ "${args[@]}"
if [[ ! -d ${target} ]] ; then
	# either install will die, or it was just a single file copy
	@INSTALL_DATA@ "${args[@]}" && sed -i "${sedexp[@]}" "${target}"
else
	@INSTALL_DATA@ "${args[@]}" && sed -i "${sedexp[@]}" "${sources[@]/#/${target}/}"
fi