summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorP. J. McDermott <pjm@nac.net>2012-09-28 08:44:49 (EDT)
committer P. J. McDermott <pjm@nac.net>2012-09-28 08:44:49 (EDT)
commit962fb7438afe046fa12b0b02129340ae0e6c4ed3 (patch)
tree46cc9458ee0407441c1a8da1c43e43d4a63a7943
parent78cb303f9f9c29f5290e23b7370ad53f9486e759 (diff)
Implement much of the "package" library modules.
-rw-r--r--lib/package.sh301
-rw-r--r--lib/package/2.sh52
2 files changed, 353 insertions, 0 deletions
diff --git a/lib/package.sh b/lib/package.sh
new file mode 100644
index 0000000..938d67c
--- /dev/null
+++ b/lib/package.sh
@@ -0,0 +1,301 @@
+# opkbuild
+# lib/package
+# Interface for retrieving source and binary package metadata.
+#
+# 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/>.
+
+[ -n "${_OB_PACKAGE_SM}" ] && return 0
+_OB_PACKAGE_SM='true'
+
+_OB_PACKAGE_DIR=
+_OB_PACKAGE_FORMAT=
+_OB_BINARY_PACKAGES=
+_OB_SOURCE_PARAMETERS=
+_OB_BINARY_PARAMETERS=
+
+ob_init_package()
+{
+ _ob_local _obip_dir _obip_orig_text_domain
+
+ if [ ${#} -eq 1 ]; then
+ _obip_dir="${1}"
+ else
+ _ob_return 125
+ return ${?}
+ fi
+
+ _OB_PACKAGE_DIR="${_obip_dir}"
+
+ if [ -r "${_OB_PACKAGE_DIR}/format" ]; then
+ case "$(cat "${_OB_PACKAGE_DIR}/format")" in
+ 2.0)
+ _OB_PACKAGE_FORMAT='2'
+ ;;
+ esac
+ fi
+
+ if [ -z "${_OB_PACKAGE_FORMAT}" ]; then
+ _obip_orig_text_domain="$(ob_get_text_domain)"
+ ob_set_text_domain 'libopkbuild.1'
+ ob_warn "$(ob_get_msg 'unable_to_detect_package_format')"
+ ob_set_text_domain "${_obip_orig_text_domain}"
+ _ob_return 1
+ return ${?}
+ fi
+
+ ob_use "package/${_OB_PACKAGE_FORMAT}"
+
+ _OB_BINARY_PACKAGES=
+
+ _ob_return 0
+ return ${?}
+}
+
+ob_parse_package_metadata()
+{
+ _ob_local _obppm_opt _obppm_cache_file _obppm_param
+
+ while getopts 'c:' _obppm_opt; do
+ case "${_obppm_opt}" in
+ c)
+ _obppm_cache_file="${OPTARG}"
+ ;;
+ ?)
+ _ob_return 125
+ return ${?}
+ ;;
+ esac
+ done
+ shift $(($OPTIND - 1))
+
+ if [ ${#} -gt 0 ]; then
+ _ob_return 125
+ return ${?}
+ fi
+
+ _ob_package_do 'parse_package_metadata'
+
+ if [ -n "${_obppm_cache_file}" ]; then
+ # FIXME: Finish.
+ for _obppm_param in ${_OB_SOURCE_PARAMETERS}; do
+ foo="$(echo "${foo}" | sed "s/'/'\\\\''/g")"
+ >>"${_obppm_cache_file}"
+ done
+ for _obppm_param in ${_OB_SOURCE_PARAMETERS}; do
+ :
+ done
+ fi
+
+ _ob_return 0
+ return ${?}
+}
+
+ob_get_binary_packages()
+{
+ _ob_local _obgbpk_opt _obgbpk_host_arch _obgbpk_pkgs
+
+ while getopts 'a:' _obgbpk_opt; do
+ case "${_obgbpk_opt}" in
+ a)
+ _obgbpk_host_arch="${OPTARG}"
+ ;;
+ ?)
+ _ob_return 125
+ return ${?}
+ ;;
+ esac
+ done
+ shift $(($OPTIND - 1))
+
+ if [ ${#} -gt 0 ]; then
+ _ob_return 125
+ return ${?}
+ fi
+
+ # NB: If a source package lists no binary packages, this will be true each
+ # call.
+ if [ -z "${_OB_BINARY_PACKAGES}" ]; then
+ _ob_package_do 'get_binary_packages'
+ fi
+
+ if [ -n "${_obgbpk_host_arch}" ]; then
+ for _obgbpk_pkg in ${_OB_BINARY_PACKAGES}; do
+ if ob_match_arch "${_obgbpk_host_arch}" "$(ob_get_binary_parameter \
+ "${_obgbpk_pkg}" 'Architecture')"; then
+ _obgbpk_pkgs="${_obgbpk_pkgs} ${_obgbpk_pkg}"
+ fi
+ done
+ else
+ _obgbpk_pkgs="${_OB_BINARY_PACKAGES}"
+ fi
+
+ IFS=' ' echo ${_obgbpk_pkgs}
+
+ _ob_return 0
+ return ${?}
+}
+
+ob_get_source_parameter()
+{
+ _ob_local _obgsp_name
+
+ if [ ${#} -eq 1 ]; then
+ _obgsp_name="${1}"
+ else
+ _ob_return 125
+ return ${?}
+ fi
+
+ # Convert field name to uppercase and validate.
+ _obgsp_name="$(echo "${_obgsp_name}" | tr 'a-z-' 'A-Z_')"
+ case "${_obgsp_name:- }" in
+ *[!A-Z0-9_]*)
+ _ob_return 125
+ return ${?}
+ ;;
+ esac
+
+ eval echo "\"\$\{_OB_SRCFIELD_${_obgsp_name}\}\""
+
+ _ob_return 0
+ return ${?}
+}
+
+ob_get_binary_parameter()
+{
+ _ob_local _obgbp_package _obgbp_name
+
+ if [ ${#} -eq 2 ]; then
+ _obgbp_package="${1}"
+ _obgbp_name="${2}"
+ else
+ _ob_return 125
+ return ${?}
+ fi
+
+ if ! ob_validate_binary_package_name "${_obgbp_package}"; then
+ _ob_return 125
+ return ${?}
+ fi
+
+ # Convert package name to its uppercase "clean" form.
+ _obgbp_package="$(echo "${_obgbp_package}" | tr 'a-z' 'A-Z' | \
+ tr -dC 'A-Z0-9')"
+
+ # Convert field name to uppercase and validate.
+ _obgbp_name="$(echo "${_obgbp_name}" | tr 'a-z-' 'A-Z_')"
+ case "${_obgbp_name:- }" in
+ *[!A-Z0-9_]*)
+ _ob_return 125
+ return ${?}
+ ;;
+ esac
+
+ eval echo "\"\$\{_OB_BINFIELD_${_obgbp_package}_${_obgbp_name}\}\""
+
+ _ob_return 0
+ return ${?}
+}
+
+ob_summarize_package_arch()
+{
+ _ob_local
+
+ if [ ${#} -gt 0 ]; then
+ _ob_return 125
+ return ${?}
+ fi
+
+ # XXX: Stub.
+
+ _ob_return 0
+ return ${?}
+}
+
+ob_summarize_package_plat()
+{
+ _ob_local
+
+ if [ ${#} -gt 0 ]; then
+ _ob_return 125
+ return ${?}
+ fi
+
+ # XXX: Stub.
+
+ _ob_return 0
+ return ${?}
+}
+
+_ob_package_do()
+{
+ _ob_local _obpd_func
+
+ _obpd_func="${1}"
+ shift 1
+
+ "_ob_${_obpd_func}_${_OB_PACKAGE_FORMAT}" "${@}"
+
+ _ob_return 0
+ return ${?}
+}
+
+_ob_set_binary_packages()
+{
+ _ob_local _obsbpk_packages
+
+ _obsbpk_packages="${1}"
+
+ _OB_BINARY_PACKAGES="${_obsbpk_packages}"
+
+ _ob_return 0
+ return ${?}
+}
+
+_ob_set_source_parameter()
+{
+ _ob_local _obssp_name _obssp_value
+
+ _obssp_name="${1}"
+ _obssp_value="${2}"
+
+ # FIXME: Name transformation and validation?
+
+ _OB_SOURCE_PARAMETERS="${_OB_SOURCE_PARAMETERS} ${_obssp_name}"
+
+ # Escape the value.
+ _obssp_value="$(echo "${_obssp_value}" | sed "s/'/'\\\\''/g")"
+
+ eval "_OB_SRCFIELD_${_obssp_name}=${_obssp_value}"
+}
+
+_ob_set_binary_parameter()
+{
+ _ob_local _obsbp_package _obsbp_name _obsbp_value
+
+ _obsbp_package="${1}"
+ _obsbp_name="${2}"
+ _obsbp_value="${3}"
+
+ # FIXME: Name transformation and validation?
+
+ _OB_BINARY_PARAMETERS="${_OB_BINARY_PARAMETERS} ${_obsbp_name}"
+
+ # Escape the value.
+ _obsbp_value="$(echo "${_obsbp_value}" | sed "s/'/'\\\\''/g")"
+
+ eval "_OB_BINFIELD_${_obsbp_package}_${_obsbp_name}=${_obsbp_value}"
+}
diff --git a/lib/package/2.sh b/lib/package/2.sh
new file mode 100644
index 0000000..99397f2
--- /dev/null
+++ b/lib/package/2.sh
@@ -0,0 +1,52 @@
+# opkbuild
+# lib/package/2
+# Functions for retrieving metadata from packages in SPF 2.0.
+#
+# 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/>.
+
+[ -n "${_OB_PACKAGE_2_SM}" ] && return 0
+_OB_PACKAGE_2_SM='true'
+
+_ob_parse_package_metadata_2()
+{
+ _ob_local
+
+ # XXX: Stub.
+
+ _ob_return 0
+ return ${?}
+}
+
+_ob_get_binary_packages_2()
+{
+ _ob_local _obgbp2_pkgs _obgbp2_pkg_control
+
+ for _obgbp2_pkg_control in "${_OB_PACKAGE_DIR}/"*'.pkg/control'; do
+
+ _obgbp2_pkg_control="${_obgbp2_pkg_control%.pkg/control}"
+ _obgbp2_pkg_control="${_obgbp2_pkg_control##*/}"
+
+ ob_validate_binary_name "${_obgbp2_pkg_control}"
+
+ _obgbp2_pkgs="${_obgbp2_pkgs} ${_obgbp2_pkg_control}"
+
+ done
+
+ _ob_set_binary_packages "${_obgbp2_pkgs}"
+
+ _ob_return 0
+ return ${?}
+}