summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorP. J. McDermott <pjm@nac.net>2012-01-29 18:37:15 (EST)
committer P. J. McDermott <pjm@nac.net>2012-01-29 18:37:49 (EST)
commit424bc4790dcb87344ee04f42c7e573d8c820cfc2 (patch)
treefe607eca9630c81940a05b23a411363d0a3a90b9 /src
parentccf93046965031cf3744d3cd17810919b64f8d78 (diff)
Write oh-copyconfig.
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.in4
-rw-r--r--src/oh-copyconfig79
2 files changed, 81 insertions, 2 deletions
diff --git a/src/Makefile.in b/src/Makefile.in
index 45be948..77541c0 100644
--- a/src/Makefile.in
+++ b/src/Makefile.in
@@ -27,8 +27,8 @@ BINDIR = @bindir@
.SUFFIXES:
-OBJS = opkbuild oh-checkbuilddeps oh-applypatches oh-strip \
- oh-installfiles oh-gencontrol oh-buildopk
+OBJS = opkbuild oh-checkbuilddeps oh-applypatches oh-copyconfig \
+ oh-strip oh-installfiles oh-gencontrol oh-buildopk
.PHONY: all
all: $(OBJS)
diff --git a/src/oh-copyconfig b/src/oh-copyconfig
new file mode 100644
index 0000000..e880392
--- /dev/null
+++ b/src/oh-copyconfig
@@ -0,0 +1,79 @@
+#! /bin/sh
+#
+# 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/>.
+
+print_usage()
+{
+ printf 'Usage: %s\n' "$1"
+}
+
+error()
+{
+ printf 'oh-copyconfig: Error: %s\n' "${1}" >&2
+ exit 1
+}
+
+if [ ! -f ../config ]; then
+ printf 'oh-copyconfig: No config files to copy.\n'
+ exit 0
+fi
+
+if [ -z "${OH_PLATFORM}" ]; then
+ 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
+ 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}"
+ ;;
+ *)
+ error "Invalid config type \"${type}\""
+ ;;
+ esac
+ # Make sure the destination directory exists.
+ mkdir -p "$(dirname "${full_dest}")"
+ # Find the config package files.
+ if [ -d "/usr/share/config/${OH_PLATFORM}/${OH_SRCPKG}-${OH_PKGVER}" ]; then
+ full_src="/usr/share/config/${OH_PLATFORM}/${OH_SRCPKG}-${OH_PKGVER}/${src}"
+ elif [ -d "/usr/share/config/${OH_PLATFORM}/${OH_SRCPKG}" ]; then
+ full_src="/usr/share/config/${OH_PLATFORM}/${OH_SRCPKG}/${src}"
+ else
+ # This shouldn't happen unless the package maintainer neglected to add
+ # the config package to the package's Build-Depends field.
+ error 'No platform config directory found'
+ fi
+ # Copy the config file(s).
+ printf 'oh-copyconfig: Copying "%s" to "%s"...\n' "${src}" "${dest}"
+ cp -p "${full_src}" "${full_dest}" || error "Cannot copy \"${src}\""
+done < ../config