From 595093e51de1ae78b8a6f0454f9f5bdc8d03a5df Mon Sep 17 00:00:00 2001 From: Aaron Ball Date: Mon, 26 Jun 2017 19:22:19 -0600 Subject: Implement pkgadd support The new libpkg pkgadd function performs the installation of a compiled port. This also adds the pkgadd.sh [basic wrapper] script, which provides easy access to the process. --- bin/pkgadd.sh | 39 +++++++++++++++++++++++++++++++++++++++ lib/pkg.sh | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 79 insertions(+) create mode 100755 bin/pkgadd.sh diff --git a/bin/pkgadd.sh b/bin/pkgadd.sh new file mode 100755 index 0000000..a5622a9 --- /dev/null +++ b/bin/pkgadd.sh @@ -0,0 +1,39 @@ +#!/usr/bin/env bash +# +# Portimg uses Crux port-like system for creating software deployment images. +# Copyright (C) 2016 Aaron Ball +# +# 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 . +# +set -eu + +export BASEDIR="$(cd $(dirname ${0})/../ && pwd)" +export LIBDIR="${BASEDIR}/lib" + +source ${LIBDIR}/log.sh +source ${LIBDIR}/pkg.sh + +export PORTSDIR=${PORTSDIR:-${BASEDIR}/ports} + +function main { + local _pkg=${1:-} + local _dest=${2:-} + + [ -z "${_pkg}" ] && lerror "A port name is required." && return 1 + [ -z "${_dest}" ] && lerror "An install destination is required." && return 1 + + pkgadd "${_pkg}" "${_dest}" +} + +main ${@} diff --git a/lib/pkg.sh b/lib/pkg.sh index aa6063e..cc11ee0 100644 --- a/lib/pkg.sh +++ b/lib/pkg.sh @@ -95,3 +95,43 @@ function pkgmk { return 1 } + + +# +# Installs the specified port's compiled package to the specified destination. +# +# @param _port Name of the port (contained in PORTSDIR) to be installed +# @param _dest Path to install the port to +# +function pkgadd { + local _port=${1:-} + local _dest=${2:-} + + local _pkgname # Pkgfile value for 'name' + local _pkgversion # Pkgfile value for 'version' + local _pkgrelease # Pkgfile value for 'release' + local _pkgbuildname # Pkgfile composite of name, version, and release + + # Ensure Pkgfile exists (we can't assemble the package filename without this) + if [ ! -f ${PORTSDIR}/${_port}/Pkgfile ]; then + lerror "Could not find Pkgfile for port ${_port}" + return 1 + fi + + # Import the Pkgfile values + source ${PORTSDIR}/${_port}/Pkgfile + _pkgname=${name} && unset 'name' + _pkgversion=${version} && unset 'version' + _pkgrelease=${release} && unset 'release' + _pkgbuildname="${_pkgname}#${_pkgversion}_${_pkgrelease}" + + # Ensure the built package exists + if [ ! -f "${PORTSDIR}/${_port}/${_pkgbuildname}.tar.xz" ]; then + lerror "Could not find compiled package for ${_port}" + return 1 + fi + + # Extract the package to the destination directory + cd ${_dest} + tar -xf ${PORTSDIR}/${_port}/${_pkgbuildname}.tar.xz +} -- cgit v1.2.3