forked from openSUSE/obs-build
-
Notifications
You must be signed in to change notification settings - Fork 1
/
build-pkg-rpm
263 lines (248 loc) · 10.6 KB
/
build-pkg-rpm
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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
#
# RPM specific functions.
#
################################################################
#
# Copyright (c) 1995-2014 SUSE Linux Products GmbH
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 or 3 as
# published by the Free Software Foundation.
#
# This program 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 this program (see the file COPYING); if not, write to the
# Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
#
################################################################
pkg_initdb_rpm() {
echo "initializing rpm db..."
mkdir -p $BUILD_ROOT/var/lib/rpm
# rpm v5 does not have initdb
if ! test -e $BUILD_ROOT/usr/lib/rpm/cpuinfo.yaml ; then
if test -x $BUILD_ROOT/usr/bin/rpmdb ; then
chroot $BUILD_ROOT /usr/bin/rpmdb --initdb || cleanup_and_exit 1
else
chroot $BUILD_ROOT rpm --initdb || cleanup_and_exit 1
fi
fi
# hack: add nofsync to db config to speed up install
mkdir -p $BUILD_ROOT/root
DBI_OTHER=`chroot $BUILD_ROOT rpm --eval '%{?__dbi_other}'`
echo "%__dbi_other $DBI_OTHER nofsync" > $BUILD_ROOT/.rpmmacros
echo "%__dbi_other $DBI_OTHER nofsync" > $BUILD_ROOT/root/.rpmmacros
}
pkg_prepare_rpm() {
rpm_set_checkopts
rpm_init_cumulate
}
pkg_erase_rpm() {
chroot $BUILD_ROOT rpm --nodeps -e $PKG 2>&1 | {
local retry
while read line; do
case "$line" in
r*failed:\ No\ such\ file\ or\ directory) ;;
error:\ failed\ to\ stat\ *:\ No\ such\ file\ or\ directory) ;;
error:\ *scriptlet\ failed*)
echo "$line"
retry=1
;;
*) echo "$line" ;;
esac
done
if test -n "$retry" ; then
echo "re-try deleting $PKG using --noscripts"
chroot $BUILD_ROOT rpm --nodeps --noscripts -e $PKG || true
fi
}
}
rpm_set_checkopts() {
RPMCHECKOPTS=
# on Fedora 10 rpmbuild is in a separate package so we need something else to
# detect rpm4
test -x $BUILD_ROOT/usr/bin/rpmquery && RPMCHECKOPTS="--nodigest --nosignature"
}
rpm_init_cumulate() {
cumulate=-1
CUMULATED_LIST=()
CUMULATED_PIDS=()
CUMULATED_HMD5=()
DO_CUMULATE=
local cumulaterpms=$(queryconfig --dist "$BUILD_DIST" --configdir "$CONFIG_DIR" --archpath "$BUILD_ARCH" buildflags cumulaterpms)
if test -n "$cumulaterpms" ; then
test "$cumulaterpms" != 0 && DO_CUMULATE=true
else
# compatibility: auto-set cumulate for newer suse distros
typeset -ri suse_version=$(queryconfig --dist "$BUILD_DIST" --configdir "$CONFIG_DIR" --archpath "$BUILD_ARCH" eval '%{?suse_version}')
if ((suse_version > 1220)) ; then
DO_CUMULATE=true
fi
fi
}
pkg_verify_installed_rpm() {
chroot $BUILD_ROOT rpm --verify $PKG 2>&1 | tee $TMPFILE
if grep ^missing $TMPFILE > /dev/null ; then
return 1
fi
return 0
}
pkg_cumulate_rpm() {
test "$DO_CUMULATE" = true || return 1
# work around for cross-build installs, we must not overwrite the running rpm
if test "$PKG" = rpm ; then
for i in $BUILD_ROOT/.init_b_cache/preinstalls/rpm-x86-* ; do
test -e "$i" && return 1
done
fi
let cumulate++
CUMULATED_LIST[$cumulate]=".init_b_cache/$PKG.rpm"
CUMULATED_PIDS[$cumulate]="$PKGID"
CUMULATED_HMD5[$cumulate]="$PKG_HDRMD5"
return 0
}
pkg_install_rpm() {
export ADDITIONAL_PARAMS=
if test "$USE_FORCE" = true ; then
export ADDITIONAL_PARAMS="$ADDITIONAL_PARAMS --force"
fi
# work around for cross-build installs, we must not overwrite the running rpm
if test "$PKG" = rpm ; then
for i in $BUILD_ROOT/.init_b_cache/preinstalls/rpm-x86-* ; do
test -e "$i" && ADDITIONAL_PARAMS="$ADDITIONAL_PARAMS --justdb"
done
fi
( cd $BUILD_ROOT && chroot $BUILD_ROOT rpm --ignorearch --nodeps -U --oldpackage --ignoresize $RPMCHECKOPTS \
$ADDITIONAL_PARAMS .init_b_cache/$PKG.rpm 2>&1 || \
touch $BUILD_ROOT/exit ) | \
grep -v "^warning:.*saved as.*rpmorig$"
}
pkg_sysrootinstall_rpm() {
if test "x$1" = "x--prepare" ; then
assert_dir_path "$BUILD_SYSROOT"
chroot $BUILD_ROOT mkdir -p "$BUILD_SYSROOT"
chroot $BUILD_ROOT rpm --root "$BUILD_SYSROOT" --initdb
local installed=$(chroot $BUILD_ROOT rpm --root "$BUILD_SYSROOT" -qa)
test -n "$installed" && chroot $BUILD_ROOT rpm --root "$BUILD_SYSROOT" --nodeps --noscripts -e --allmatches $installed
return
fi
if test "x$1" = "x--finalize" ; then
return
fi
export ADDITIONAL_PARAMS=
if test "$USE_FORCE" = true ; then
export ADDITIONAL_PARAMS="$ADDITIONAL_PARAMS --force"
fi
( cd $BUILD_ROOT && chroot $BUILD_ROOT rpm --ignorearch --nodeps -U --oldpackage --ignoresize $RPMCHECKOPTS \
$ADDITIONAL_PARAMS --noscripts --root "$BUILD_SYSROOT" .init_b_cache/$PKG.rpm 2>&1 || \
touch $BUILD_ROOT/exit ) | \
grep -v "^warning:.*saved as.*rpmorig$"
}
pkg_finalize_rpm() {
if test -n "${CUMULATED_LIST[*]}" ; then
echo "now installing cumulated packages"
for ((num=0; num<=cumulate; num++)) ; do
echo ${CUMULATED_LIST[$num]}
PKG=${CUMULATED_LIST[$num]##*/}
test "$BUILD_ROOT/.init_b_cache/rpms/$PKG" -ef "$BUILD_ROOT/${CUMULATED_LIST[$num]}" && continue
rm -f $BUILD_ROOT/${CUMULATED_LIST[$num]}
cp $BUILD_ROOT/.init_b_cache/rpms/$PKG $BUILD_ROOT/${CUMULATED_LIST[$num]} || cleanup_and_exit 1
done > $BUILD_ROOT/.init_b_cache/manifest
( cd $BUILD_ROOT && chroot $BUILD_ROOT rpm --ignorearch --nodeps -Uh --oldpackage --ignoresize --verbose $RPMCHECKOPTS \
$ADDITIONAL_PARAMS .init_b_cache/manifest 2>&1 || touch $BUILD_ROOT/exit )
for ((num=0; num<=cumulate; num++)) ; do
rm -f $BUILD_ROOT/${CUMULATED_LIST[$num]}
done
rm -f $BUILD_ROOT/.init_b_cache/manifest
check_exit
for ((num=0; num<=cumulate; num++)) ; do
PKG=${CUMULATED_LIST[$num]##*/}
echo "${CUMULATED_PIDS[$num]}" > $BUILD_ROOT/installed-pkg/${PKG%.rpm}
test -n "${CUMULATED_HMD5[$num]}" || continue
echo "${CUMULATED_HMD5[$num]} ${CUMULATED_PIDS[$num]}" > $BUILD_ROOT/.preinstall_image/${PKG%.rpm}
done
fi
}
LZMA_PAYLOADDECOMPRESS=cat
t=$(mktemp)
rpm --showrc > $t
grep -q -E 'PayloadIsLzma|_lzma' < $t || PAYLOADDECOMPRESS="lzma -d"
XZ_PAYLOADDECOMPRESS=cat
grep -q -E 'PayloadIsXz|_xz' < $t || PAYLOADDECOMPRESS="xz -d"
ZSTD_PAYLOADDECOMPRESS=cat
grep -q -F 'PayloadIsZstd' < $t || PAYLOADDECOMPRESS="zstd -d"
rm -f $t
pkg_preinstall_rpm() {
test -d "$BUILD_INIT_CACHE/scripts" || mkdir -p "$BUILD_INIT_CACHE/scripts"
# if our rpm(1) can decompress everything, we don't need to probe what compression
# we actually have
if test "$LZMA_PAYLOADDECOMPRESS" = "cat" -a "$XZ_PAYLOADDECOMPRESS" = "cat" -a "$ZSTD_PAYLOADDECOMPRESS" = "cat"; then
rpm2cpio "$BUILD_INIT_CACHE/rpms/$PKG.rpm" | $CPIO || cleanup_and_exit 1
else
PAYLOADDECOMPRESS=cat
case $(rpm -qp --nodigest --nosignature --qf "%{PAYLOADCOMPRESSOR}\n" "$BUILD_INIT_CACHE/rpms/$PKG.rpm") in
lzma) PAYLOADCOMPRESSOR="$LZMA_PAYLOADDECOMPRESS" ;;
xz) PAYLOADDECOMPRESSOR="$XZ_PAYLOADDECOMPRESS" ;;
zstd) PAYLOADDECOMPRESSOR="$ZSTD_PAYLOADDECOMPRESS" ;;
esac
if test "$PAYLOADDECOMPRESS" = "lzma -d" ; then
if ! lzma </dev/null >/dev/null 2>&1 ; then
test -f "$BUILD_DIR/lzmadec.sh" || cleanup_and_exit 3 "no lzma decoder available in host system"
PAYLOADDECOMPRESS="bash $BUILD_DIR/lzmadec.sh"
fi
fi
if test "$PAYLOADDECOMPRESS" = "xz -d" ; then
if ! xz </dev/null >/dev/null 2>&1 ; then
test -f "$BUILD_DIR/xzdec.sh" || cleanup_and_exit 3 "no xz decoder available in host system"
PAYLOADDECOMPRESS="bash $BUILD_DIR/xzdec.sh"
fi
fi
if test "$PAYLOADDECOMPRESS" = "zstd -d" ; then
if ! zstd </dev/null >/dev/null 2>&1 ; then
test -f "$BUILD_DIR/zstddec.sh" || cleanup_and_exit 3 "no zstd decoder available in host system"
PAYLOADDECOMPRESS="bash $BUILD_DIR/zstddec.sh"
fi
fi
rpm2cpio "$BUILD_INIT_CACHE/rpms/$PKG.rpm" | $PAYLOADDECOMPRESS | $CPIO || cleanup_and_exit 1
fi
test -L "$BUILD_INIT_CACHE/scripts" && cleanup_and_exit 1
rm -rf "$BUILD_INIT_CACHE/scripts/$PKG.pre" "$BUILD_INIT_CACHE/scripts/$PKG.preprog" "$BUILD_INIT_CACHE/scripts/$PKG.post" "$BUILD_INIT_CACHE/scripts/$PKG.postprog"
if test -e "$BUILD_INIT_CACHE/scripts/$PKG.run" ; then
rpm -qp --nodigest --nosignature --qf "%{PREIN}" "$BUILD_INIT_CACHE/rpms/$PKG.rpm" > "$BUILD_INIT_CACHE/scripts/$PKG.pre"
rpm -qp --nodigest --nosignature --qf "%{PREINPROG}" "$BUILD_INIT_CACHE/rpms/$PKG.rpm" > "$BUILD_INIT_CACHE/scripts/$PKG.preprog"
rpm -qp --nodigest --nosignature --qf "%{POSTIN}" "$BUILD_INIT_CACHE/rpms/$PKG.rpm" > "$BUILD_INIT_CACHE/scripts/$PKG.post"
rpm -qp --nodigest --nosignature --qf "%{POSTINPROG}" "$BUILD_INIT_CACHE/rpms/$PKG.rpm" > "$BUILD_INIT_CACHE/scripts/$PKG.postprog"
rm -f "$BUILD_INIT_CACHE/scripts/.none"
echo -n '(none)' > "$BUILD_INIT_CACHE/scripts/.none"
cmp -s "$BUILD_INIT_CACHE/scripts/$PKG.pre" "$BUILD_INIT_CACHE/scripts/.none" && rm -f "$BUILD_INIT_CACHE/scripts/$PKG.pre"
cmp -s "$BUILD_INIT_CACHE/scripts/$PKG.post" "$BUILD_INIT_CACHE/scripts/.none" && rm -f "$BUILD_INIT_CACHE/scripts/$PKG.post"
rm -f "$BUILD_INIT_CACHE/scripts/.none"
fi
# hack for rpm erasures
if test -d "$BUILD_ROOT/installed-pkg" -a -z "$PREPARE_VM" ; then
# call for rpm-4.x and not rpm-devel
test -z "${PKG##rpm-[0-9]*}" && chroot . rpm --rebuilddb
# also exec for exchanged rpm ! naming is rpm-x86-<target>-<ver>
test -z "${PKG##rpm-x86-*[0-9]*}" && chroot . rpm --rebuilddb
fi
}
pkg_runscripts_rpm() {
if test -e "$BUILD_ROOT/.init_b_cache/scripts/$PKG.pre" ; then
echo "running $PKG preinstall script"
local prog
read prog < "$BUILD_ROOT/.init_b_cache/scripts/$PKG.preprog"
(cd $BUILD_ROOT && chroot $BUILD_ROOT "${prog:-sh}" ".init_b_cache/scripts/$PKG.pre" 0)
rm -f "$BUILD_ROOT/.init_b_cache/scripts/$PKG.pre" "$BUILD_ROOT/.init_b_cache/scripts/$PKG.preprog"
fi
if test -e "$BUILD_ROOT/.init_b_cache/scripts/$PKG.post" ; then
echo "running $PKG postinstall script"
local prog
read prog < "$BUILD_ROOT/.init_b_cache/scripts/$PKG.postprog"
(cd $BUILD_ROOT && chroot $BUILD_ROOT "${prog:-sh}" ".init_b_cache/scripts/$PKG.post" 1)
rm -f "$BUILD_ROOT/.init_b_cache/scripts/$PKG.post" "$BUILD_ROOT/.init_b_cache/scripts/$PKG.postprog"
fi
}