summaryrefslogtreecommitdiffstats
path: root/src/oh-copyconfig.sh
blob: 39b4ba2ddd4f1c5bfb2bcf5ffecdb499727b6ddf (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
#!@@SHELL@@
#
# opkhelper
# src/oh-copyconfig
# Copy build-time or run-time platform configuration files.
#
# Copyright (C) 2012 Patrick "P. J." McDermott
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

. @@LIBDIR@@/opkhelper/messages

print_usage()
{
	printf 'Usage: %s\n' "${1}"
}

if [ ! -f ../config ]; then
	oh_info 'No config files to copy'
	exit 0
fi

if [ -z "${OH_HOST_PLATFORM}" ]; then
	oh_error 'No target platform defined'
fi

if [ ${#} -ne 0 ]; then
	print_usage ${0} >&2
	exit 1
fi

while read -r type src dest; do
	if [ -z "${type}" -o -z "${src}" -o -z "${dest}" ]; then
		oh_error 'Invalid syntax in config list'
	fi
	case "${type}" in
		runtime)
			# The destiest dest that ever dest.
			full_dest="dest${dest}"
			;;
		buildtime)
			# A less desty dest.
			full_dest="${dest}"
			;;
		*)
			oh_error 'Invalid config type "%s"' "${type}"
			;;
	esac
	# Make sure the destination directory exists.
	mkdir -p "$(dirname "${full_dest}")"
	# Find the config package files.
	config_dir_base="/usr/share/config/${OH_HOST_PLATFORM}/${OH_SRCPKG}"
	if [ -d "${config_dir_base}-${OH_PKGVER%%-*}" ]; then
		full_src="${config_dir_base}-${OH_PKGVER%%-*}/${src}"
	elif [ -d "${config_dir_base}" ]; then
		full_src="${config_dir_base}/${src}"
	else
		# This shouldn't happen unless the package maintainer neglected to add
		# the config package to the package's Build-Depends field.
		oh_error 'No platform config directory found'
	fi
	# Copy the config file(s).
	oh_info 'Copying "%s" to "%s"...' "${src}" "${dest}"
	mkdir -p "$(dirname "${full_dest}")"
	cp -p "${full_src}" "${full_dest}" || oh_error 'Cannot copy "%s"' "${src}"
done < ../config