From 11f45e92ad0197f90a70dd27bee470513c683a0f Mon Sep 17 00:00:00 2001 From: P. J. McDermott Date: Wed, 03 Oct 2012 16:13:34 -0400 Subject: Implement ob-unpacksource. --- diff --git a/locale/en_US/opkbuild.sh b/locale/en_US/opkbuild.sh index 87b7d74..9f6705a 100644 --- a/locale/en_US/opkbuild.sh +++ b/locale/en_US/opkbuild.sh @@ -61,3 +61,15 @@ msg_opkbuild_cant_rm_src_pkg_data='Can'\''t clean up data directory for source p # ob-buildenv msg_opkbuild_setup_build_env='Setting up build environment...' + +# ob-unpacksource +msg_opkbuild_unpacking_native='Copying native source directory...' +msg_opkbuild_cant_unpack_native='Can'\''t copy native source directory' +msg_opkbuild_no_sources='No native or upstream sources found' +msg_opkbuild_multiple_upstream_sources='Multiple upstream source archives found' +msg_opkbuild_unsupported_archive_compression='Compression format with extension "%s" nsupported' +msg_opkbuild_no_upstream_dirs='No directories found in upstream source archive' +msg_opkbuild_multiple_top_upstream_dirs='Multiple top-level directories found in upstream source archive' +msg_opkbuild_unpacking_upstream='Extracting upstream source archive...' +msg_opkbuild_cant_unpack_upstream='Can'\''t extract upstream source archive' +msg_opkbuild_cant_move_native='Can'\''t move extracted upstream source directory' diff --git a/src/Makefile.in b/src/Makefile.in index 9567306..3d02603 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -38,8 +38,8 @@ sed_script = s&@@PACKAGE_NAME@@&$(package_name)&;\ SRCS = opkbuild.sh \ ob-checkbuilddeps.sh \ - ob-buildenv.sh #\ - ob-unpacksource.sh \ + ob-buildenv.sh \ + ob-unpacksource.sh #\ ob-applypatches.sh \ ob-installplatconf.sh \ ob-installdocs.sh \ diff --git a/src/ob-unpacksource.sh b/src/ob-unpacksource.sh new file mode 100644 index 0000000..8b3a01e --- /dev/null +++ b/src/ob-unpacksource.sh @@ -0,0 +1,124 @@ +#!@@SH@@ +# +# opkbuild +# src/ob-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 . + +. '@@LIBOPKBUILD@@/load.sm' + +ob_use locale +ob_use output +ob_use package + +upstream_archive_base= +upstream_archive= +upstream_archive_z= +upstream_archive_dir= + +main() +{ + ob_set_text_domain 'opkbuild' + + ob_init_package '..' + ob_parse_package_metadata -c '.opkbuild.cache' + + if [ -d ../src ]; then + unpack_native + else + unpack_upstream + fi +} + +unpack_native() +{ + ob_info "$(ob_get_msg 'unpacking_native')" + cp -Rp ../src src || ob_error "$(ob_get_msg 'cant_unpack_native')" +} + +unpack_upstream() +{ + get_upstream_archive + get_upstream_compression + get_upstream_dir + extract_upstream +} + +get_upstream_archive() +{ + upstream_archive_base="${OB_SOURCE}-${OB_SOURCE_VERSION_UPSTREAM}.orig.tar." + upstream_archive="$(find .. -name "${upstream_archive_base}*")" + case "$(echo "${upstream_archive}" | grep -v '^$' | wc -l)" in + 0) + ob_error "$(ob_get_msg 'no_sources')" + ;; + 1) + ;; + *) + ob_error "$(ob_get_msg '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' + ;; + *) + ob_error "$(ob_get_msg 'unsupported_archive_compression')" \ + "${z_ext}" + ;; + esac +} + +get_upstream_dir() +{ + upstream_archive_dir="$(tar "-t${upstream_archive_z}f" \ + "${upstream_archive}" | sed -n 's@^\(\./\|\)\([^/]*\)\(/\|\)$@\2@p')" + case "$(echo "${upstream_archive_dir}" | grep -v '^$' | wc -l)" in + 0) + ob_error "$(ob_get_msg 'no_upstream_dirs')" + ;; + 1) + ;; + *) + ob_error "$(ob_get_msg 'multiple_top_upstream_dirs')" + esac +} + +extract_upstream() +{ + ob_info "$(ob_get_msg 'unpacking_upstream')" + tar "-x${upstream_archive_z}f" "${upstream_archive}" || \ + ob_error "$(ob_get_msg 'cant_unpack_upstream')" + mv "${upstream_archive_dir}" src || \ + ob_error "$(ob_get_msg 'cant_move_native')" +} + +main "${@}" -- cgit v0.9.1