Debian Codegraph @

build-pkg-rpm

raw
1 #
2 # RPM specific functions.
3 #
4 ################################################################
5 #
6 # Copyright (c) 1995-2014 SUSE Linux Products GmbH
7 #
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.
11 #
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.
16 #
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
21 #
22 ################################################################
23
24
25 pkg_initdb_rpm() {
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
32 else
33 chroot $BUILD_ROOT rpm --initdb || cleanup_and_exit 1
34 fi
35 fi
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
41 }
42
43 pkg_prepare_rpm() {
44 rpm_set_checkopts
45 rpm_init_cumulate
46 }
47
48 pkg_erase_rpm() {
49 chroot $BUILD_ROOT rpm --nodeps -e $PKG 2>&1 | {
50 local retry
51 while read line; do
52 case "$line" in
53 r*failed:\ No\ such\ file\ or\ directory) ;;
54 error:\ failed\ to\ stat\ *:\ No\ such\ file\ or\ directory) ;;
55 error:\ *scriptlet\ failed*)
56 echo "$line"
57 retry=1
58 ;;
59 *) echo "$line" ;;
60 esac
61 done
62 if test -n "$retry" ; then
63 echo "re-try deleting $PKG using --noscripts"
64 chroot $BUILD_ROOT rpm --nodeps --noscripts -e $PKG || true
65 fi
66 }
67 }
68
69 rpm_set_checkopts() {
70 RPMCHECKOPTS=
71 # on Fedora 10 rpmbuild is in a separate package so we need something else to
72 # detect rpm4
73 test -x $BUILD_ROOT/usr/bin/rpmquery && RPMCHECKOPTS="--nodigest --nosignature"
74 }
75
76 rpm_init_cumulate() {
77 cumulate=-1
78 CUMULATED_LIST=()
79 CUMULATED_PIDS=()
80 CUMULATED_HMD5=()
81 DO_CUMULATE=
82 typeset -ri suse_version=$(chroot $BUILD_ROOT rpm --eval '%{?suse_version}' 2>/dev/null)
83 if ((suse_version > 1220)) ; then
84 DO_CUMULATE=true
85 fi
86 }
87
88 pkg_verify_installed_rpm() {
89 chroot $BUILD_ROOT rpm --verify $PKG 2>&1 | tee $TMPFILE
90 if grep ^missing $TMPFILE > /dev/null ; then
91 return 1
92 fi
93 return 0
94 }
95
96 pkg_cumulate_rpm() {
97 test "$DO_CUMULATE" = true || return 1
98 # work around for cross-build installs, we must not overwrite the running rpm
99 if test "$PKG" = rpm ; then
100 for i in $BUILD_ROOT/.init_b_cache/preinstalls/rpm-x86-* ; do
101 test -e "$i" && return 1
102 done
103 fi
104 let cumulate++
105 CUMULATED_LIST[$cumulate]=".init_b_cache/$PKG.rpm"
106 CUMULATED_PIDS[$cumulate]="$PKGID"
107 CUMULATED_HMD5[$cumulate]="$PKG_HDRMD5"
108 return 0
109 }
110
111 pkg_install_rpm() {
112 export ADDITIONAL_PARAMS=
113 if test "$USE_FORCE" = true ; then
114 export ADDITIONAL_PARAMS="$ADDITIONAL_PARAMS --force"
115 fi
116 # work around for cross-build installs, we must not overwrite the running rpm
117 if test "$PKG" = rpm ; then
118 for i in $BUILD_ROOT/.init_b_cache/preinstalls/rpm-x86-* ; do
119 test -e "$i" && ADDITIONAL_PARAMS="$ADDITIONAL_PARAMS --justdb"
120 done
121 fi
122 ( cd $BUILD_ROOT && chroot $BUILD_ROOT rpm --ignorearch --nodeps -U --oldpackage --ignoresize $RPMCHECKOPTS \
123 $ADDITIONAL_PARAMS .init_b_cache/$PKG.rpm 2>&1 || \
124 touch $BUILD_ROOT/exit ) | \
125 grep -v "^warning:.*saved as.*rpmorig$"
126 }
127
128 pkg_finalize_rpm() {
129 if test -n "${CUMULATED_LIST[*]}" ; then
130 echo "now installing cumulated packages"
131 for ((num=0; num<=cumulate; num++)) ; do
132 echo ${CUMULATED_LIST[$num]}
133 PKG=${CUMULATED_LIST[$num]##*/}
134 test "$BUILD_ROOT/.init_b_cache/rpms/$PKG" -ef "$BUILD_ROOT/${CUMULATED_LIST[$num]}" && continue
135 rm -f $BUILD_ROOT/${CUMULATED_LIST[$num]}
136 cp $BUILD_ROOT/.init_b_cache/rpms/$PKG $BUILD_ROOT/${CUMULATED_LIST[$num]} || cleanup_and_exit 1
137 done > $BUILD_ROOT/.init_b_cache/manifest
138 ( cd $BUILD_ROOT && chroot $BUILD_ROOT rpm --ignorearch --nodeps -Uh --oldpackage --ignoresize --verbose $RPMCHECKOPTS \
139 $ADDITIONAL_PARAMS .init_b_cache/manifest 2>&1 || touch $BUILD_ROOT/exit )
140 for ((num=0; num<=cumulate; num++)) ; do
141 rm -f $BUILD_ROOT/${CUMULATED_LIST[$num]}
142 done
143 rm -f $BUILD_ROOT/.init_b_cache/manifest
144 check_exit
145 for ((num=0; num<=cumulate; num++)) ; do
146 PKG=${CUMULATED_LIST[$num]##*/}
147 echo "${CUMULATED_PIDS[$num]}" > $BUILD_ROOT/installed-pkg/${PKG%.rpm}
148 test -n "${CUMULATED_HMD5[$num]}" || continue
149 echo "${CUMULATED_HMD5[$num]} ${CUMULATED_PIDS[$num]}" > $BUILD_ROOT/.preinstall_image/${PKG%.rpm}
150 done
151 fi
152 }
153
154 pkg_preinstall_rpm() {
155 PAYLOADDECOMPRESS=cat
156 case `rpm -qp --nodigest --nosignature --qf "%{PAYLOADCOMPRESSOR}\n" "$BUILD_INIT_CACHE/rpms/$PKG.rpm"` in
157 lzma) rpm --showrc | egrep 'PayloadIsLzma|_lzma' > /dev/null || PAYLOADDECOMPRESS="lzma -d" ;;
158 xz) rpm --showrc | egrep 'PayloadIsXz|_xz' > /dev/null || PAYLOADDECOMPRESS="xz -d" ;;
159 zstd) rpm --showrc | egrep 'PayloadIsZstd' > /dev/null || PAYLOADDECOMPRESS="zstd -d" ;;
160 esac
161 if test "$PAYLOADDECOMPRESS" = "lzma -d" ; then
162 if ! lzma </dev/null >/dev/null 2>&1 ; then
163 test -f "$BUILD_DIR/lzmadec.sh" || cleanup_and_exit 3 "no lzma decoder available in host system"
164 PAYLOADDECOMPRESS="bash $BUILD_DIR/lzmadec.sh"
165 fi
166 fi
167 if test "$PAYLOADDECOMPRESS" = "xz -d" ; then
168 if ! xz </dev/null >/dev/null 2>&1 ; then
169 test -f "$BUILD_DIR/xzdec.sh" || cleanup_and_exit 3 "no xz decoder available in host system"
170 PAYLOADDECOMPRESS="bash $BUILD_DIR/xzdec.sh"
171 fi
172 fi
173 if test "$PAYLOADDECOMPRESS" = "zstd -d" ; then
174 if ! zstd </dev/null >/dev/null 2>&1 ; then
175 test -f "$BUILD_DIR/zstddec.sh" || cleanup_and_exit 3 "no zstd decoder available in host system"
176 PAYLOADDECOMPRESS="bash $BUILD_DIR/zstddec.sh"
177 fi
178 fi
179 mkdir -p "$BUILD_INIT_CACHE/scripts"
180 if test "$PAYLOADDECOMPRESS" = cat ; then
181 rpm2cpio "$BUILD_INIT_CACHE/rpms/$PKG.rpm" | $CPIO || cleanup_and_exit 1
182 else
183 rpm2cpio "$BUILD_INIT_CACHE/rpms/$PKG.rpm" | $PAYLOADDECOMPRESS | $CPIO || cleanup_and_exit 1
184 fi
185 test -L "$BUILD_INIT_CACHE/scripts" && cleanup_and_exit 1
186 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"
187 if test -e "$BUILD_INIT_CACHE/scripts/$PKG.run" ; then
188 rpm -qp --nodigest --nosignature --qf "%{PREIN}" "$BUILD_INIT_CACHE/rpms/$PKG.rpm" > "$BUILD_INIT_CACHE/scripts/$PKG.pre"
189 rpm -qp --nodigest --nosignature --qf "%{PREINPROG}" "$BUILD_INIT_CACHE/rpms/$PKG.rpm" > "$BUILD_INIT_CACHE/scripts/$PKG.preprog"
190 rpm -qp --nodigest --nosignature --qf "%{POSTIN}" "$BUILD_INIT_CACHE/rpms/$PKG.rpm" > "$BUILD_INIT_CACHE/scripts/$PKG.post"
191 rpm -qp --nodigest --nosignature --qf "%{POSTINPROG}" "$BUILD_INIT_CACHE/rpms/$PKG.rpm" > "$BUILD_INIT_CACHE/scripts/$PKG.postprog"
192 rm -f "$BUILD_INIT_CACHE/scripts/.none"
193 echo -n '(none)' > "$BUILD_INIT_CACHE/scripts/.none"
194 cmp -s "$BUILD_INIT_CACHE/scripts/$PKG.pre" "$BUILD_INIT_CACHE/scripts/.none" && rm -f "$BUILD_INIT_CACHE/scripts/$PKG.pre"
195 cmp -s "$BUILD_INIT_CACHE/scripts/$PKG.post" "$BUILD_INIT_CACHE/scripts/.none" && rm -f "$BUILD_INIT_CACHE/scripts/$PKG.post"
196 rm -f "$BUILD_INIT_CACHE/scripts/.none"
197 fi
198 # hack for rpm erasures
199 if test -d "$BUILD_ROOT/installed-pkg" -a -z "$PREPARE_VM" ; then
200 # call for rpm-4.x and not rpm-devel
201 test -z "${PKG##rpm-[0-9]*}" && chroot . rpm --rebuilddb
202 # also exec for exchanged rpm ! naming is rpm-x86-<target>-<ver>
203 test -z "${PKG##rpm-x86-*[0-9]*}" && chroot . rpm --rebuilddb
204 fi
205 }
206
207 pkg_runscripts_rpm() {
208 if test -e "$BUILD_ROOT/.init_b_cache/scripts/$PKG.pre" ; then
209 echo "running $PKG preinstall script"
210 local prog
211 read prog < "$BUILD_ROOT/.init_b_cache/scripts/$PKG.preprog"
212 (cd $BUILD_ROOT && chroot $BUILD_ROOT "${prog:-sh}" ".init_b_cache/scripts/$PKG.pre" 0)
213 rm -f "$BUILD_ROOT/.init_b_cache/scripts/$PKG.pre" "$BUILD_ROOT/.init_b_cache/scripts/$PKG.preprog"
214 fi
215 if test -e "$BUILD_ROOT/.init_b_cache/scripts/$PKG.post" ; then
216 echo "running $PKG postinstall script"
217 local prog
218 read prog < "$BUILD_ROOT/.init_b_cache/scripts/$PKG.postprog"
219 (cd $BUILD_ROOT && chroot $BUILD_ROOT "${prog:-sh}" ".init_b_cache/scripts/$PKG.post" 1)
220 rm -f "$BUILD_ROOT/.init_b_cache/scripts/$PKG.post" "$BUILD_ROOT/.init_b_cache/scripts/$PKG.postprog"
221 fi
222 }