blob: b2f8aa8e1631dfc40c7817503bb3892bad5acbed (
plain)
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
|
#!/bin/bash
# Copyright 2010 - 2011 Nicolás Reynolds
# Copyright 2011 Joshua Ismael Haase Hernández
# ---------- GNU General Public License 3 ----------
# This file is part of Parabola.
# Parabola is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# Parabola is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with Parabola. If not, see <http://www.gnu.org/licenses/>.
source /etc/libretools.conf
source /etc/makepkg.conf
function usage {
echo 'cd to a dir containing a PKGBUILD and run:'
echo '$0 [options] [makepkg args]'
echo 'This script will build your package on a chroot.'
echo
echo 'OPTIONS:'
echo
echo ' -h show this message.'
echo ' -c cleans the chroot before building.'
echo ' -u updates the chroot before building.'
echo ' -U copy pacman, makepkg, and mtag config files to the chroot'
echo ' -n use this dir instead of "${CHCOPY}".'
echo ' -M <--arg> passes long args to makepkg, use it as many times as needed.'
echo
}
function buildenv {
msg "Building env"
for mp in ${SRCDEST} ${PKGDEST} ${SRCPKGDEST} ${WORKDIR}; do
msg2 "binding ${mp} to ${CHROOTDIR}/${CHCOPY}${mp}"
mkdir -p "${CHROOTDIR}/${CHCOPY}${mp}"
mount -o bind ${mp} "${CHROOTDIR}/${CHCOPY}${mp}" || exit 1
done
if [ "$update_config" = 'y' ] ; then
for config in etc/makepkg.conf etc/pacman.conf etc/mtab; do
msg2 "copying config /$config to ${CHROOTDIR}/${CHCOPY}/${config}"
cp --remove-destination /${config} ${CHROOTDIR}/${CHCOPY}/${config} || exit 1
done
fi
}
# Clean packages with pacman
function clean_chroot {
plain "making list of packages in ${CHROOTDIR}/${CHROOTNAME}/root/"
cp "/etc/libretools.d/cleansystem" "${CHROOTDIR}/${CHROOTNAME}/root/cleansystem"
(cat <<EOF
#!/bin/bash
export LANG=C
clean='false'
while [ "\$clean" = 'false' ]; do
pkgs=(\$(comm -23 <(pacman -Qq | sort) <(sort /root/cleansystem)))
if [ \${#pkgs[@]} -gt 0 ]; then
pacman --noconfirm -Rcs \${pkgs[@]}
else
clean="true"
echo "clean"
fi
done
EOF
) > "${CHROOTDIR}/${CHROOTNAME}/clean"
chmod +x "${CHROOTDIR}/${CHROOTNAME}/clean"
mkarchroot -r "/clean" "${CHROOTDIR}/${CHROOTNAME}"
}
# End inmediately but print a useful message
trap_exit() {
for mp in ${SRCDEST} ${PKGDEST} ${SRCPKGDEST} ${WORKDIR}; do
umount "${CHROOTDIR}/${CHCOPY}${mp}"
done
error "$@"
exit 1
}
## Trap signals
# From makepkg
set -E
trap 'trap_exit "(libremakepkg): TERM signal caught. Exiting..."' TERM HUP QUIT
trap 'trap_exit "(libremakepkg): Aborted by user! Exiting..."' INT
trap 'trap_exit "(libremakepkg): An unknown error has occurred. Exiting..."' ERR
CLEAN_FIRST="n"
CLEAN_CACHE=""
UPDATE_FIRST="n"
USE_LOG='n'
CHROOTNAME=${CHCOPY}
MAKEPKG_ARGS=""
update_config='n'
#libremakepkg own args
libremakepkgargs='hcuUn:I:M:'
#now makepkg args
libremakepkgargs+='ACdefiLmop:rRs'
while getopts ${libremakepkgargs} arg ; do
case "${arg}" in
h) usage; exit 0 ;;
c) CLEAN_FIRST="y" ;;
u) UPDATE_FIRST="y" ;;
U) update_config='y' ;;
n) CHROOTNAME="$OPTARG" ;;
M) MAKEPKG_ARGS+=" $OPTARG" ;;
L) MAKEPKG_ARGS+=" -$arg $OPTARG"
USE_LOG='y';;
*) MAKEPKG_ARGS+=" -$arg $OPTARG" ;;
esac
done
if [ ${UID} -ne 0 ]; then
error "This script must be run as root"
exit 1
fi
msg "Checking PKGBUILD for non-free issues"
pkgbuild-check-nonfree ||{
if [[ $? -eq 15 ]]; then # other errors mean fail, not nonfree
error "PKGBUILD contains non-free issues"
exit 15
else
true
fi
}
buildenv
if [ "${UPDATE_FIRST}" = 'y' ]; then
msg "Updating the chroot in use..."
# -c option in mkarchroot indicates cache
mkarchroot -c ${CACHEDIR} -u "${CHROOTDIR}/${CHROOTNAME}"
fi
if [ "${CLEAN_FIRST}" = 'y' ]; then
msg "Cleaning"
clean_chroot
fi
msg "Creating the package"
makechrootpkg -r "${CHROOTDIR}" -l "${CHROOTNAME}" -- "${MAKEPKG_ARGS}"
ev=$? # exit value
if [ "${USE_LOG}" == 'y' ]; then
find ${CHROOTDIR}/${CHROOTNAME}/build/ -name "*\.log" -exec cp {} ./ \;
}
exit $ev
|