summaryrefslogtreecommitdiff
path: root/lib/pkg.sh
blob: 680ccb6887072dd27e7a2124c54b51f9b3f2c517 (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 
   20 source ${LIBDIR}/log.sh                 # Logging support
   21 source ${LIBDIR}/template.sh            # Included so each port can use templates
   22 source ${LIBDIR}/port.sh                # Basic port functions
   23 
   24 export PORTSDIR=${PORTSDIR:-/usr/ports} # Path to port store
   25 export PORTTMP=''                       # Path to the port temp dir
   26 
   27 #
   28 # @param _port_path      Path to the port Pkgfile directory
   29 # @param _port_src_path  Path to the port's working src directory for building
   30 # @param _src            Ref to the source array for the given package
   31 #
   32 function pkg_setup_src {
   33   local _port_path=${1:-}
   34   local _port_src_path=${2:-}
   35   local _ref_src=${3:-}
   36 
   37   local _file_path
   38 
   39   # Download from Pkgfile src spec
   40   for file in ${_src[@]}; do
   41     if [ -f "${_port_path}/${file}" ]; then
   42       # The referenced source file is a local path, so use that verbatim
   43       _file_path="${_port_path}/${file}"
   44     elif [ -f "${_port_path}/$(basename ${file})" ]; then
   45       # The verbatim referenced source file path does not exist locally, so it
   46       # is probably a uri. Get the basename of the path, and try to extract
   47       # that.
   48       _file_path="${_port_path}/$(basename ${file})"
   49     fi
   50     # Extract any local files to the pkg src path
   51     linfo "Extracting $(basename ${file}) to ${_port_src_path}"
   52     archive_extract "${_file_path}" "${_port_src_path}"
   53   done
   54 }
   55 
   56 
   57 #
   58 # TODO: Describe this
   59 #
   60 function pkgmk {
   61   local _name=${1:-}
   62   local _ref_source=${2:-}
   63   local _porttmp=${3:-}
   64 
   65   local _retval  # Return value variable
   66   # NOTE: These are "global", so the Pkgfile can access them
   67   local PKG      # Path to the port pkg dir (binary install dest)
   68   local PKGSRC   # Path to the port src dir
   69   
   70   # Create the port build and install directory structure
   71   PKGSRC=${_porttmp}/src
   72   PKG=${_porttmp}/pkg
   73 
   74   cd ${PKGSRC}
   75 
   76   # Call the build process if defined
   77   if [[ $(type -t pkgbuild) == 'function' ]]; then
   78     linfo "Running ${_name} build process"
   79     pkgbuild
   80     return $?
   81   else
   82     lerror "Port ${_name} has no pkgbuild function. Aborting."
   83   fi
   84 
   85   return 1
   86 }
   87 
   88 
   89 #
   90 # Installs the specified port's compiled package to the specified destination.
   91 #
   92 # @param _port Name of the port (contained in PORTSDIR) to be installed
   93 # @param _dest Path to install the port to
   94 #
   95 function pkgadd {
   96   local _port=${1:-}
   97   local _dest=${2:-}
   98 
   99   local _pkgname      # Pkgfile value for 'name'
  100   local _pkgversion   # Pkgfile value for 'version'
  101   local _pkgrelease   # Pkgfile value for 'release'
  102   local _pkgbuildname # Pkgfile composite of name, version, and release
  103 
  104   # Ensure Pkgfile exists (we can't assemble the package filename without this)
  105   if [ ! -f ${PORTSDIR}/${_port}/Pkgfile ]; then
  106     lerror "Could not find Pkgfile for port ${_port}"
  107     return 1
  108   fi
  109 
  110   # Import the Pkgfile values
  111   source ${PORTSDIR}/${_port}/Pkgfile
  112   _pkgname=${name}       && unset 'name'
  113   _pkgversion=${version} && unset 'version'
  114   _pkgrelease=${release} && unset 'release'
  115   _pkgbuildname="${_pkgname}#${_pkgversion}_${_pkgrelease}"
  116 
  117   # Ensure the built package exists
  118   if [ ! -f "${PORTSDIR}/${_port}/${_pkgbuildname}.tar.xz" ]; then
  119     lerror "Could not find compiled package for ${_port}"
  120     return 1
  121   fi
  122 
  123   # Extract the package to the destination directory
  124   cd ${_dest}
  125   tar -xf ${PORTSDIR}/${_port}/${_pkgbuildname}.tar.xz
  126 }

Generated by cgit