From f3cb9916675ee2270fefd6e8eff676c78914e4d7 Mon Sep 17 00:00:00 2001 From: P. J. McDermott Date: Tue, 31 Jul 2012 21:59:53 -0400 Subject: Rewrite oh-copyconfig. --- diff --git a/locale/en_US.sh b/locale/en_US.sh index 3b14cc8..479c65f 100644 --- a/locale/en_US.sh +++ b/locale/en_US.sh @@ -89,3 +89,12 @@ oh_str_usage_oh_applypatches='Usage: oh-applypatches' oh_str_applying_patch='Applying patch "%s"...' oh_str_cant_apply_patch='Can'\''t apply patch "%s"' oh_str_no_patches='No patches to be applied' + +# oh-copyconfig strings: +oh_str_usage_oh_copyconfig='Usage: oh-copyconfig' +oh_str_no_config='No config files to be copied' +oh_str_bad_config_syntax='Syntax error in platform configuration file list "%s"' +oh_str_cant_make_config_dest_dir='Can'\''t make directory "%s" for platform configuration' +oh_str_no_config_dir='No platform configuration files found' +oh_str_copying_config_file='Copying configuration file "%s" to "%s"...' +oh_str_cant_copy_config_file='Can'\''t copy configuration file' diff --git a/src/oh-copyconfig.sh b/src/oh-copyconfig.sh index 39b4ba2..9d6e645 100644 --- a/src/oh-copyconfig.sh +++ b/src/oh-copyconfig.sh @@ -19,59 +19,62 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -. @@LIBDIR@@/opkhelper/messages +. @@LIBDIR@@/messages +. @@LIBDIR@@/locale -print_usage() +main() { - printf 'Usage: %s\n' "${1}" -} - -if [ ! -f ../config ]; then - oh_info 'No config files to copy' - exit 0 -fi + oh_locale_set -if [ -z "${OH_HOST_PLATFORM}" ]; then - oh_error 'No target platform defined' -fi + if [ "${#}" -ne 0 ]; then + oh_usage + exit 1 + fi -if [ ${#} -ne 0 ]; then - print_usage ${0} >&2 - exit 1 -fi + copied=false -while read -r type src dest; do - if [ -z "${type}" -o -z "${src}" -o -z "${dest}" ]; then - oh_error 'Invalid syntax in config list' + if [ -f ../config ]; then + copy_config config '.' + copied=true 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 + + for bin_config in ../*.pkg/config; do + copy_config "${bin_config#../}" 'dest' + copied=true + done + + "${copied}" || oh_info "${oh_str_no_config}" +} + +copy_config() +{ + list="${1}" + dest_base="${2}" + + while read -r src dest; do + if [ -z "${src}" -o -z "${dest}" ]; then + oh_error "${oh_str_bad_config_syntax}" "${list}" + fi + # Make sure the destination directory exists. + mkdir -p "${dest_base}/${dest%/*}" || \ + oh_error "${oh_str_cant_make_config_dest_dir}" "${dest%/*}" + # Find the config package files. + # TODO: Don't hardcode path. + config_dir_base="/usr/share/config/${OH_HOST_PLATFORM}/${OH_SOURCE}" + if [ -d "${config_dir_base}-${OH_SOURCE_VERSION_UPSTREAM}" ]; then + src_base="${config_dir_base}-${OH_SOURCE_VERSION_UPSTREAM}" + elif [ -d "${config_dir_base}" ]; then + src_base="${config_dir_base}" + else + # This shouldn't happen unless the package maintainer neglected to + # add the config package to the package's Build-Depends field. + oh_error "${oh_str_no_config_dir}" + fi + # Copy the config file(s). + oh_info "${oh_str_copying_config_file}" "${src}" "${dest}" + cp -p "${src_base}/${src}" "${dest_base}/${dest}" || \ + oh_error "${oh_str_cant_copy_config_file}" + done <"../${list}" +} + +main "${@}" diff --git a/src/opkbuild.sh b/src/opkbuild.sh index c3ae895..80921c1 100644 --- a/src/opkbuild.sh +++ b/src/opkbuild.sh @@ -375,57 +375,7 @@ step_platconf() { oh_cv_set step platconf - # TODO: Put this in oh-copyconfig. - if [ -f ../config ]; then - while read -r src dest; do - if [ -z "${src}" -o -z "${dest}" ]; then - oh_error - fi - # Make sure the destination directory exists. - mkdir -p "${dest%/*}" || oh_error - # Find the config package files. - # TODO: Don't hardcode path. - config_dir_base="/usr/share/config/${OH_HOST_PLATFORM}/${OH_SOURCE}" - if [ -d "${config_dir_base}-${OH_SOURCE_VERSION_UPSTREAM}" ]; then - src_base="${config_dir_base}-${OH_SOURCE_VERSION_UPSTREAM}" - elif [ -d "${config_dir_base}" ]; then - src_base="${config_dir_base}" - else - # This shouldn't happen unless the package maintainer neglected - # to add the config package to the package's Build-Depends - # field. - oh_error - fi - # Copy the config file(s). - oh_info - cp -p "${src_base}/${src}" "${dest}" || oh_error - done <../config - fi - for bin_config in ../*.pkg/config; do - while read -r src dest; do - if [ -z "${src}" -o -z "${dest}" ]; then - oh_error - fi - # Make sure the destination directory exists. - mkdir -p "dest/${dest%/*}" || oh_error - # Find the config package files. - # TODO: Don't hardcode path. - config_dir_base="/usr/share/config/${OH_HOST_PLATFORM}/${OH_SOURCE}" - if [ -d "${config_dir_base}-${OH_SOURCE_VERSION_UPSTREAM}" ]; then - src_base="${config_dir_base}-${OH_SOURCE_VERSION_UPSTREAM}" - elif [ -d "${config_dir_base}" ]; then - src_base="${config_dir_base}" - else - # This shouldn't happen unless the package maintainer neglected - # to add the config package to the package's Build-Depends - # field. - oh_error - fi - # Copy the config file(s). - oh_info - cp -p "${src_base}/${src}" "dest/${dest}" || oh_error - done <"${bin_config}" - done + oh-copyconfig step_build } -- cgit v0.9.1