summaryrefslogtreecommitdiff
path: root/bin/pkgimg.sh
blob: 462c0e14def77170bc90d88a879696f1a62dc808 (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 -u
   20 
   21 export BASEDIR="$(cd $(dirname ${0})/../ && pwd)"
   22 export LIBDIR="${BASEDIR}/lib"
   23 
   24 source ${LIBDIR}/log.sh
   25 source ${LIBDIR}/pkg.sh
   26 source ${LIBDIR}/config.sh
   27 source ${LIBDIR}/common.sh
   28 
   29 export PORTSDIR=${PORTSDIR:-${BASEDIR}/ports}
   30 export KEEP_BUILD=${KEEP_BUILD:-0}
   31 
   32 function main {
   33   local manifest=${1:-}
   34 
   35   local _installbase # Path to the temporary image working directory
   36   local _porttmp     # Path to the temporary package working directory
   37 
   38   if [[ -z "${manifest}" ]]; then
   39     lerror "Please specify a port manifest."
   40     return 1
   41   fi
   42   if [[ ! -f "${manifest}" ]]; then
   43     lerror "Path '${manifest}' does not exist or is not a manifest"
   44     return 2
   45   fi
   46 
   47   # Convert portsdir to absolute path
   48   PORTSDIR="$(cd ${PORTSDIR} && pwd)"
   49 
   50   _installbase=$(mktemp -d /tmp/pkgimg-install.XXXX)
   51 
   52   # Loop over each port in the manifest
   53   for port in $(grep -v '^#' ${manifest} | grep -v '^[ 	]*$'); do
   54     # Call pkgmk to build the port
   55     pkgmk ${port} '_porttmp'
   56     [ $? -gt 0 ] && return 1
   57 
   58     # Move the package contents to the install base
   59     linfo "Synchronizing ${port} build to install base ${_installbase}"
   60     rsync -a ${_porttmp}/pkg/ ${_installbase}/
   61 
   62     # Cleanup
   63     if [ "${KEEP_BUILD}" = 0 ]; then
   64       rm -rf ${_porttmp}
   65     else
   66       linfo "KEEP_BUILD is set. Skipping cleanup of ${port}."
   67     fi
   68   done
   69 
   70   linfo "Generating footprint file for ${_installbase}"
   71   footprint_dir ${_installbase} > ${_installbase}.footprint
   72 
   73   linfo "Creating deployment tarball from ${_installbase}"
   74   tar -cf ${_installbase}.tar -C ${_installbase} ./*
   75 
   76   linfo "Compressing ${_installbase}.tar"
   77   xz -v ${_installbase}.tar
   78 
   79   linfo "Fakeroot filesystem: ${_installbase}"
   80   linfo "Deployment tarball:  ${_installbase}.tar.xz"
   81   linfo "Tarball footprint:   ${_installbase}.footprint"
   82 }
   83 
   84 main ${@}

Generated by cgit