summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaron Ball <nullspoon@oper.io>2017-06-29 23:49:50 -0600
committerAaron Ball <nullspoon@oper.io>2017-06-29 23:49:50 -0600
commit28d9586478fd9dba9c29881f7f22733deecf718a (patch)
treec128d117454f593ec1546a9c1e26d52c99adac50
parenta224d4e77ec027718a37dea8b1503fe6f512611d (diff)
downloadportimg-28d9586478fd9dba9c29881f7f22733deecf718a.tar.gz
portimg-28d9586478fd9dba9c29881f7f22733deecf718a.tar.xz
Refactored pkgimg.sh
This changes the manifest format to somewhat match the Pkgfile format (shell syntax, requiring name, version, release, and a depends array). This enables better naming of the built packages. Implemented support for soon-to-come pkgmk.sh script. Rather than calling the library, we now call the same process that pkgmk uses, enabling this script to be a bit more flexible as it not longer needs to adhere to function signatures. Added helptext switch. Implemented support for external config files that provide additional variables for ports at build time. This will enable more flexible builds, which may have use when building the same package for different custom environments.
-rwxr-xr-xbin/pkgimg.sh134
1 files changed, 100 insertions, 34 deletions
diff --git a/bin/pkgimg.sh b/bin/pkgimg.sh
index 7d0df70..3c290e3 100755
--- a/bin/pkgimg.sh
+++ b/bin/pkgimg.sh
@@ -16,10 +16,11 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
-set -u
+set -eu
export BASEDIR="$(cd $(dirname ${0})/../ && pwd)"
export LIBDIR="${BASEDIR}/lib"
+export BINDIR="${BASEDIR}/bin"
source ${LIBDIR}/log.sh
source ${LIBDIR}/pkg.sh
@@ -28,10 +29,52 @@ source ${LIBDIR}/common.sh
export PORTSDIR=${PORTSDIR:-${BASEDIR}/ports}
export KEEP_BUILD=${KEEP_BUILD:-0}
-function main {
- local manifest=${1:-}
- local _installbase # Path to the temporary image working directory
+usage() {
+ printf "
+Pkgimg is a wrapper script for a simple ports system build process. The ports
+system provides build instructions for individual packages/ports. The pkgimg
+script will build multiple ports into the same working directory, creating a
+composite port package image.
+
+Usage:
+ pkgimg.sh [-c addtional_configs] <ports.manifest>
+
+Arguments:
+ -h,--help Print this help text
+ -c,--config Import additional configs file (shell syntax)
+"
+}
+
+img_mkpkg() {
+ local _imgname=${1:-}
+ local _imgversion=${2:-}
+ local _imgrelease=${3:-}
+ local _imgsrc=${4:-}
+
+ local _imgbuildname
+
+ _imgbuildname="${_imgname}#${_imgversion}_${_imgrelease}"
+
+ linfo "Generating footprint file for ${_imgname}"
+ footprint_dir ${_imgsrc} > ${BASEDIR}/${_imgbuildname}.footprint
+
+ linfo "Creating deployment tarball from ${_imgsrc}"
+ tar -cf ${BASEDIR}/${_imgbuildname}.tar -C ${_imgsrc} .
+
+ linfo "Compressing ${_imgname}.tar"
+ xz -v ${BASEDIR}/${_imgbuildname}.tar
+
+ # linfo "Build dir: ${_dest}"
+ # linfo "Deployment tarball: ${BASEDIR}/${_imgbuildname}.tar.xz"
+ # linfo "Tarball footprint: ${BASEDIR}/${_imgbuildname}.footprint"
+}
+
+
+build_manifest() {
+ local _manifest=${1:-}
+ local _installbase=${2:-}
+
local _porttmp # Path to the temporary package working directory
# Port image variables
@@ -41,16 +84,16 @@ function main {
local _imgrelease # Release number of the image
local _imgbuildname # Name of the built image file
- if [[ -z "${manifest}" ]]; then
+ if [[ -z "${_manifest}" ]]; then
lerror "Please specify a port manifest."
return 1
fi
- if [[ ! -f "${manifest}" ]]; then
+ if [[ ! -f "${_manifest}" ]]; then
lerror "Path '${manifest}' does not exist or is not a manifest"
return 2
fi
- source ${manifest}
+ source ${_manifest}
# Set all these variables as the same variables will be set later by port
# files
_imgname=${name} && unset 'name'
@@ -58,47 +101,70 @@ function main {
_imgversion=${version} && unset 'version'
_imgrelease=${release} && unset 'release'
_imgbuildname="${_imgname}#${_imgversion}_${_imgrelease}"
+ _installbase="$(mktemp -d /tmp/pkgimg-${_imgbuildname}.XXXX)"
- # Convert portsdir to absolute path
- PORTSDIR="$(cd ${PORTSDIR} && pwd)"
-
- _installbase=$(mktemp -d /tmp/pkgimg-${_imgbuildname}.XXXX)
# Loop over each port in the manifest
for port in ${_imgdepends[@]}; do
- # Call pkgmk to build the port
- pkgmk ${port} '_porttmp'
+ # Build the package
+ ${BINDIR}/pkgmk.sh ${port}
[ $? -gt 0 ] && return 1
- # Move the package contents to the install base
- linfo "Synchronizing ${port} build to install base ${_installbase}"
- rsync -a ${_porttmp}/pkg/ ${_installbase}/
+ # Install the package to the image install base
+ ${BINDIR}/pkgadd.sh "${port}" "${_installbase}"
+ [ $? -gt 0 ] && return 1
+ done
- # Cleanup
- if [ "${KEEP_BUILD}" = 0 ]; then
- rm -rf ${_porttmp}
+ # Assemble the package composite
+ img_mkpkg "${_imgname}" "${_imgversion}" "${_imgrelease}" "${_installbase}"
+}
+
+function main {
+ local argv=(${@})
+
+ local i=0
+ local _configs=() # List of config files to load
+ local _config # Single config file to include
+ local _installbase # Path to the temporary image working directory
+ local _manifest # Manifest file to compile
+
+ for (( i=0; i < ${#argv[@]}; i++ )); do
+ if [ ${argv[$i]} == '-c' ] || [ ${argv[$i]} == '--config' ]; then
+ i=$(( i + 1 ))
+ _configs+=(${argv[$i]})
+ elif [ -f ${argv[$i]} ]; then
+ # If no switch was detected at this argument index, test to see if a
+ # manifest file exists at argument path. If so, assume it is a manifest
+ # file
+ _manifest="${argv[$i]}"
+ elif [ ${argv[$i]} == '-h' ] || [ ${argv[$i]} == '--help' ]; then
+ usage
+ return 0
else
- linfo "KEEP_BUILD is set. Skipping cleanup of ${port}."
+ printf "No arguments specified (for help, run with -h,--help).\n"
+ return 1
fi
done
- linfo "Generating footprint file for ${_installbase}"
- footprint_dir ${_installbase} > ${_installbase}.footprint
-
- linfo "Creating deployment tarball from ${_installbase}"
- tar -cf ${_installbase}.tar -C ${_installbase} ./*
-
- linfo "Compressing ${_installbase}.tar"
- xz -v ${_installbase}.tar
+ # Ensure a manifest file was specified
+ if [ -z "${_manifest:-}" ]; then
+ printf "No manifest file specified.\n"
+ return 1
+ fi
- # Move the package and footprint to current directory
- mv ${_installbase}.tar.xz ${BASEDIR}/${_imgbuildname}.tar.xz
- mv ${_installbase}.footprint ${BASEDIR}/${_imgbuildname}.footprint
+ for _config in ${_configs[@]}; do
+ if [ -f ${_config} ]; then
+ source ${_config}
+ continue
+ fi
+ printf "Could not find or access config '%s'\n" "${_config}"
+ return 2
+ done
- linfo "Build dir: ${_installbase}"
- linfo "Deployment tarball: ${BASEDIR}/${_imgbuildname}.tar.xz"
- linfo "Tarball footprint: ${BASEDIR}/${_imgbuildname}.footprint"
+ # Convert portsdir to absolute path
+ PORTSDIR="$(cd ${PORTSDIR} && pwd)"
+ build_manifest "${_manifest}"
}
main ${@}

Generated by cgit