2 # RPM specific functions.
4 ################################################################
6 # Copyright (c) 1995-2014 SUSE Linux Products GmbH
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License version 2 or 3 as
10 # published by the Free Software Foundation.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program (see the file COPYING); if not, write to the
19 # Free Software Foundation, Inc.,
20 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 ################################################################
26 echo "initializing rpm db..."
27 mkdir -p "$BUILD_ROOT"/var/lib/rpm
28 # rpm v5 does not have initdb
29 if ! test -e "$BUILD_ROOT"/usr/lib/rpm/cpuinfo.yaml ; then
30 if test -x "$BUILD_ROOT"/usr/bin/rpmdb ; then
31 chroot "$BUILD_ROOT" /usr/bin/rpmdb --initdb || cleanup_and_exit 1
33 chroot "$BUILD_ROOT" rpm --initdb || cleanup_and_exit 1
36 # hack: add nofsync to db config to speed up install
37 mkdir -p "$BUILD_ROOT"/root
38 DBI_OTHER=`chroot "$BUILD_ROOT" rpm --eval '%{?__dbi_other}'`
39 echo "%__dbi_other $DBI_OTHER nofsync" > "$BUILD_ROOT"/.rpmmacros
40 echo "%__dbi_other $DBI_OTHER nofsync" > "$BUILD_ROOT"/root/.rpmmacros
49 chroot "$BUILD_ROOT" rpm --nodeps -e $PKG 2>&1 | {
53 r*failed:\ No\ such\ file\ or\ directory) ;;
54 error:\ failed\ to\ stat\ *:\ No\ such\ file\ or\ directory) ;;
55 error:\ *scriptlet\ failed*)
62 if test -n "$retry" ; then
63 echo "re-try deleting $PKG using --noscripts"
64 chroot "$BUILD_ROOT" rpm --nodeps --noscripts -e $PKG || true
71 # on Fedora 10 rpmbuild is in a separate package so we need something else to
73 test -x "$BUILD_ROOT"/usr/bin/rpmquery && RPMCHECKOPTS="--nodigest --nosignature"
82 # force enable DO_CUMULATE
84 # We can't use cumulative install because we don't use %suse_version macro.
85 # However, our build system is based on openSUSE Build service and we use
86 # always newer suse version than 1220. Thus, we can always enable cumulative
87 # install instead of defining the suse_version.
89 # ref: https://review.tizen.org/gerrit/#/c/platform/upstream/build/+/25635/
92 local nocumulaterpms=$(queryconfig --dist "$BUILD_DIST" --configdir "$CONFIG_DIR" --archpath "$BUILD_ARCH" buildflags nocumulaterpms)
93 if test -n "$nocumulaterpms" ; then
94 test "$nocumulaterpms" != 0 && DO_CUMULATE=false
96 # # compatibility: auto-set cumulate for newer suse distros
97 # typeset -ri suse_version=$(queryconfig --dist "$BUILD_DIST" --configdir "$CONFIG_DIR" --archpath "$BUILD_ARCH" eval '%{?suse_version}')
98 # if ((suse_version > 1220)) ; then
105 pkg_verify_installed_rpm() {
106 chroot "$BUILD_ROOT" rpm --verify $PKG 2>&1 | tee $TMPFILE
107 if grep ^missing $TMPFILE > /dev/null ; then
114 test "$DO_CUMULATE" = true || return 1
115 # work around for cross-build installs, we must not overwrite the running rpm
116 if test "$PKG" = rpm ; then
117 for i in "$BUILD_ROOT"/.init_b_cache/preinstalls/rpm-x86-* ; do
118 test -e "$i" && return 1
122 CUMULATED_LIST[$cumulate]=".init_b_cache/$PKG.rpm"
123 CUMULATED_PIDS[$cumulate]="$PKGID"
124 CUMULATED_HMD5[$cumulate]="$PKG_HDRMD5"
129 ( cd "$BUILD_ROOT" && chroot "$BUILD_ROOT" rpm --ignorearch --nodeps -U --oldpackage --ignoresize $RPMCHECKOPTS \
130 $ADDITIONAL_PARAMS .init_b_cache/$PKG.rpm 2>&1 || \
131 touch "$BUILD_ROOT"/exit ) | \
132 grep -v "^warning:.*saved as.*rpmorig$"
136 if test -n "${CUMULATED_LIST[*]}" ; then
137 echo "now installing cumulated packages"
138 for ((num=0; num<=cumulate; num++)) ; do
139 echo ${CUMULATED_LIST[$num]}
140 PKG=${CUMULATED_LIST[$num]##*/}
141 test "$BUILD_ROOT/.init_b_cache/rpms/$PKG" -ef "$BUILD_ROOT/${CUMULATED_LIST[$num]}" && continue
142 rm -f "$BUILD_ROOT"/${CUMULATED_LIST[$num]}
143 cp "$BUILD_ROOT"/.init_b_cache/rpms/$PKG "$BUILD_ROOT"/${CUMULATED_LIST[$num]} || cleanup_and_exit 1
144 done > "$BUILD_ROOT"/.init_b_cache/manifest
145 ( cd "$BUILD_ROOT" && chroot "$BUILD_ROOT" rpm --ignorearch --nodeps -Uh --oldpackage --ignoresize --verbose $RPMCHECKOPTS \
146 $ADDITIONAL_PARAMS .init_b_cache/manifest 2>&1 || touch "$BUILD_ROOT"/exit )
147 for ((num=0; num<=cumulate; num++)) ; do
148 rm -f "$BUILD_ROOT"/${CUMULATED_LIST[$num]}
150 rm -f "$BUILD_ROOT"/.init_b_cache/manifest
152 for ((num=0; num<=cumulate; num++)) ; do
153 PKG=${CUMULATED_LIST[$num]##*/}
154 echo "${CUMULATED_PIDS[$num]}" > "$BUILD_ROOT"/installed-pkg/${PKG%.rpm}
155 test -n "${CUMULATED_HMD5[$num]}" || continue
156 echo "${CUMULATED_HMD5[$num]} ${CUMULATED_PIDS[$num]}" > "$BUILD_ROOT"/.preinstall_image/${PKG%.rpm}
161 pkg_preinstall_rpm() {
162 PAYLOADDECOMPRESS=cat
163 case `rpm -qp --nodigest --nosignature --qf "%{PAYLOADCOMPRESSOR}\n" "'$BUILD_ROOT'/.init_b_cache/rpms/$PKG.rpm"` in
164 lzma) rpm --showrc | egrep 'PayloadIsLzma|_lzma' > /dev/null || PAYLOADDECOMPRESS="lzma -d" ;;
165 xz) rpm --showrc | egrep 'PayloadIsXz|_xz' > /dev/null || PAYLOADDECOMPRESS="xz -d" ;;
166 zstd) rpm --showrc | egrep 'PayloadIsZstd' > /dev/null || PAYLOADDECOMPRESS="zstd -d" ;;
168 if test "$PAYLOADDECOMPRESS" = "lzma -d" ; then
169 if ! lzma </dev/null >/dev/null 2>&1 ; then
170 test -f "$BUILD_DIR/lzmadec.sh" || cleanup_and_exit 3 "no lzma decoder available in host system"
171 PAYLOADDECOMPRESS="bash $BUILD_DIR/lzmadec.sh"
174 if test "$PAYLOADDECOMPRESS" = "xz -d" ; then
175 if ! xz </dev/null >/dev/null 2>&1 ; then
176 test -f "$BUILD_DIR/xzdec.sh" || cleanup_and_exit 3 "no xz decoder available in host system"
177 PAYLOADDECOMPRESS="bash $BUILD_DIR/xzdec.sh"
180 if test "$PAYLOADDECOMPRESS" = "zstd -d" ; then
181 if ! zstd </dev/null >/dev/null 2>&1 ; then
182 test -f "$BUILD_DIR/zstddec.sh" || cleanup_and_exit 3 "no zstd decoder available in host system"
183 PAYLOADDECOMPRESS="bash $BUILD_DIR/zstddec.sh"
186 if test "$PAYLOADDECOMPRESS" = cat ; then
187 rpm2cpio "$BUILD_ROOT/.init_b_cache/rpms/$PKG.rpm" | $CPIO
189 rpm2cpio "$BUILD_ROOT/.init_b_cache/rpms/$PKG.rpm" | $PAYLOADDECOMPRESS | $CPIO
191 if test -e ".init_b_cache/scripts/$PKG.run" ; then
192 rpm -qp --nodigest --nosignature --qf "%{PREIN}" "'$BUILD_ROOT'/.init_b_cache/rpms/$PKG.rpm" > ".init_b_cache/scripts/$PKG.pre"
193 rpm -qp --nodigest --nosignature --qf "%{POSTIN}" "'$BUILD_ROOT'/.init_b_cache/rpms/$PKG.rpm" > ".init_b_cache/scripts/$PKG.post"
194 echo -n '(none)' > .init_b_cache/scripts/.none
195 cmp -s ".init_b_cache/scripts/$PKG.pre" .init_b_cache/scripts/.none && rm -f ".init_b_cache/scripts/$PKG.pre"
196 cmp -s ".init_b_cache/scripts/$PKG.post" .init_b_cache/scripts/.none && rm -f ".init_b_cache/scripts/$PKG.post"
197 rm -f .init_b_cache/scripts/.none
199 # hack for rpm erasures
200 if test -d "$BUILD_ROOT/installed-pkg" ; then
201 # call for rpm-4.x and not rpm-devel
202 test -z "${PKG##rpm-[0-9]*}" && chroot "$BUILD_ROOT" rpm --rebuilddb
203 # also exec for exchanged rpm ! naming is rpm-x86-<target>-<ver>
204 test -z "${PKG##rpm-x86-*[0-9]*}" && chroot "$BUILD_ROOT" rpm --rebuilddb
208 pkg_runscripts_rpm() {
209 if test -e "$BUILD_ROOT/.init_b_cache/scripts/$PKG.pre" ; then
210 echo "running $PKG preinstall script"
211 (cd "$BUILD_ROOT" && chroot "$BUILD_ROOT" sh ".init_b_cache/scripts/$PKG.pre" 0)
212 rm -f "$BUILD_ROOT/.init_b_cache/scripts/$PKG.pre"
214 if test -e "$BUILD_ROOT/.init_b_cache/scripts/$PKG.post" ; then
215 echo "running $PKG postinstall script"
216 (cd "$BUILD_ROOT" && chroot "$BUILD_ROOT" sh ".init_b_cache/scripts/$PKG.post" 1)
217 rm -f "$BUILD_ROOT/.init_b_cache/scripts/$PKG.post"