-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathxbps-src
executable file
·101 lines (78 loc) · 2.42 KB
/
xbps-src
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/bin/bash
SELF_SRC="$(realpath ${BASH_SOURCE})"
SELF_DIR="$(dirname "${SELF_SRC}")"
function guard() {
local code="${1}"
local message="${2}"
if [ "${code}" -ne 0 ]; then
echo "${message} (${code})"
exit 1
fi
}
function switch() {
local user="${1}"
local group="${2}"
if [ "${user}" != "$(whoami)" ]; then
exec su -g "${group}" -m -s '/bin/bash' "${user}" -- "${SELF_SRC}" "${@:3}"
fi
}
function install() {
local srcdir="${SELF_DIR}/srcpkgs/${1}"
test -f "${srcdir}/template"
guard $? 'no teamplate file found'
# skip dependency install if not running as root
test "$(whoami)" != 'root' && return 1
( source "${srcdir}/template"
test -n "${makedepends[*]}" && xbps-install -Ay ${makedepends[*]}
)
}
function build() {
local keydir="${SELF_DIR}"
local pkgdir="${SELF_DIR}/pkgdir"
local bindir="${SELF_DIR}/binpkgs"
local srcdir="${SELF_DIR}/srcpkgs/${1}"
test -f "${srcdir}/template"
guard $? 'no teamplate file found'
find "${pkgdir}" -mindepth 1 -delete
mkdir -p "${pkgdir}"
( unset install
source "${srcdir}/template"
# run prepare steps from template file
( set -e; set -x; prepare )
guard $? 'error in prepare step'
# run package steps from template file
( set -e; set -x; package )
guard $? 'error in package step'
mkdir -p "${bindir}/${arch}"
# required to "overwrite" signature of same package version
# this also requires deletion of /var/cache/xbps/<pkgname>.{xbps,sig} on clients
rm -f "${bindir}/${arch}/${pkgname}-${version}_${revision}.${arch}.xbps.sig"
cd "${bindir}/${arch}"
xbps-create "${pkgdir}" \
-n "${pkgname}-${version}_${revision}" \
-A "${arch}" \
-D "${depends[*]}" \
-H "${homepage}" \
-l "${license}" \
-s "${short_desc}"
export XBPS_TARGET_ARCH="${arch}"
xbps-rindex -c "${bindir}/${arch}"
xbps-rindex -f -a "${bindir}/${arch}"/*.xbps
xbps-rindex "${bindir}/${arch}" \
--sign --signedby 'root <root@raspberry.home>' \
--privkey "${keydir}/signkey.pem"
xbps-rindex \
--sign-pkg "${bindir}/${arch}/${pkgname}-${version}_${revision}.${arch}.xbps" \
--privkey "${keydir}/signkey.pem"
)
# do not purge package directory when build fails (for debugging purposes)
if [ $? -eq 0 ]; then
find "${pkgdir}" -mindepth 1 -delete
fi
}
function main() {
install "${@}"
switch 'nobody' 'xbuilder' "${@}"
build "${@}"
}
main "${@}"