summaryrefslogtreecommitdiff
path: root/bin/pkgmk.sh
blob: e0f3d4ffea492a6de7ed1b3ccfc7f31b7bdc0b94 (plain)
    1 #!/usr/bin/env bash
    2 #
    3 # Portimg uses Crux port-like system for creating software deployment images.
    4 # Copyright (C) 2016 Aaron Ball <nullspoon@oper.io>
    5 #
    6 # This program is free software: you can redistribute it and/or modify
    7 # it under the terms of the GNU General Public License as published by
    8 # the Free Software Foundation, either version 3 of the License, or
    9 # (at your option) any later version.
   10 #
   11 # This program is distributed in the hope that it will be useful,
   12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
   13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   14 # GNU General Public License for more details.
   15 #
   16 # You should have received a copy of the GNU General Public License
   17 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
   18 #
   19 set -eu
   20 
   21 export BASEDIR="$(cd $(dirname ${0})/../ && pwd)"
   22 export LIBDIR="${BASEDIR}/lib"
   23 
   24 source ${LIBDIR}/log.sh
   25 source ${LIBDIR}/template.sh
   26 source ${LIBDIR}/port.sh
   27 source ${LIBDIR}/pkg.sh
   28 source ${LIBDIR}/common.sh
   29 
   30 export PORTSDIR=${PORTSDIR:-${BASEDIR}/ports}
   31 export KEEP_BUILD=${KEEP_BUILD:-0}
   32 
   33 function main {
   34   local _pkg=${1:-}
   35   [[ -z ${_pkg} ]] && lerror "A port name is required." && return 1
   36 
   37   local _porttmp # Path to the port build working directory
   38   local _pkgfile # Path to the port's Pkgfile
   39 
   40   _pkgfile="${PORTSDIR}/${_pkg}/Pkgfile"
   41 
   42   if [ ! -f ${_pkgfile} ]; then
   43     lerror "Could not find Pkgfile at ${_pkgfile}."
   44     return 1
   45   fi
   46 
   47   source ${_pkgfile}
   48 
   49   # Set all these variables as the same variables will be set later by port
   50   # files
   51   _pkgname=${name}              && unset 'name'
   52   _pkgdepends=("${depends[@]}") && unset 'depends[@]'
   53   _pkgversion=${version}        && unset 'version'
   54   _pkgrelease=${release}        && unset 'release'
   55   _pkgbuildname="${_pkgname}#${_pkgversion}_${_pkgrelease}"
   56 
   57   pkgmk ${_pkg} '_porttmp'
   58   [ $? -gt 0 ] && return 1
   59 
   60   linfo "Generating footprint file for ${_pkg}"
   61   footprint_dir ${_porttmp}/pkg > ${_porttmp}/pkg.footprint
   62 
   63   # linfo "Creating deployment tarball from ${_installbase}"
   64   tar -cf ${_porttmp}/pkg.tar -C ${_porttmp}/pkg .
   65 
   66   # linfo "Compressing ${_installbase}.tar"
   67   xz -v ${_porttmp}/pkg.tar
   68 
   69   # # Move the package and footprint to current directory
   70   mv ${_porttmp}/pkg.tar.xz    ${PORTSDIR}/${_pkg}/${_pkgbuildname}.tar.xz
   71   mv ${_porttmp}/pkg.footprint ${PORTSDIR}/${_pkg}/${_pkgbuildname}.footprint
   72 
   73   # Cleanup if allowed
   74   if [ "${KEEP_BUILD}" = 0 ]; then
   75     rm -rf ${_porttmp}
   76   else
   77     linfo "KEEP_BUILD is set. Skipping cleanup of ${port}."
   78   fi
   79 }
   80 
   81 main ${@}

Generated by cgit