summaryrefslogtreecommitdiff
path: root/bin/pkgimg.sh
blob: 25afe11fffd059077430f81dba6e26bc3f37d661 (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=''
   36 
   37   if [[ -z ${manifest} ]]; then
   38     lerror "Please provide a port manifest."
   39     return 1
   40   fi
   41 
   42   # Convert portsdir to absolute path
   43   PORTSDIR="$(cd ${PORTSDIR} && pwd)"
   44 
   45   installbase=$(mktemp -d /tmp/pkgimg-install.XXXX)
   46 
   47   # Loop over each port in the manifest
   48   for port in $(grep -v '^#' ${manifest} | grep -v '^[ 	]*$'); do
   49     # Call pkgmk to build the port
   50     pkgmk ${port}
   51     [ $? -gt 0 ] && return 1
   52 
   53     # Move the package contents to the install base
   54     linfo "Synchronizing ${port} build to install base ${installbase}"
   55     rsync -a ${PORTTMP}/pkg/ ${installbase}/
   56 
   57     # Cleanup
   58     if [ "${KEEP_BUILD}" = 0 ]; then
   59       rm -rf ${PORTTMP}
   60     else
   61       linfo "KEEP_BUILD is set. Skipping cleanup of ${port}."
   62     fi
   63   done
   64 
   65   linfo "Generating footprint file for ${installbase}"
   66   footprint_dir ${installbase} > ${installbase}.footprint
   67 
   68   linfo "Creating deployment tarball from ${installbase}"
   69   tar -cf ${installbase}.tar -C ${installbase} ./*
   70 
   71   linfo "Compressing ${installbase}.tar"
   72   xz -v ${installbase}.tar
   73 
   74   linfo "Fakeroot filesystem: ${installbase}"
   75   linfo "Deployment tarball:  ${installbase}.tar.xz"
   76   linfo "Tarball footprint:   ${installbase}.footprint"
   77 }
   78 
   79 main ${@}

Generated by cgit