summaryrefslogtreecommitdiff
path: root/bin/pkgmk.sh
blob: 3e7e091968d03467c2846386246fbb527347f894 (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 _porttmp      # Path to the port build working directory
   35   local _portdir      # Path to the port dir that contains the Pkgfile
   36 
   37   local _pkgname      # Pkgfile value for 'name'
   38   local _pkgsource    # Pkgfile value for 'source'
   39   local _pkgversion   # Pkgfile value for 'version'
   40   local _pkgrelease   # Pkgfile value for 'release'
   41   local _pkgbuildname # Pkgfile composite of name, version, and release
   42   local _porttmp      # Temporary working directory to build the pkg
   43 
   44   if [ ! -f Pkgfile ]; then
   45     lerror "Could not find Pkgfile."
   46     return 1
   47   fi
   48 
   49   _portdir="$(pwd)"
   50 
   51   # Include the port Pkgfile
   52   source Pkgfile
   53 
   54   # Set all these variables to local versions, to avoid possible overrides,
   55   # conflicts, etc. when these are used later on.
   56   _pkgname=${name}
   57   _pkgsource=("${source[@]}")
   58   _pkgversion=${version}
   59   _pkgrelease=${release}
   60   _pkgbuildname="${_pkgname}#${_pkgversion}_${_pkgrelease}"
   61 
   62 
   63   for _src in ${_pkgsource[@]}; do
   64     # Download the package source files
   65     port_download_src "_pkgsource[@]"
   66   done
   67 
   68 
   69   # Create the temporary build and packaging location
   70   _porttmp=$(mktemp -d /tmp/pkgmk-${_pkgname}.XXXX)
   71   mkdir -p ${_porttmp}/{pkg,src}
   72 
   73   # Copy the sources into the build and packaging location
   74   for _src in ${_pkgsource[@]}; do
   75     pkg_setup_src "./" "${_porttmp}/src" "_pkgsource[@]"
   76   done
   77 
   78   pkgmk ${_pkgname} '_pkgsource[@]' "${_porttmp}"
   79   [ $? -gt 0 ] && return 1
   80 
   81   linfo "Generating footprint file for ${_pkgname}"
   82   footprint_dir ${_porttmp}/pkg > ${_porttmp}/pkg.footprint
   83 
   84   # linfo "Creating deployment tarball from ${_installbase}"
   85   tar -cf ${_porttmp}/pkg.tar -C ${_porttmp}/pkg .
   86 
   87   # linfo "Compressing ${_installbase}.tar"
   88   xz -v ${_porttmp}/pkg.tar
   89 
   90   # # Move the package and footprint to current directory
   91   mv -v ${_porttmp}/pkg.tar.xz    ${_portdir}/${_pkgbuildname}.tar.xz
   92   mv -v ${_porttmp}/pkg.footprint ${_portdir}/${_pkgbuildname}.footprint
   93 
   94   # Cleanup if allowed
   95   if [ "${KEEP_BUILD}" = 0 ]; then
   96     rm -rf ${_porttmp}
   97   else
   98     linfo "KEEP_BUILD is set. Skipping cleanup of ${port}."
   99   fi
  100 }
  101 
  102 main ${@}

Generated by cgit