blob: 2a5047aeedb5d4e1cba0815fb9b07532b399ca94 (
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
58 local PKG='' # Path to the port pkg dir (binary install dest)
59 local PKGSRC='' # Path to the port src dir
60
61 # Change context to port dir
62 cd ${PORTSDIR}/${port}
63
64 # Include the port Pkgfile
65 source Pkgfile
66
67 # Create the port build and install directory structure
68 PORTTMP=$(mktemp -d /tmp/pkgmk-${port}.XXXX)
69 PKGSRC=${PORTTMP}/src
70 PKG=${PORTTMP}/pkg
71 mkdir -p {${PKGSRC},${PKG}}
72
73 # Download the package source files
74 pkg_download_src "${PORTSDIR}/${port}" "${PKGSRC}" "${source[@]}"
75
76 cd ${PKGSRC}
77
78 # Call the build process if defined
79 if [[ $(type -t pkgbuild) == 'function' ]]; then
80 linfo "Running ${port} build process"
81 pkgbuild
82 return $?
83 else
84 lerror "Port ${port} has no pkgbuild function. Aborting."
85 return 1
86 fi
87
88 return 0
89 }
|