blob: aa6063ea60a10deba5662075c24ce5d1a956984a (
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 function pkg_download_src {
28 local _port=${1:-}
29 local _pkgsrc=${2:-}
30 shift && shift
31 local _src=${@}
32
33 # Download from Pkgfile src spec
34 for file in ${_src[@]}; do
35 if [[ -f ${file} ]]; then
36 # If the source file exists locally, just copy from here
37 cp -p ${file} ${_pkgsrc}
38 else
39 if [ -f $(basename ${file}) ]; then
40 linfo "Source '${file}' already downloaded"
41 else
42 linfo "Downloading ${file}"
43 download_src ${file} ${_port}
44 fi
45 linfo "Extracting $(basename ${file}) to ${_pkgsrc}"
46 archive_extract ${_port}/$(basename ${file}) ${_pkgsrc}
47 fi
48 done
49 }
50
51
52 #
53 # TODO: Describe this
54 #
55 function pkgmk {
56 local _port=${1:-}
57 local _ref_porttmp=${2:-}
58
59 local _retval # Return value variable
60 local _tmpdir # Temporary working directory to build the pkg
61 # NOTE: These are "global", so the Pkgfile can access them
62 local PKG # Path to the port pkg dir (binary install dest)
63 local PKGSRC # Path to the port src dir
64
65 # Change context to port dir
66 cd ${PORTSDIR}/${_port}
67
68 # Include the port Pkgfile
69 source Pkgfile
70
71 # Create the port build and install directory structure
72 _tmpdir=$(mktemp -d /tmp/pkgmk-${_port}.XXXX)
73 PKGSRC=${_tmpdir}/src
74 PKG=${_tmpdir}/pkg
75 mkdir -p {${PKGSRC},${PKG}}
76
77 # Download the package source files
78 pkg_download_src "${PORTSDIR}/${_port}" "${PKGSRC}" "${source[@]}"
79
80 cd ${PKGSRC}
81
82 # Call the build process if defined
83 if [[ $(type -t pkgbuild) == 'function' ]]; then
84 linfo "Running ${_port} build process"
85 pkgbuild
86 _retval=$?
87
88 # Set the pkg temp dir (this is our return value)
89 eval "${_ref_porttmp}=${_tmpdir}"
90 return ${_retval}
91 else
92 lerror "Port ${_port} has no pkgbuild function. Aborting."
93 return 1
94 fi
95
96 return 1
97 }
|