diff options
author | P. J. McDermott <pjm@nac.net> | 2012-07-31 21:23:56 (EDT) |
---|---|---|
committer | P. J. McDermott <pjm@nac.net> | 2012-07-31 21:23:56 (EDT) |
commit | e93df698ad3c5172cf1157a8c72978b427fc0aa8 (patch) | |
tree | 897656b7fa29616bdd4a54021ff966fee323a543 | |
parent | 710ca0fbb707828b9317dc09686b0accc0d6a5d6 (diff) |
Write oh-unpacksource.
-rw-r--r-- | locale/en_US.sh | 8 | ||||
-rw-r--r-- | src/oh-unpacksource.sh | 117 | ||||
-rw-r--r-- | src/opkbuild.sh | 53 |
3 files changed, 123 insertions, 55 deletions
diff --git a/locale/en_US.sh b/locale/en_US.sh index 80c0129..b7d730a 100644 --- a/locale/en_US.sh +++ b/locale/en_US.sh @@ -69,6 +69,11 @@ oh_str_arch_stat_plat=' Platform: %s' oh_str_host_arch_stat_header='Host system:' oh_str_cant_make_work_area='Can'\''t make work area' oh_str_cant_enter_work_area='Can'\''t enter work area' +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-unpacksource strings: oh_str_unpacking_native='Copying native source directory...' oh_str_cant_unpack_native='Can'\''t copy native source directory' oh_str_no_sources='No native or upstream sources found' @@ -79,6 +84,3 @@ oh_str_multiple_top_upstream_dirs='Multiple top-level directories found in upstr oh_str_unpacking_upstream='Extracting upstream source archive...' oh_str_cant_unpack_upstream='Can'\''t extract upstream source archive' oh_str_cant_move_native='Can'\''t move extracted upstream source directory' -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' diff --git a/src/oh-unpacksource.sh b/src/oh-unpacksource.sh new file mode 100644 index 0000000..128d85a --- /dev/null +++ b/src/oh-unpacksource.sh @@ -0,0 +1,117 @@ +#!@@SHELL@@ +# +# opkhelper +# src/oh-unpacksource +# Unpack native or upstream source. +# +# 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@@/messages +. @@LIBDIR@@/locale + +# Global parameters: +UPSTREAM_ARCHIVE_BASE= +UPSTREAM_ARCHIVE= +UPSTREAM_ARCHIVE_Z= +UPSTREAM_ARCHIVE_DIR= + +main() +{ + oh_locale_set + + if [ -d ../src ]; then + unpack_native + else + unpack_upstream + fi +} + +unpack_native() +{ + oh_info "${oh_str_unpacking_native}" + cp -Rp ../src src || oh_error "${oh_str_cant_unpack_native}" +} + +unpack_upstream() +{ + get_upstream_archive + get_upstream_compression + get_upstream_dir + extract_upstream +} + +get_upstream_archive() +{ + UPSTREAM_ARCHIVE_BASE="${OH_SOURCE}-${OH_SOURCE_VERSION_UPSTREAM}.orig.tar." + UPSTREAM_ARCHIVE=$(find .. -name "${UPSTREAM_ARCHIVE_BASE}*") + case "$(echo "${UPSTREAM_ARCHIVE}" | grep -v '^$' | wc -l)" in + 0) + oh_error "${oh_str_no_sources}" + ;; + 1) + ;; + *) + oh_error "${oh_str_multiple_upstream_sources}" + ;; + esac +} + +get_upstream_compression() +{ + z_ext="${UPSTREAM_ARCHIVE#../${UPSTREAM_ARCHIVE_BASE}}" + case "${z_ext}" in + gz) + UPSTREAM_ARCHIVE_Z=z + ;; + bz2) + UPSTREAM_ARCHIVE_Z=j + ;; + lz) + UPSTREAM_ARCHIVE_Z=a + ;; + Z) + UPSTREAM_ARCHIVE_Z=Z + ;; + *) + oh_error "${oh_str_unsupported_archive_compression}" "${z_ext}" + ;; + esac +} + +get_upstream_dir() +{ + UPSTREAM_ARCHIVE_DIR=$(tar "-t${UPSTREAM_ARCHIVE_Z}f" \ + "${UPSTREAM_ARCHIVE}" | sed -n 's@^\./\([^/]*\)$@\1@p') + case "$(echo "${UPSTREAM_ARCHIVE_DIR}" | grep -v '^$' | wc -l)" in + 0) + oh_error "${oh_str_no_upstream_dirs}" + ;; + 1) + ;; + *) + oh_error "${oh_str_multiple_top_upstream_dirs}" + esac +} + +extract_upstream() +{ + oh_info "${oh_str_unpacking_upstream}" + tar "-x${UPSTREAM_ARCHIVE_Z}f" "${UPSTREAM_ARCHIVE}" || \ + oh_error "${oh_str_cant_unpack_upstream}" + mv "${UPSTREAM_ARCHIVE_DIR}" src || oh_error "${oh_str_cant_move_native}" +} + +main "${@}" diff --git a/src/opkbuild.sh b/src/opkbuild.sh index 54a22f3..94bc6c7 100644 --- a/src/opkbuild.sh +++ b/src/opkbuild.sh @@ -343,58 +343,7 @@ step_unpack() { oh_cv_set step unpack - # TODO: Put this in oh-unpacksource. - if [ -d ../src ]; then - oh_info "${oh_str_unpacking_native}" - cp -Rp ../src src || oh_error "${oh_str_cant_unpack_native}" - else - archive_base_name="${OH_SOURCE}-${OH_SOURCE_VERSION_UPSTREAM}.orig.tar." - archive_matches=$(find .. -name "${archive_base_name}*") - case "$(echo "${archive_matches}" | wc -l)" in - 0) - oh_error "${oh_str_no_sources}" - ;; - 1) - ;; - *) - oh_error "${oh_str_multiple_upstream_sources}" - ;; - esac - z_ext="${archive_matches#../${archive_base_name}}" - case ${z_ext} in - gz) - z=z - ;; - bz2) - z=j - ;; - lz) - z=a - ;; - Z) - z=Z - ;; - *) - oh_error "${oh_str_unsupported_archive_compression}" "${z_ext}" - ;; - esac - sed 's@^./@@' | grep '^[^/]*/$' - top_dirs=$(tar "-t${z}f" "${archive_matches}${z_ext}" | \ - sed -n 's@^\./\([^/]*\)$@\1@p') - case "$(echo "${top_dirs}" | wc -l)" in - 0) - oh_error "${oh_str_no_upstream_dirs}" - ;; - 1) - ;; - *) - oh_error "${oh_str_multiple_top_upstream_dirs}" - esac - oh_info "${oh_str_unpacking_upstream}" - tar "-x${z}f" "${archive_matches}${z_ext}" || \ - oh_error "${oh_str_cant_unpack_upstream}" - mv "${top_dirs}" src || oh_error "${oh_str_cant_move_native}" - fi + oh-unpacksource step_patch } |