summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaron Ball <nullspoon@oper.io>2017-06-29 23:53:02 -0600
committerAaron Ball <nullspoon@oper.io>2017-06-29 23:53:02 -0600
commit9f9f56299cc2d39c8d328d96018c489e6703744d (patch)
treebc9c6048d279f37a0deff784df61b134dc57f6e0
parenta224d4e77ec027718a37dea8b1503fe6f512611d (diff)
parentc7c50b6527999dca23444e97a027d839075c26ce (diff)
downloadportimg-9f9f56299cc2d39c8d328d96018c489e6703744d.tar.gz
portimg-9f9f56299cc2d39c8d328d96018c489e6703744d.tar.xz
Merge branch 'pkgmk-refactor'
* pkgmk-refactor: Refactored pkgmk.sh and libpkg libport:Added port_download_src function
-rwxr-xr-xbin/pkgmk.sh63
-rw-r--r--lib/pkg.sh71
-rw-r--r--lib/port.sh30
3 files changed, 102 insertions, 62 deletions
diff --git a/bin/pkgmk.sh b/bin/pkgmk.sh
index e0f3d4f..3e7e091 100755
--- a/bin/pkgmk.sh
+++ b/bin/pkgmk.sh
@@ -31,33 +31,54 @@ export PORTSDIR=${PORTSDIR:-${BASEDIR}/ports}
export KEEP_BUILD=${KEEP_BUILD:-0}
function main {
- local _pkg=${1:-}
- [[ -z ${_pkg} ]] && lerror "A port name is required." && return 1
-
- local _porttmp # Path to the port build working directory
- local _pkgfile # Path to the port's Pkgfile
-
- _pkgfile="${PORTSDIR}/${_pkg}/Pkgfile"
-
- if [ ! -f ${_pkgfile} ]; then
- lerror "Could not find Pkgfile at ${_pkgfile}."
+ local _porttmp # Path to the port build working directory
+ local _portdir # Path to the port dir that contains the Pkgfile
+
+ local _pkgname # Pkgfile value for 'name'
+ local _pkgsource # Pkgfile value for 'source'
+ local _pkgversion # Pkgfile value for 'version'
+ local _pkgrelease # Pkgfile value for 'release'
+ local _pkgbuildname # Pkgfile composite of name, version, and release
+ local _porttmp # Temporary working directory to build the pkg
+
+ if [ ! -f Pkgfile ]; then
+ lerror "Could not find Pkgfile."
return 1
fi
- source ${_pkgfile}
+ _portdir="$(pwd)"
- # Set all these variables as the same variables will be set later by port
- # files
- _pkgname=${name} && unset 'name'
- _pkgdepends=("${depends[@]}") && unset 'depends[@]'
- _pkgversion=${version} && unset 'version'
- _pkgrelease=${release} && unset 'release'
+ # Include the port Pkgfile
+ source Pkgfile
+
+ # Set all these variables to local versions, to avoid possible overrides,
+ # conflicts, etc. when these are used later on.
+ _pkgname=${name}
+ _pkgsource=("${source[@]}")
+ _pkgversion=${version}
+ _pkgrelease=${release}
_pkgbuildname="${_pkgname}#${_pkgversion}_${_pkgrelease}"
- pkgmk ${_pkg} '_porttmp'
+
+ for _src in ${_pkgsource[@]}; do
+ # Download the package source files
+ port_download_src "_pkgsource[@]"
+ done
+
+
+ # Create the temporary build and packaging location
+ _porttmp=$(mktemp -d /tmp/pkgmk-${_pkgname}.XXXX)
+ mkdir -p ${_porttmp}/{pkg,src}
+
+ # Copy the sources into the build and packaging location
+ for _src in ${_pkgsource[@]}; do
+ pkg_setup_src "./" "${_porttmp}/src" "_pkgsource[@]"
+ done
+
+ pkgmk ${_pkgname} '_pkgsource[@]' "${_porttmp}"
[ $? -gt 0 ] && return 1
- linfo "Generating footprint file for ${_pkg}"
+ linfo "Generating footprint file for ${_pkgname}"
footprint_dir ${_porttmp}/pkg > ${_porttmp}/pkg.footprint
# linfo "Creating deployment tarball from ${_installbase}"
@@ -67,8 +88,8 @@ function main {
xz -v ${_porttmp}/pkg.tar
# # Move the package and footprint to current directory
- mv ${_porttmp}/pkg.tar.xz ${PORTSDIR}/${_pkg}/${_pkgbuildname}.tar.xz
- mv ${_porttmp}/pkg.footprint ${PORTSDIR}/${_pkg}/${_pkgbuildname}.footprint
+ mv -v ${_porttmp}/pkg.tar.xz ${_portdir}/${_pkgbuildname}.tar.xz
+ mv -v ${_porttmp}/pkg.footprint ${_portdir}/${_pkgbuildname}.footprint
# Cleanup if allowed
if [ "${KEEP_BUILD}" = 0 ]; then
diff --git a/lib/pkg.sh b/lib/pkg.sh
index cc11ee0..680ccb6 100644
--- a/lib/pkg.sh
+++ b/lib/pkg.sh
@@ -24,27 +24,32 @@ source ${LIBDIR}/port.sh # Basic port functions
export PORTSDIR=${PORTSDIR:-/usr/ports} # Path to port store
export PORTTMP='' # Path to the port temp dir
-function pkg_download_src {
- local _port=${1:-}
- local _pkgsrc=${2:-}
- shift && shift
- local _src=${@}
+#
+# @param _port_path Path to the port Pkgfile directory
+# @param _port_src_path Path to the port's working src directory for building
+# @param _src Ref to the source array for the given package
+#
+function pkg_setup_src {
+ local _port_path=${1:-}
+ local _port_src_path=${2:-}
+ local _ref_src=${3:-}
+
+ local _file_path
# Download from Pkgfile src spec
for file in ${_src[@]}; do
- if [[ -f ${file} ]]; then
- # If the source file exists locally, just copy from here
- cp -p ${file} ${_pkgsrc}
- else
- if [ -f $(basename ${file}) ]; then
- linfo "Source '${file}' already downloaded"
- else
- linfo "Downloading ${file}"
- download_src ${file} ${_port}
- fi
- linfo "Extracting $(basename ${file}) to ${_pkgsrc}"
- archive_extract ${_port}/$(basename ${file}) ${_pkgsrc}
+ if [ -f "${_port_path}/${file}" ]; then
+ # The referenced source file is a local path, so use that verbatim
+ _file_path="${_port_path}/${file}"
+ elif [ -f "${_port_path}/$(basename ${file})" ]; then
+ # The verbatim referenced source file path does not exist locally, so it
+ # is probably a uri. Get the basename of the path, and try to extract
+ # that.
+ _file_path="${_port_path}/$(basename ${file})"
fi
+ # Extract any local files to the pkg src path
+ linfo "Extracting $(basename ${file}) to ${_port_src_path}"
+ archive_extract "${_file_path}" "${_port_src_path}"
done
}
@@ -53,44 +58,28 @@ function pkg_download_src {
# TODO: Describe this
#
function pkgmk {
- local _port=${1:-}
- local _ref_porttmp=${2:-}
+ local _name=${1:-}
+ local _ref_source=${2:-}
+ local _porttmp=${3:-}
local _retval # Return value variable
- local _tmpdir # Temporary working directory to build the pkg
# NOTE: These are "global", so the Pkgfile can access them
local PKG # Path to the port pkg dir (binary install dest)
local PKGSRC # Path to the port src dir
-
- # Change context to port dir
- cd ${PORTSDIR}/${_port}
-
- # Include the port Pkgfile
- source Pkgfile
# Create the port build and install directory structure
- _tmpdir=$(mktemp -d /tmp/pkgmk-${_port}.XXXX)
- PKGSRC=${_tmpdir}/src
- PKG=${_tmpdir}/pkg
- mkdir -p {${PKGSRC},${PKG}}
-
- # Download the package source files
- pkg_download_src "${PORTSDIR}/${_port}" "${PKGSRC}" "${source[@]}"
+ PKGSRC=${_porttmp}/src
+ PKG=${_porttmp}/pkg
cd ${PKGSRC}
# Call the build process if defined
if [[ $(type -t pkgbuild) == 'function' ]]; then
- linfo "Running ${_port} build process"
+ linfo "Running ${_name} build process"
pkgbuild
- _retval=$?
-
- # Set the pkg temp dir (this is our return value)
- eval "${_ref_porttmp}=${_tmpdir}"
- return ${_retval}
+ return $?
else
- lerror "Port ${_port} has no pkgbuild function. Aborting."
- return 1
+ lerror "Port ${_name} has no pkgbuild function. Aborting."
fi
return 1
diff --git a/lib/port.sh b/lib/port.sh
index 0797e57..dd7a484 100644
--- a/lib/port.sh
+++ b/lib/port.sh
@@ -44,3 +44,33 @@ function download_src {
curl -L -s -k -o "${destdir}/${localname}" "${uri}"
}
+
+#
+# Downloads the list of source files to the specified port directory. If the
+# file is local, it is skipped (with a friendly info message).
+#
+# @param _src Array reference of sources (from the Pkgfile)
+#
+function port_download_src {
+ local _ref_src="${1:-}"
+
+ # Download from Pkgfile src spec
+ for file in ${!_ref_src}; do
+ if [ -f "${file}" ]; then
+ # If the source file exists locally, just copy from here
+ linfo "File ${file} exists locally."
+ continue
+ else
+ # The "file" is probably a uri that couldn't be resolved locally, so we
+ # get the basename and see if that exists locally.
+ if [ -f $(basename ${file}) ]; then
+ linfo "Source '${file}' already downloaded"
+ else
+ linfo "Downloading ${file}"
+ download_src "${file}" "./"
+ fi
+ fi
+ done
+}
+
+

Generated by cgit