| 1 |
#!/bin/bash |
| 2 |
# Script to create a complete system to build packages in a chroot |
| 3 |
# environment. This script ensures, that all packages given as |
| 4 |
# parameter are installed. All other packges will be deleted. |
| 5 |
# |
| 6 |
# BUILD_ROOT here the packages will be installed/deleted |
| 7 |
# BUILD_RPMS here we get our packages to install (obsolete) |
| 8 |
# BUILD_ARCH path of the architectures we try |
| 9 |
# BUILD_DIST distribution to build for (will be guessed if not set) |
| 10 |
# |
| 11 |
################################################################ |
| 12 |
# |
| 13 |
# Copyright (c) 1997-2014 SUSE Linux Products GmbH |
| 14 |
# |
| 15 |
# This program is free software; you can redistribute it and/or modify |
| 16 |
# it under the terms of the GNU General Public License version 2 or 3 as |
| 17 |
# published by the Free Software Foundation. |
| 18 |
# |
| 19 |
# This program is distributed in the hope that it will be useful, |
| 20 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 21 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 22 |
# GNU General Public License for more details. |
| 23 |
# |
| 24 |
# You should have received a copy of the GNU General Public License |
| 25 |
# along with this program (see the file COPYING); if not, write to the |
| 26 |
# Free Software Foundation, Inc., |
| 27 |
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA |
| 28 |
# |
| 29 |
################################################################ |
| 30 |
|
| 31 |
# |
| 32 |
# needed globals variables |
| 33 |
# |
| 34 |
export SRC |
| 35 |
export BUILD_DIR=${BUILD_DIR:-/usr/lib/build} |
| 36 |
PATH="$BUILD_DIR:$PATH" |
| 37 |
|
| 38 |
export YAST_IS_RUNNING=instsys |
| 39 |
# https://github.com/systemd/systemd/blob/master/docs/ENVIRONMENT.md |
| 40 |
export SYSTEMD_OFFLINE=1 |
| 41 |
|
| 42 |
# slurp in package binary support |
| 43 |
. "$BUILD_DIR/build-pkg" |
| 44 |
|
| 45 |
# need to restore build root owner for non-root builds |
| 46 |
browner=0 |
| 47 |
definesnstuff=() |
| 48 |
repos=() |
| 49 |
|
| 50 |
. $BUILD_DIR/common_functions || exit 1 |
| 51 |
|
| 52 |
# should RPMs be installed with --force ? |
| 53 |
USE_FORCE=false |
| 54 |
PREPARE_VM= |
| 55 |
USEUSEDFORBUILD= |
| 56 |
LIST_STATE= |
| 57 |
RPMLIST= |
| 58 |
CLEAN_BUILD= |
| 59 |
CREATE_BUILD_BINARIES= |
| 60 |
DLNOSIGNATURE= |
| 61 |
CACHE_DIR=/var/cache/build |
| 62 |
test -z "$CONFIG_DIR" && CONFIG_DIR="$BUILD_DIR/configs" |
| 63 |
|
| 64 |
while test -n "$1" ; do |
| 65 |
case "$1" in |
| 66 |
--prepare) |
| 67 |
shift |
| 68 |
PREPARE_VM=true |
| 69 |
;; |
| 70 |
--create-build-binaries) |
| 71 |
shift |
| 72 |
CREATE_BUILD_BINARIES=true |
| 73 |
;; |
| 74 |
--useusedforbuild) |
| 75 |
shift |
| 76 |
USEUSEDFORBUILD=--useusedforbuild |
| 77 |
;; |
| 78 |
--list-state) |
| 79 |
shift |
| 80 |
LIST_STATE=true |
| 81 |
;; |
| 82 |
--rpmlist) |
| 83 |
shift |
| 84 |
RPMLIST=$1 |
| 85 |
shift |
| 86 |
;; |
| 87 |
--define|--with|--without|--buildflavor|--obspackage) |
| 88 |
definesnstuff[${#definesnstuff[@]}]="$1"; |
| 89 |
definesnstuff[${#definesnstuff[@]}]="$2"; |
| 90 |
shift 2 |
| 91 |
;; |
| 92 |
--repository|--repo) |
| 93 |
repos[${#repos[@]}]="$2"; |
| 94 |
shift 2 |
| 95 |
;; |
| 96 |
--clean) |
| 97 |
CLEAN_BUILD="$1" |
| 98 |
shift |
| 99 |
;; |
| 100 |
--cachedir) |
| 101 |
CACHE_DIR="$2" |
| 102 |
shift 2 |
| 103 |
;; |
| 104 |
--configdir) |
| 105 |
CONFIG_DIR="$2" |
| 106 |
shift 2 |
| 107 |
;; |
| 108 |
--nosignature) |
| 109 |
shift |
| 110 |
DLNOSIGNATURE="--nosignature" |
| 111 |
;; |
| 112 |
--root) |
| 113 |
BUILD_ROOT="$2" |
| 114 |
shift 2 |
| 115 |
;; |
| 116 |
--arch) |
| 117 |
BUILD_ARCH="$2" |
| 118 |
shift 2 |
| 119 |
;; |
| 120 |
--dist) |
| 121 |
BUILD_DIST="$2" |
| 122 |
shift 2 |
| 123 |
;; |
| 124 |
*) |
| 125 |
break |
| 126 |
;; |
| 127 |
esac |
| 128 |
done |
| 129 |
PKGS=("$@") |
| 130 |
|
| 131 |
if test -z "$BUILD_ROOT" ; then |
| 132 |
echo "Please specify a build root!" |
| 133 |
exit 1 |
| 134 |
fi |
| 135 |
|
| 136 |
BUILD_IS_RUNNING=$BUILD_ROOT/not-ready |
| 137 |
TMPFILE=$BUILD_ROOT/tmpfile |
| 138 |
BUILD_INIT_CACHE="$BUILD_ROOT/.init_b_cache" |
| 139 |
|
| 140 |
# |
| 141 |
# needed functions |
| 142 |
# |
| 143 |
|
| 144 |
mount_stuff() { |
| 145 |
if test "$UID" = 0 -a -n "$BUILD_ROOT" -a "$BUILD_ROOT" != / ; then |
| 146 |
mount -n -tproc none "$BUILD_ROOT/proc" |
| 147 |
test -e "$BUILD_ROOT/proc/self" || cleanup_and_exit 1 "Could not mount /proc, is this a container with missing capabilities?" |
| 148 |
mount -n -tdevpts -omode=0620,gid=5 none "$BUILD_ROOT/dev/pts" |
| 149 |
fi |
| 150 |
} |
| 151 |
|
| 152 |
umount_stuff() { |
| 153 |
if test -n "$BUILD_ROOT" -a "$BUILD_ROOT" != / ; then |
| 154 |
buildroot_umount "/proc/sys/fs/binfmt_misc" |
| 155 |
buildroot_umount "/proc" |
| 156 |
buildroot_umount "/sys" |
| 157 |
buildroot_umount "/dev/pts" |
| 158 |
buildroot_umount "/dev/shm" |
| 159 |
buildroot_umount "/mnt" |
| 160 |
fi |
| 161 |
} |
| 162 |
|
| 163 |
cleanup_and_exit() { |
| 164 |
trap EXIT |
| 165 |
test -z "$1" && set 0 |
| 166 |
if test -n "$2" ; then |
| 167 |
if test "$1" -ne 0 ; then |
| 168 |
echo "$2" >&2 |
| 169 |
else |
| 170 |
echo "$2" |
| 171 |
fi |
| 172 |
fi |
| 173 |
test "$BUILD_ROOT" = / -a -n "$browner" && chown "$browner" "$BUILD_ROOT" |
| 174 |
# umount so init_buildsystem can be used standalone |
| 175 |
umount_stuff |
| 176 |
exit $1 |
| 177 |
} |
| 178 |
|
| 179 |
clean_build_root() { |
| 180 |
if test -n "$BUILD_ROOT" -a "$BUILD_ROOT" != / ; then |
| 181 |
umount_stuff |
| 182 |
rm -rf -- "$BUILD_ROOT"/* 2> /dev/null || true |
| 183 |
chattr -a -A -i -R -- "$BUILD_ROOT" 2> /dev/null || true # does not follow symlinks |
| 184 |
rm -rf -- "$BUILD_ROOT"/* |
| 185 |
rm -rf -- "$BUILD_ROOT/.build" |
| 186 |
rm -rf -- "$BUILD_ROOT"/.build.kernel.* |
| 187 |
rm -rf -- "$BUILD_ROOT"/.build.initrd.* |
| 188 |
rm -rf -- "$BUILD_ROOT/.root" |
| 189 |
rm -rf -- "$BUILD_ROOT/.init_b_cache" |
| 190 |
test -L "$BUILD_ROOT/.preinstall_image" && rm -f -- "$BUILD_ROOT/.preinstall_image" |
| 191 |
rm -rf -- "$BUILD_ROOT"/.preinstall_image/* |
| 192 |
rm -rf -- "$BUILD_ROOT"/.preinstallimage* |
| 193 |
fi |
| 194 |
} |
| 195 |
|
| 196 |
unsafe_preinstall_check() { |
| 197 |
# cpio isn't safe so we require bsdtar for VMs. chroot is |
| 198 |
# unsafe anyways so it's ok for that. |
| 199 |
if test -n "$PREPARE_VM" ; then |
| 200 |
echo "Error: setting up a VM requires bsdtar for security reasons." |
| 201 |
echo "Please install bsdtar." |
| 202 |
cleanup_and_exit 1 |
| 203 |
fi |
| 204 |
} |
| 205 |
|
| 206 |
preinstall_image_filter() { |
| 207 |
for PKG in "$@" ; do |
| 208 |
test -e "$BUILD_ROOT/.preinstall_image/$PKG" && continue |
| 209 |
echo $PKG |
| 210 |
done |
| 211 |
} |
| 212 |
|
| 213 |
preinstall_setup() { |
| 214 |
cd "$BUILD_ROOT" || cleanup_and_exit 1 |
| 215 |
rm -rf build-preinstall |
| 216 |
mkdir build-preinstall || cleanup_and_exit 1 |
| 217 |
for i in * .* ; do |
| 218 |
# please keep in sync with recipe_build_preinstallimage |
| 219 |
case "$i" in |
| 220 |
.|..|build-preinstall) continue ;; |
| 221 |
.build.kernel.*|.build.hostarch.*|.build.initrd.*|.build.console.*) ;; |
| 222 |
.build*|.init_b_cache|.preinstallimage*|.srcfiles*|.pkgs|.rpm-cache|installed-pkg|proc|sys) continue ;; |
| 223 |
esac |
| 224 |
mv "./$i" build-preinstall || cleanup_and_exit 1 |
| 225 |
done |
| 226 |
cd build-preinstall || cleanup_and_exit 1 |
| 227 |
} |
| 228 |
|
| 229 |
preinstall_integrate() { |
| 230 |
cd "$BUILD_ROOT/build-preinstall" || cleanup_and_exit 1 |
| 231 |
for i in * .* ; do |
| 232 |
case "$i" in |
| 233 |
.|..|build-preinstall) continue ;; |
| 234 |
.build.kernel.*|.build.hostarch.*|.build.initrd.*|.build.console.*) ;; |
| 235 |
.build*|.init_b_cache|.preinstallimage*|.srcfiles*|.pkgs|.rpm-cache|installed-pkg|proc|sys) continue ;; |
| 236 |
esac |
| 237 |
mv "./$i" .. || cleanup_and_exit 1 |
| 238 |
done |
| 239 |
cd "$BUILD_ROOT" || cleanup_and_exit 1 |
| 240 |
assert_dirs |
| 241 |
} |
| 242 |
|
| 243 |
preinstall_image() { |
| 244 |
check_exit |
| 245 |
echo "unpacking preinstall image${2:+ $2}" |
| 246 |
preinstall_setup |
| 247 |
if test -x /usr/bin/bsdtar ; then |
| 248 |
TAR="/usr/bin/bsdtar --exclude .build --exclude .init_b_cache -P --chroot --numeric-owner -x" |
| 249 |
else |
| 250 |
unsafe_preinstall_check |
| 251 |
TAR="tar --exclude .build --exclude .init_b_cache -x" |
| 252 |
fi |
| 253 |
# pipe output through perl to print a dot every 1000 lines |
| 254 |
if ! $TAR -z -f "$BUILD_INIT_CACHE/rpms/$1" -v > >(tee "$BUILD_INIT_CACHE/.preinstallimage.unpack" | perl -e '$|=1; my $done=0; $done++ % 1000 or print "." while <STDIN>; print "\n";') 2>&1 ; then |
| 255 |
echo "unpack failed." |
| 256 |
test -f "$BUILD_INIT_CACHE/.preinstallimage.unpack" && cat "$BUILD_INIT_CACHE/.preinstallimage.unpack" |
| 257 |
cleanup_and_exit 1 |
| 258 |
fi |
| 259 |
rm -rf "$BUILD_INIT_CACHE/.preinstallimage.unpack" |
| 260 |
preinstall_integrate |
| 261 |
} |
| 262 |
|
| 263 |
preinstall() { |
| 264 |
local PKG="$1" |
| 265 |
check_exit |
| 266 |
echo "preinstalling $PKG..." |
| 267 |
preinstall_setup |
| 268 |
if test -x /usr/bin/bsdtar ; then |
| 269 |
CPIO="/usr/bin/bsdtar --exclude .build --exclude .init_b_cache -P --chroot -o --numeric-owner -x -f-" |
| 270 |
TAR="/usr/bin/bsdtar --exclude .build --exclude .init_b_cache -P --chroot -o --numeric-owner -x" |
| 271 |
else |
| 272 |
unsafe_preinstall_check |
| 273 |
CPIO="cpio --extract --unconditional --preserve-modification-time --make-directories --no-absolute-filenames --quiet" |
| 274 |
TAR="tar --exclude .build --exclude .init_b_cache -x" |
| 275 |
fi |
| 276 |
pkg_preinstall |
| 277 |
preinstall_integrate |
| 278 |
} |
| 279 |
|
| 280 |
run_pkg_scripts() { |
| 281 |
chroot $BUILD_ROOT /sbin/ldconfig 2>/dev/null |
| 282 |
for PKG in $PACKAGES_TO_RUNSCRIPTS ; do |
| 283 |
pkg_runscripts |
| 284 |
check_exit |
| 285 |
done |
| 286 |
} |
| 287 |
|
| 288 |
reorder() { |
| 289 |
test -z "$*" && return |
| 290 |
rm -f $BUILD_ROOT/.init_b_cache/order.manifest |
| 291 |
for PKG in "$@" ; do |
| 292 |
echo "$PKG" >> $BUILD_ROOT/.init_b_cache/order.manifest |
| 293 |
done |
| 294 |
$BUILD_DIR/order --dist "$BUILD_DIST" --archpath "$BUILD_ARCH" --configdir $CONFIG_DIR --manifest $BUILD_ROOT/.init_b_cache/order.manifest $BUILD_ROOT/.init_b_cache/rpms || touch $BUILD_ROOT/exit |
| 295 |
rm -f $BUILD_ROOT/.init_b_cache/order.manifest |
| 296 |
} |
| 297 |
|
| 298 |
create_devs() { |
| 299 |
local com file mode arg |
| 300 |
|
| 301 |
test -d $BUILD_ROOT/dev/pts -a ! -L $BUILD_ROOT/dev/pts || rm -f $BUILD_ROOT/dev/pts |
| 302 |
test -d $BUILD_ROOT/dev/shm -a ! -L $BUILD_ROOT/dev/shm || rm -f $BUILD_ROOT/dev/shm |
| 303 |
mkdir -m 755 -p $BUILD_ROOT/dev/pts |
| 304 |
mkdir -m 755 -p $BUILD_ROOT/dev/shm |
| 305 |
while read com file mode arg ; do |
| 306 |
rm -f $BUILD_ROOT/dev/$file |
| 307 |
if test $com = ln ; then |
| 308 |
ln -s $arg $BUILD_ROOT/dev/$file |
| 309 |
elif test $com = mknod ; then |
| 310 |
mknod -m $mode $BUILD_ROOT/dev/$file $arg |
| 311 |
fi |
| 312 |
done << DEVLIST |
| 313 |
mknod null 666 c 1 3 |
| 314 |
mknod zero 666 c 1 5 |
| 315 |
mknod full 666 c 1 7 |
| 316 |
mknod random 666 c 1 8 |
| 317 |
mknod urandom 644 c 1 9 |
| 318 |
mknod tty 666 c 5 0 |
| 319 |
mknod ptmx 666 c 5 2 |
| 320 |
mknod loop-control 600 c 10 237 |
| 321 |
mknod loop0 640 b 7 0 |
| 322 |
mknod loop1 640 b 7 1 |
| 323 |
mknod loop2 640 b 7 2 |
| 324 |
mknod loop3 640 b 7 3 |
| 325 |
mknod fuse 666 c 10 229 |
| 326 |
ln fd 777 /proc/self/fd |
| 327 |
ln stdin 777 fd/0 |
| 328 |
ln stdout 777 fd/1 |
| 329 |
ln stderr 777 fd/2 |
| 330 |
DEVLIST |
| 331 |
} |
| 332 |
|
| 333 |
# check whether the repo list contains a plain "zypp://". Add all |
| 334 |
# enabled zypp repos in this case |
| 335 |
expand_plain_zypp_repo() { |
| 336 |
local i j |
| 337 |
r=() |
| 338 |
for i in "${repos[@]}"; do |
| 339 |
if test "$i" = "zypp://" ; then |
| 340 |
for j in $($BUILD_DIR/createzyppdeps --listrepos) ; do |
| 341 |
r=("${r[@]}" "zypp://$j") |
| 342 |
done |
| 343 |
else |
| 344 |
r=("${r[@]}" "$i") |
| 345 |
fi |
| 346 |
done |
| 347 |
repos=("${r[@]}") |
| 348 |
} |
| 349 |
|
| 350 |
create_cache_file() { |
| 351 |
local findonly= |
| 352 |
expand_plain_zypp_repo |
| 353 |
|
| 354 |
# check if we can reuse the old cache file |
| 355 |
if ! test -f $CACHE_FILE || ! test -f $CACHE_FILE.id || \ |
| 356 |
test "${repos[*]} ${BUILD_RPMS//:/ /}" != "$(cat $CACHE_FILE.id 2>/dev/null)"; then |
| 357 |
rm -f $CACHE_FILE.id |
| 358 |
else |
| 359 |
for SRC in "${repos[@]}" ${BUILD_RPMS//:/ /}; do |
| 360 |
test -n "$SRC" || SRC=. |
| 361 |
if test "${SRC#zypp://}" != "$SRC" ; then |
| 362 |
SRC="/var/cache/zypp/raw/${SRC#zypp://}" |
| 363 |
fi |
| 364 |
if test "$SRC" -nt $CACHE_FILE; then |
| 365 |
rm -f $CACHE_FILE.id |
| 366 |
break |
| 367 |
fi |
| 368 |
# always rebuild if we have remote repositories and --clean is given |
| 369 |
if test -n "$CLEAN_BUILD" -a "$SRC" != "${SRC#*://}" -a "${SRC#zypp://}" = "$SRC" ; then |
| 370 |
rm -f $CACHE_FILE.id |
| 371 |
break |
| 372 |
fi |
| 373 |
done |
| 374 |
fi |
| 375 |
if test -f $CACHE_FILE.id ; then |
| 376 |
return |
| 377 |
fi |
| 378 |
|
| 379 |
# nope, generate a new cache file |
| 380 |
test -z "$LIST_STATE" && echo initializing $CACHE_FILE ... |
| 381 |
|
| 382 |
# figure out a repository type default |
| 383 |
REPOTYPE= |
| 384 |
if test -n "$BUILD_DIST" ; then |
| 385 |
for i in `queryconfig repotype --dist "$BUILD_DIST" --configdir "$CONFIG_DIR" --archpath "$BUILD_ARCH"` ; do |
| 386 |
case $i in |
| 387 |
arch|debian|hdlist2|rpm-md) REPOTYPE=$i ;; |
| 388 |
esac |
| 389 |
test -n "$REPOTYPE" && break |
| 390 |
done |
| 391 |
if test -z "$REPOTYPE"; then |
| 392 |
BINTYPE=`queryconfig binarytype --dist "$BUILD_DIST" --configdir "$CONFIG_DIR" --archpath "$BUILD_ARCH"` |
| 393 |
case "$BINTYPE" in |
| 394 |
arch) REPOTYPE=arch ;; |
| 395 |
deb) REPOTYPE=debian ;; |
| 396 |
esac |
| 397 |
fi |
| 398 |
fi |
| 399 |
if test -z "$REPOTYPE" ; then |
| 400 |
# check the first init_buildsystem arg, maybe it is a recipe |
| 401 |
case ${PKGS[0]} in |
| 402 |
*.spec) |
| 403 |
REPOTYPE=rpm-md ;; |
| 404 |
*.dsc) |
| 405 |
REPOTYPE=debian ;; |
| 406 |
*/PKGBUILD|PKGBUILD|*/_service:*:PKGBUILD|_service:*:PKGBUILD) |
| 407 |
REPOTYPE=arch ;; |
| 408 |
esac |
| 409 |
fi |
| 410 |
for SRC in "${repos[@]}" -- ${BUILD_RPMS//:/ /}; do |
| 411 |
if test "$SRC" = '--' ; then |
| 412 |
findonly=1 |
| 413 |
continue |
| 414 |
fi |
| 415 |
SRCREPOTYPE=$REPOTYPE |
| 416 |
case $SRC in |
| 417 |
arch@* | debian@* | hdlist2@* | rpmmd@* | rpm-md@* | suse@*) |
| 418 |
SRCREPOTYPE=${SRC%%@*} |
| 419 |
SRC=${SRC#*@} |
| 420 |
;; |
| 421 |
esac |
| 422 |
test -z "$SRC" && SRC=`pwd` |
| 423 |
if test "${SRC#http://}" != "$SRC" -o "${SRC#https://}" != "$SRC" -o "${SRC#ftp://}" != "$SRC" -o "${SRC#ftps://}" != "$SRC" ; then |
| 424 |
# remote repo, cache binary packages |
| 425 |
mkdir -p "$(getcachedir "$SRC")" |
| 426 |
if test "$SRCREPOTYPE" = arch ; then |
| 427 |
set -- $BUILD_DIR/createarchdeps --cachedir="$CACHE_DIR" "$SRC" |
| 428 |
elif test "$SRCREPOTYPE" = debian ; then |
| 429 |
set -- $BUILD_DIR/createdebdeps --cachedir="$CACHE_DIR" --archpath "$BUILD_ARCH" "$SRC" |
| 430 |
elif test "$SRCREPOTYPE" = suse ; then |
| 431 |
set -- $BUILD_DIR/createyastdeps --cachedir="$CACHE_DIR" "$SRC" |
| 432 |
elif test "$SRCREPOTYPE" = hdlist2 ; then |
| 433 |
set -- $BUILD_DIR/createmdkdeps --cachedir="$CACHE_DIR" "$SRC" |
| 434 |
else |
| 435 |
set -- $BUILD_DIR/createrepomddeps --cachedir="$CACHE_DIR" "$SRC" |
| 436 |
fi |
| 437 |
elif test "${SRC#zypp://}" != "$SRC" ; then |
| 438 |
# special zypp repo |
| 439 |
set -- $BUILD_DIR/createzyppdeps --cachedir="$CACHE_DIR" "$SRC" |
| 440 |
elif test ! -e "$SRC" ; then |
| 441 |
cleanup_and_exit 1 "*** $SRC does not exist" |
| 442 |
elif test -z "$findonly" -a \( -e "$SRC"/suse/setup/descr/packages -o -e "$SRC"/suse/setup/descr/packages.gz \) ; then |
| 443 |
set -- $BUILD_DIR/createyastdeps "$SRC" |
| 444 |
elif test -z "$findonly" -a -e "$SRC"/repodata/repomd.xml ; then |
| 445 |
set -- $BUILD_DIR/createrepomddeps "$SRC" |
| 446 |
else |
| 447 |
set -- $BUILD_DIR/createdirdeps --oldfile "$CACHE_FILE" "$SRC" |
| 448 |
fi |
| 449 |
echo "$@" >&2 |
| 450 |
"$@" || cleanup_and_exit 1 |
| 451 |
echo D: |
| 452 |
done > $CACHE_FILE.new |
| 453 |
|
| 454 |
mv $CACHE_FILE.new $CACHE_FILE |
| 455 |
echo "${repos[*]} ${BUILD_RPMS//:/ /}" > $CACHE_FILE.id |
| 456 |
} |
| 457 |
|
| 458 |
fail_exit() { |
| 459 |
cleanup_and_exit 1 |
| 460 |
} |
| 461 |
|
| 462 |
# modifies $SRC |
| 463 |
downloadpkg() { |
| 464 |
local url="$1" |
| 465 |
|
| 466 |
case $url in |
| 467 |
zypp://* | http://* | https://* | ftp://* | ftps://*) ;; |
| 468 |
*) cleanup_and_exit 1 "Invalid url: $url" ;; |
| 469 |
esac |
| 470 |
|
| 471 |
local cachedir="$(getcachedir "$url")" |
| 472 |
local name="$(basename "$url")" |
| 473 |
name=${name/%.pkg.tar.zst/.arch} |
| 474 |
name=${name/%.pkg.tar.?z/.arch} |
| 475 |
SRC="$cachedir/$name" |
| 476 |
local destdir="$cachedir/tmp" |
| 477 |
mkdir -p "$destdir" |
| 478 |
echo "downloading $url ... "; |
| 479 |
$BUILD_DIR/download "$destdir" "$url" || cleanup_and_exit 1 |
| 480 |
local destfile="$destdir/${url##*/}" |
| 481 |
if test ! -e "$destfile" ; then |
| 482 |
cleanup_and_exit 1 "expected $destfile after download but it's missing" |
| 483 |
fi |
| 484 |
# for rpm check integrity and the signature |
| 485 |
case $destfile in |
| 486 |
*.rpm) |
| 487 |
rpm -K $DLNOSIGNATURE "$destfile" > $destfile.v || { echo "rpm verify failed" >&2; rm -rf "$destdir"; cleanup_and_exit 1; } |
| 488 |
if grep "NOT OK" $destfile.v; then |
| 489 |
rm -rf "$destdir" |
| 490 |
cleanup_and_exit 1 |
| 491 |
fi |
| 492 |
rm -f "$destfile.v" |
| 493 |
;; |
| 494 |
esac |
| 495 |
mv "$destfile" "$SRC" || cleanup_and_exit 1 |
| 496 |
} |
| 497 |
|
| 498 |
getcachedir() { |
| 499 |
local url=$1 |
| 500 |
for repo in "${repos[@]}" ; do |
| 501 |
case $repo in |
| 502 |
arch@* | debian@* | hdlist2@* | rpmmd@* | rpm-md@* | suse@*) repo=${repo#*@} ;; |
| 503 |
esac |
| 504 |
if test "${url:0:${#repo}}" == "$repo" ; then |
| 505 |
read repoid dummy < <(echo -n "$repo" | md5sum) |
| 506 |
echo "$CACHE_DIR/$repoid" |
| 507 |
break |
| 508 |
fi |
| 509 |
done |
| 510 |
} |
| 511 |
|
| 512 |
set_build_arch |
| 513 |
|
| 514 |
trap fail_exit EXIT |
| 515 |
|
| 516 |
if test "$BUILD_ROOT" = / ; then |
| 517 |
browner="$(stat -c %u /)" |
| 518 |
fi |
| 519 |
|
| 520 |
if test -n "$CLEAN_BUILD" ; then |
| 521 |
clean_build_root |
| 522 |
fi |
| 523 |
|
| 524 |
# |
| 525 |
# now test if there was an incomplete run |
| 526 |
# |
| 527 |
if test -e "$BUILD_IS_RUNNING" ; then |
| 528 |
echo "It seems that there was an incomplete setup of $BUILD_ROOT." |
| 529 |
if test -z "$BUILD_ROOT" -o "$BUILD_ROOT" = / ; then |
| 530 |
cleanup_and_exit 1 |
| 531 |
fi |
| 532 |
echo "To be sure, we will build it again completely..." |
| 533 |
umount_stuff |
| 534 |
echo "Your build system is broken!! Shall I execute" |
| 535 |
echo |
| 536 |
echo " rm -rf -- $BUILD_ROOT/*" |
| 537 |
echo |
| 538 |
echo "y - yes, cleanup the build root" |
| 539 |
echo "N - No, abort build (default on enter)" |
| 540 |
echo "c - Continue anyway with this build root" |
| 541 |
echo -n "[y/N/c] " |
| 542 |
read ANSWER |
| 543 |
case "$ANSWER" in |
| 544 |
c|C) |
| 545 |
rm -f $BUILD_IS_RUNNING $BUILD_ROOT/exit ;; |
| 546 |
y|Y) |
| 547 |
clean_build_root ;; |
| 548 |
*) |
| 549 |
cleanup_and_exit 1 ;; |
| 550 |
esac |
| 551 |
fi |
| 552 |
|
| 553 |
# check for surprises |
| 554 |
if test -z "$CLEAN_BUILD" -a -n "$BUILD_ROOT" -a "$BUILD_ROOT" != / ; then |
| 555 |
assert_dirs |
| 556 |
fi |
| 557 |
# umount stuff if mounted |
| 558 |
if test -n "$BUILD_ROOT" -a "$BUILD_ROOT" != / -a -e "$BUILD_ROOT/proc/self" ; then |
| 559 |
umount_stuff |
| 560 |
fi |
| 561 |
|
| 562 |
# |
| 563 |
# store that we start to build the system |
| 564 |
# |
| 565 |
mkdir -p "$BUILD_ROOT" |
| 566 |
mkdir -p "$BUILD_ROOT/.build" |
| 567 |
mkdir -p "$BUILD_ROOT/proc" |
| 568 |
mkdir -p "$BUILD_ROOT/dev/pts" |
| 569 |
touch $BUILD_IS_RUNNING |
| 570 |
|
| 571 |
if test -n "$PREPARE_VM" ; then |
| 572 |
rm -rf $BUILD_ROOT/.build/init_buildsystem.data |
| 573 |
fi |
| 574 |
|
| 575 |
if test -e $BUILD_ROOT/.build/init_buildsystem.data ; then |
| 576 |
# vm continuation, read old config |
| 577 |
. $BUILD_ROOT/.build/init_buildsystem.data |
| 578 |
else |
| 579 |
# |
| 580 |
# now make sure that all the packages are installed. |
| 581 |
# |
| 582 |
rm -rf "$BUILD_ROOT/.init_b_cache" |
| 583 |
mkdir -p "$BUILD_ROOT/.init_b_cache/scripts" |
| 584 |
|
| 585 |
if test -z "$RPMLIST" ; then |
| 586 |
# |
| 587 |
# create rpmdeps file |
| 588 |
# |
| 589 |
CACHE_FILE=$BUILD_ROOT/.srcfiles.cache |
| 590 |
create_cache_file |
| 591 |
|
| 592 |
# |
| 593 |
# select and expand packages |
| 594 |
# |
| 595 |
RPMLIST=$BUILD_ROOT/.init_b_cache/rpmlist |
| 596 |
test -z "$LIST_STATE" && echo "expanding package dependencies..." |
| 597 |
VMOPT= |
| 598 |
test -z "$PREPARE_VM" || VMOPT=--vm |
| 599 |
if ! $BUILD_DIR/expanddeps $USEUSEDFORBUILD $VMOPT "${definesnstuff[@]}" --dist "$BUILD_DIST" --depfile "$CACHE_FILE" --archpath "$BUILD_ARCH" --configdir $CONFIG_DIR "${PKGS[@]}" > $RPMLIST ; then |
| 600 |
rm -f $BUILD_IS_RUNNING |
| 601 |
cleanup_and_exit 1 |
| 602 |
fi |
| 603 |
fi |
| 604 |
|
| 605 |
if test -n "$LIST_STATE" ; then |
| 606 |
rm -f $BUILD_IS_RUNNING |
| 607 |
while read PKG SRC ; do |
| 608 |
test "$PKG" = "preinstall:" && continue |
| 609 |
test "$PKG" = "runscripts:" && continue |
| 610 |
test "$PKG" = "cbpreinstall:" && continue |
| 611 |
test "$PKG" = "vminstall:" && continue |
| 612 |
test "$PKG" = "dist:" && continue |
| 613 |
test "$PKG" = "rpmid:" && continue |
| 614 |
echo "${SRC##*/}" |
| 615 |
done < $BUILD_ROOT/.init_b_cache/rpmlist |
| 616 |
rm -rf "$BUILD_ROOT/.init_b_cache" |
| 617 |
cleanup_and_exit 0 |
| 618 |
fi |
| 619 |
|
| 620 |
# |
| 621 |
# register the QEMU emulator if needed |
| 622 |
# (we do not need this for the prepare step, as we do not run scripts in this case) |
| 623 |
# |
| 624 |
if test -z "$PREPARE_VM" ; then |
| 625 |
if check_use_emulator ; then |
| 626 |
echo "registering binfmt handlers for cross build" |
| 627 |
"$BUILD_DIR/$INITVM_NAME" |
| 628 |
echo 0 > /proc/sys/vm/mmap_min_addr |
| 629 |
read mmap_min_addr < /proc/sys/vm/mmap_min_addr |
| 630 |
if test "$mmap_min_addr" != 0 ; then |
| 631 |
echo "Warning: mmap_min_addr is != 0. If programs fail at mmap this could be the reason." |
| 632 |
fi |
| 633 |
fi |
| 634 |
fi |
| 635 |
|
| 636 |
# |
| 637 |
# extract the data from the (generated) rpm list |
| 638 |
# |
| 639 |
PACKAGES_TO_INSTALL= |
| 640 |
PACKAGES_TO_PREINSTALL= |
| 641 |
PACKAGES_TO_RUNSCRIPTS= |
| 642 |
PACKAGES_TO_VMINSTALL= |
| 643 |
PACKAGES_TO_INSTALLONLY= |
| 644 |
PACKAGES_TO_NOINSTALL= |
| 645 |
PREINSTALL_IMAGE= |
| 646 |
PREINSTALL_IMAGE_SOURCE= |
| 647 |
RUNSCRIPTS_SEEN= |
| 648 |
PACKAGES_FROM_PREINSTALLIMAGE= |
| 649 |
GUESSED_DIST=unknown |
| 650 |
mkdir -p $BUILD_ROOT/.init_b_cache/rpms |
| 651 |
rm -f $BUILD_ROOT/.init_b_cache/rpmlist.download |
| 652 |
while read PKG SRC ; do |
| 653 |
if test "$PKG" = "preinstall:" ; then |
| 654 |
PACKAGES_TO_PREINSTALL=$SRC |
| 655 |
continue |
| 656 |
fi |
| 657 |
if test "$PKG" = "vminstall:" ; then |
| 658 |
PACKAGES_TO_VMINSTALL=$SRC |
| 659 |
continue |
| 660 |
fi |
| 661 |
if test "$PKG" = "installonly:" ; then |
| 662 |
PACKAGES_TO_INSTALLONLY=$SRC |
| 663 |
continue |
| 664 |
fi |
| 665 |
if test "$PKG" = "noinstall:" ; then |
| 666 |
PACKAGES_TO_NOINSTALL=$SRC |
| 667 |
continue |
| 668 |
fi |
| 669 |
if test "$PKG" = "preinstallimage:" ; then |
| 670 |
PREINSTALL_IMAGE=${SRC##*/} |
| 671 |
ln -s "$SRC" "$BUILD_ROOT/.init_b_cache/rpms/${SRC##*/}" |
| 672 |
continue |
| 673 |
fi |
| 674 |
if test "$PKG" = "preinstallimagesource:" ; then |
| 675 |
PREINSTALL_IMAGE_SOURCE="$SRC" |
| 676 |
continue |
| 677 |
fi |
| 678 |
if test "$PKG" = "runscripts:" ; then |
| 679 |
RUNSCRIPTS_SEEN=true |
| 680 |
PACKAGES_TO_RUNSCRIPTS=$SRC |
| 681 |
continue |
| 682 |
fi |
| 683 |
if test "$PKG" = "dist:" ; then |
| 684 |
GUESSED_DIST=$SRC |
| 685 |
continue |
| 686 |
fi |
| 687 |
if test "$PKG" = "rpmid:" ; then |
| 688 |
echo "${SRC#*:}" > $BUILD_ROOT/.init_b_cache/rpms/${SRC%%:*}.id |
| 689 |
continue |
| 690 |
fi |
| 691 |
if test "$PKG" != "${PKG%:}"; then |
| 692 |
echo "Warning: ignoring unsupported tag '$PKG'" >&2 |
| 693 |
continue |
| 694 |
fi |
| 695 |
if test "$SRC" = "preinstallimage" ; then |
| 696 |
PACKAGES_FROM_PREINSTALLIMAGE="$PACKAGES_FROM_PREINSTALLIMAGE $PKG" |
| 697 |
PACKAGES_TO_INSTALL="$PACKAGES_TO_INSTALL $PKG" |
| 698 |
continue |
| 699 |
fi |
| 700 |
PACKAGES_TO_INSTALL="$PACKAGES_TO_INSTALL $PKG" |
| 701 |
if test "${SRC#/}" = "$SRC" ; then |
| 702 |
case "$SRC" in |
| 703 |
zypp://* | http://* | https://* | ftp://* | ftps://*) |
| 704 |
echo "$PKG $SRC" >>$BUILD_ROOT/.init_b_cache/rpmlist.download |
| 705 |
continue |
| 706 |
;; |
| 707 |
*) |
| 708 |
cleanup_and_exit 1 "unsupported url for '$PKG': $SRC" |
| 709 |
;; |
| 710 |
esac |
| 711 |
fi |
| 712 |
SRCSUF=${SRC/%.pkg.tar.zst/.arch} |
| 713 |
SRCSUF=${SRCSUF/%.pkg.tar.?z/.arch} |
| 714 |
ln -s "$SRC" "$BUILD_ROOT/.init_b_cache/rpms/$PKG.${SRCSUF##*.}" |
| 715 |
done < $RPMLIST |
| 716 |
|
| 717 |
PACKAGES_TO_ALL="$PACKAGES_TO_INSTALL" |
| 718 |
PACKAGES_TO_AVAILABLE="$PACKAGES_TO_INSTALL" |
| 719 |
|
| 720 |
# subtract noinstall packages from PACKAGES_TO_INSTALL |
| 721 |
if test -n "$PACKAGES_TO_NOINSTALL" ; then |
| 722 |
settest=" $PACKAGES_TO_NOINSTALL " |
| 723 |
PACKAGES_TO_INSTALL= |
| 724 |
for PKG in $PACKAGES_TO_ALL ; do |
| 725 |
test "$settest" = "${settest/ $PKG /}" && PACKAGES_TO_INSTALL="$PACKAGES_TO_INSTALL $PKG" |
| 726 |
done |
| 727 |
fi |
| 728 |
# subtract installonly packages from PACKAGES_TO_AVAILABLE |
| 729 |
if test -n "$PACKAGES_TO_INSTALLONLY" ; then |
| 730 |
settest=" $PACKAGES_TO_INSTALLONLY " |
| 731 |
PACKAGES_TO_AVAILABLE= |
| 732 |
for PKG in $PACKAGES_TO_ALL ; do |
| 733 |
test "$settest" = "${settest/ $PKG /}" && PACKAGES_TO_AVAILABLE="$PACKAGES_TO_AVAILABLE $PKG" |
| 734 |
done |
| 735 |
fi |
| 736 |
|
| 737 |
# use cached packages where possible |
| 738 |
if test -s $BUILD_ROOT/.init_b_cache/rpmlist.download ; then |
| 739 |
echo "calculating packages to download..." |
| 740 |
while read PKG SRC ; do |
| 741 |
SRCSUF=${SRC/%.pkg.tar.zst/.arch} |
| 742 |
SRCSUF=${SRCSUF/%.pkg.tar.?z/.arch} |
| 743 |
if test -s "$BUILD_ROOT/.init_b_cache/rpms/$PKG.id" ; then |
| 744 |
read cachepkgid < $BUILD_ROOT/.init_b_cache/rpms/$PKG.id |
| 745 |
echo "PKG $PKG $cachepkgid" |
| 746 |
else |
| 747 |
echo "PKG $PKG" |
| 748 |
fi |
| 749 |
echo "DST $BUILD_ROOT/.init_b_cache/rpms/$PKG.${SRCSUF##*.}" |
| 750 |
if test "$SRC" != "${SRC#zypp://}" ; then |
| 751 |
# for zypp packages also look in the zypp cache |
| 752 |
cachedir="/var/cache/zypp/packages/${SRC#zypp://}" |
| 753 |
echo "CACHE ${cachedir%/*}/${SRC##*/}" |
| 754 |
fi |
| 755 |
cachedir="$(getcachedir "$SRC")" |
| 756 |
echo "CACHE $cachedir/${SRCSUF##*/}" |
| 757 |
done < $BUILD_ROOT/.init_b_cache/rpmlist.download | "$BUILD_DIR/getbuildids" cachecheck |
| 758 |
# remove found packages from download list |
| 759 |
rm -f $BUILD_ROOT/.init_b_cache/rpmlist.download2 |
| 760 |
while read PKG SRC ; do |
| 761 |
SRCSUF=${SRC/%.pkg.tar.zst/.arch} |
| 762 |
SRCSUF=${SRCSUF/%.pkg.tar.?z/.arch} |
| 763 |
test -L "$BUILD_ROOT/.init_b_cache/rpms/$PKG.${SRCSUF##*.}" || echo "$PKG $SRC" >>$BUILD_ROOT/.init_b_cache/rpmlist.download2 |
| 764 |
done < $BUILD_ROOT/.init_b_cache/rpmlist.download |
| 765 |
rm -f $BUILD_ROOT/.init_b_cache/rpmlist.download |
| 766 |
test -s $BUILD_ROOT/.init_b_cache/rpmlist.download2 && mv $BUILD_ROOT/.init_b_cache/rpmlist.download2 $BUILD_ROOT/.init_b_cache/rpmlist.download |
| 767 |
fi |
| 768 |
|
| 769 |
# now do the download of missing packages |
| 770 |
if test -s $BUILD_ROOT/.init_b_cache/rpmlist.download ; then |
| 771 |
PACKAGES_TO_DOWNLOAD=`awk '{print $2}' < "$BUILD_ROOT/.init_b_cache/rpmlist.download"` |
| 772 |
progress_setup PACKAGES_TO_DOWNLOAD |
| 773 |
while read PKG SRC ; do |
| 774 |
progress_step PACKAGES_TO_DOWNLOAD |
| 775 |
downloadpkg "$SRC" |
| 776 |
# downloadpkg modified $SRC, so it has a right name for use |
| 777 |
SRCSUF=${SRC/%.pkg.tar.zst/.arch} |
| 778 |
SRCSUF=${SRCSUF/%.pkg.tar.?z/.arch} |
| 779 |
ln -s "$SRC" "$BUILD_ROOT/.init_b_cache/rpms/$PKG.${SRCSUF##*.}" |
| 780 |
done < $BUILD_ROOT/.init_b_cache/rpmlist.download |
| 781 |
rm -f $BUILD_ROOT/.init_b_cache/rpmlist.download |
| 782 |
echo |
| 783 |
fi |
| 784 |
|
| 785 |
# compatibility... |
| 786 |
test -z "$RUNSCRIPTS_SEEN" && PACKAGES_TO_RUNSCRIPTS="$PACKAGES_TO_PREINSTALL" |
| 787 |
|
| 788 |
buildroot_rm .guessed_dist |
| 789 |
echo "$GUESSED_DIST" > $BUILD_ROOT/.guessed_dist |
| 790 |
test -n "$BUILD_DIST" || BUILD_DIST="$GUESSED_DIST" |
| 791 |
|
| 792 |
pkg_set_type |
| 793 |
|
| 794 |
if test -n "$PREINSTALL_IMAGE" ; then |
| 795 |
for PKG in $PACKAGES_FROM_PREINSTALLIMAGE ; do |
| 796 |
# touch the file so that the copying works |
| 797 |
touch $BUILD_ROOT/.init_b_cache/rpms/"$PKG.$PSUF" |
| 798 |
done |
| 799 |
fi |
| 800 |
|
| 801 |
fi |
| 802 |
|
| 803 |
# XXX: should use an option instead of looking at the recipe? |
| 804 |
CREATE_PREINSTALL_DATA= |
| 805 |
case ${PKGS[0]} in |
| 806 |
_preinstallimage | */_preinstallimage | _service:*:_preinstallimage | */_service:*:_preinstallimage) |
| 807 |
mkdir -p $BUILD_ROOT/.preinstall_image |
| 808 |
CREATE_PREINSTALL_DATA=true |
| 809 |
echo "saving package data for preinstallimage generation" |
| 810 |
;; |
| 811 |
esac |
| 812 |
|
| 813 |
# |
| 814 |
# test if we need to preinstall |
| 815 |
# |
| 816 |
if test ! -e $BUILD_ROOT/installed-pkg -a ! -e $BUILD_ROOT/.build/init_buildsystem.data ; then |
| 817 |
mkdir -p $BUILD_ROOT/.init_b_cache/rpms || cleanup_and_exit 1 |
| 818 |
mkdir -p $BUILD_ROOT/etc || cleanup_and_exit 1 |
| 819 |
mkdir -p $BUILD_ROOT/proc || cleanup_and_exit 1 |
| 820 |
test -L $BUILD_ROOT/etc/HOSTNAME && buildroot_rm etc/HOSTNAME |
| 821 |
test -f $BUILD_ROOT/etc/HOSTNAME || hostname -f > $BUILD_ROOT/etc/HOSTNAME |
| 822 |
for PKG in $PACKAGES_TO_RUNSCRIPTS ; do |
| 823 |
: > $BUILD_ROOT/.init_b_cache/scripts/$PKG.run |
| 824 |
done |
| 825 |
PACKAGES_TO_PREINSTALL_FILTERED="$PACKAGES_TO_PREINSTALL" |
| 826 |
PACKAGES_TO_VMINSTALL_FILTERED="$PACKAGES_TO_VMINSTALL" |
| 827 |
rm -f "$BUILD_ROOT/.preinstall_image"/* |
| 828 |
if test -n "$PREINSTALL_IMAGE" ; then |
| 829 |
preinstall_image "$PREINSTALL_IMAGE" "$PREINSTALL_IMAGE_SOURCE" |
| 830 |
PACKAGES_TO_PREINSTALL_FILTERED=`preinstall_image_filter $PACKAGES_TO_PREINSTALL_FILTERED` |
| 831 |
PACKAGES_TO_VMINSTALL_FILTERED=`preinstall_image_filter $PACKAGES_TO_VMINSTALL_FILTERED` |
| 832 |
fi |
| 833 |
PACKAGES_TO_PREINSTALL_FILTERED=`reorder $PACKAGES_TO_PREINSTALL_FILTERED` |
| 834 |
if test -n "$PREPARE_VM" ; then |
| 835 |
PACKAGES_TO_VMINSTALL_FILTERED=`reorder $PACKAGES_TO_VMINSTALL_FILTERED` |
| 836 |
fi |
| 837 |
progress_setup PACKAGES_TO_PREINSTALL_FILTERED |
| 838 |
for PKG in $PACKAGES_TO_PREINSTALL_FILTERED ; do |
| 839 |
progress_step PACKAGES_TO_PREINSTALL_FILTERED |
| 840 |
preinstall ${PKG##*/} |
| 841 |
done |
| 842 |
if test -n "$PREPARE_VM" ; then |
| 843 |
echo |
| 844 |
progress_setup PACKAGES_TO_VMINSTALL_FILTERED |
| 845 |
for PKG in $PACKAGES_TO_VMINSTALL_FILTERED ; do |
| 846 |
progress_step PACKAGES_TO_VMINSTALL_FILTERED |
| 847 |
preinstall ${PKG##*/} |
| 848 |
done |
| 849 |
fi |
| 850 |
# for reorder |
| 851 |
check_exit |
| 852 |
if test -w /root ; then |
| 853 |
test -c $BUILD_ROOT/dev/null || create_devs |
| 854 |
fi |
| 855 |
if ! test -e $BUILD_ROOT/etc/fstab ; then |
| 856 |
rm -rf $BUILD_ROOT/etc/fstab |
| 857 |
touch $BUILD_ROOT/etc/fstab |
| 858 |
fi |
| 859 |
if test ! -e $BUILD_ROOT/etc/ld.so.conf -a -f $BUILD_ROOT/etc/ld.so.conf.in -a ! -L $BUILD_ROOT/etc/ld.so.conf.in ; then |
| 860 |
rm -rf $BUILD_ROOT/etc/ld.so.conf |
| 861 |
cp $BUILD_ROOT/etc/ld.so.conf.in $BUILD_ROOT/etc/ld.so.conf |
| 862 |
fi |
| 863 |
if test -z "$PREPARE_VM" ; then |
| 864 |
mount_stuff |
| 865 |
run_pkg_scripts |
| 866 |
pkg_initdb |
| 867 |
touch $BUILD_ROOT/.init_b_cache/preinstall_finished |
| 868 |
fi |
| 869 |
# mark as preinstalled no longer needed |
| 870 |
rm -rf "$BUILD_ROOT/installed-pkg" |
| 871 |
mkdir -p "$BUILD_ROOT/installed-pkg" |
| 872 |
else |
| 873 |
# preinstall was already done |
| 874 |
if test -z "$PREPARE_VM" ; then |
| 875 |
mount_stuff |
| 876 |
fi |
| 877 |
fi |
| 878 |
|
| 879 |
if test -n "$PREPARE_VM" ; then |
| 880 |
echo "copying packages..." |
| 881 |
for PKG in $PACKAGES_TO_ALL ; do |
| 882 |
rm -rf $BUILD_ROOT/.init_b_cache/$PKG.$PSUF |
| 883 |
cp $BUILD_ROOT/.init_b_cache/rpms/$PKG.$PSUF $BUILD_ROOT/.init_b_cache/$PKG.$PSUF || cleanup_and_exit 1 |
| 884 |
ln -s -f ../$PKG.$PSUF $BUILD_ROOT/.init_b_cache/rpms/$PKG.$PSUF |
| 885 |
check_exit |
| 886 |
done |
| 887 |
# alreadyinstalled check will not work, but we have to live with that... |
| 888 |
echo -n 'reordering...' |
| 889 |
PACKAGES_TO_INSTALL=`reorder $PACKAGES_TO_INSTALL` |
| 890 |
check_exit |
| 891 |
echo 'done' |
| 892 |
Q="'\''" |
| 893 |
rm -rf "$BUILD_ROOT/.build/init_buildsystem.data" |
| 894 |
echo "PACKAGES_TO_INSTALL='${PACKAGES_TO_INSTALL//"'"/$Q}'" > $BUILD_ROOT/.build/init_buildsystem.data |
| 895 |
echo "PACKAGES_TO_RUNSCRIPTS='${PACKAGES_TO_RUNSCRIPTS//"'"/$Q}'" >> $BUILD_ROOT/.build/init_buildsystem.data |
| 896 |
# needed for continuation in xen/kvm with rpm-x86 |
| 897 |
echo "PACKAGES_TO_PREINSTALL='${PACKAGES_TO_PREINSTALL//"'"/$Q}'" >> $BUILD_ROOT/.build/init_buildsystem.data |
| 898 |
echo "PACKAGES_TO_AVAILABLE='${PACKAGES_TO_AVAILABLE//"'"/$Q}'" >> $BUILD_ROOT/.build/init_buildsystem.data |
| 899 |
echo "PSUF='$PSUF'" >> $BUILD_ROOT/.build/init_buildsystem.data |
| 900 |
rm -f $BUILD_IS_RUNNING |
| 901 |
cleanup_and_exit 0 |
| 902 |
fi |
| 903 |
|
| 904 |
# |
| 905 |
# finish preinstall if this is a vm continuation |
| 906 |
# |
| 907 |
if test -e "$BUILD_ROOT/.build/init_buildsystem.data" -a ! -e "$BUILD_ROOT/.init_b_cache/preinstall_finished" ; then |
| 908 |
run_pkg_scripts |
| 909 |
pkg_initdb |
| 910 |
touch "$BUILD_ROOT/.init_b_cache/preinstall_finished" |
| 911 |
fi |
| 912 |
|
| 913 |
# |
| 914 |
# create .build.binaries directory if requested |
| 915 |
# |
| 916 |
rm -rf "$BUILD_ROOT/.build.binaries" |
| 917 |
if test -n "$CREATE_BUILD_BINARIES" ; then |
| 918 |
echo "creating .build.binaries directory..." |
| 919 |
mkdir -p "$BUILD_ROOT/.build.binaries" |
| 920 |
for PKG in $PACKAGES_TO_AVAILABLE ; do |
| 921 |
test -L "$BUILD_ROOT/.init_b_cache/rpms/$PKG.$PSUF" || continue |
| 922 |
LPKG=`readlink -f "$BUILD_ROOT/.init_b_cache/rpms/$PKG.$PSUF"` |
| 923 |
ln "$LPKG" "$BUILD_ROOT/.build.binaries/$PKG.$PSUF" 2>/dev/null |
| 924 |
test -f "$BUILD_ROOT/.build.binaries/$PKG.$PSUF" && continue |
| 925 |
cp "$LPKG" "$BUILD_ROOT/.build.binaries/$PKG.$PSUF" |
| 926 |
check_exit |
| 927 |
done |
| 928 |
fi |
| 929 |
|
| 930 |
# |
| 931 |
# Save some package build environment preparation time on Debian-like systems |
| 932 |
# Note: for OS image builds we probably want the man-db constructed properly |
| 933 |
# |
| 934 |
if test -x "$BUILD_ROOT/usr/bin/debconf-set-selections" && test "$BUILDTYPE" = dsc ; then |
| 935 |
echo "Preseed man-db/auto-update to false for a DSC package build..." |
| 936 |
chroot "$BUILD_ROOT" /usr/bin/debconf-set-selections <<EOF |
| 937 |
man-db man-db/auto-update boolean false |
| 938 |
EOF |
| 939 |
fi |
| 940 |
|
| 941 |
# |
| 942 |
# reorder packages (already done in vm continuation) |
| 943 |
# |
| 944 |
if ! test -e $BUILD_ROOT/.build/init_buildsystem.data ; then |
| 945 |
echo -n 'reordering...' |
| 946 |
PACKAGES_TO_INSTALL=`reorder $PACKAGES_TO_INSTALL` |
| 947 |
check_exit |
| 948 |
echo 'done' |
| 949 |
fi |
| 950 |
|
| 951 |
echo "querying package ids..." |
| 952 |
for PKG in $PACKAGES_TO_INSTALL ; do |
| 953 |
test -s "$BUILD_ROOT/.init_b_cache/rpms/$PKG.$PSUF" || continue |
| 954 |
test -L "$BUILD_ROOT/.init_b_cache/rpms/$PKG.$PSUF" || continue |
| 955 |
echo "$BUILD_ROOT/.init_b_cache/rpms/$PKG.$PSUF" |
| 956 |
done | "$BUILD_DIR/getbuildids" |
| 957 |
|
| 958 |
# |
| 959 |
# get list and ids of already installed packages |
| 960 |
# |
| 961 |
mkdir -p $BUILD_ROOT/.init_b_cache/alreadyinstalled |
| 962 |
listinstalled --root "$BUILD_ROOT" --type "$PSUF" --extraname | ( |
| 963 |
while read id name buildid; do |
| 964 |
echo "$buildid" > "$BUILD_ROOT/.init_b_cache/alreadyinstalled/$name" |
| 965 |
done |
| 966 |
) |
| 967 |
|
| 968 |
# do pre-installation work |
| 969 |
pkg_prepare |
| 970 |
|
| 971 |
# |
| 972 |
# delete all packages we don't want |
| 973 |
# |
| 974 |
mkdir -p $BUILD_ROOT/.init_b_cache/todelete |
| 975 |
for PKG in $BUILD_ROOT/.init_b_cache/alreadyinstalled/* ; do |
| 976 |
PKG=${PKG##*/} |
| 977 |
test "$PKG" = "*" && continue |
| 978 |
ln $BUILD_ROOT/.init_b_cache/alreadyinstalled/$PKG $BUILD_ROOT/.init_b_cache/todelete/$PKG |
| 979 |
done |
| 980 |
for PKG in $PACKAGES_TO_INSTALL; do |
| 981 |
rm -f $BUILD_ROOT/.init_b_cache/todelete/$PKG |
| 982 |
done |
| 983 |
for PKG in $BUILD_ROOT/.init_b_cache/todelete/* ; do |
| 984 |
PKG=${PKG##*/} |
| 985 |
test "$PKG" = "*" && continue |
| 986 |
echo "deleting $PKG" |
| 987 |
pkg_erase |
| 988 |
check_exit |
| 989 |
done |
| 990 |
rm -rf "$BUILD_ROOT/.init_b_cache/todelete" |
| 991 |
|
| 992 |
rm -rf "$BUILD_ROOT/.init_b_cache/preinstalls" |
| 993 |
mkdir -p "$BUILD_ROOT/.init_b_cache/preinstalls" |
| 994 |
for PKG in $PACKAGES_TO_PREINSTALL; do |
| 995 |
touch "$BUILD_ROOT/.init_b_cache/preinstalls/$PKG" |
| 996 |
done |
| 997 |
|
| 998 |
rm -rf "$BUILD_ROOT/installed-pkg" |
| 999 |
mkdir -p "$BUILD_ROOT/installed-pkg" |
| 1000 |
|
| 1001 |
test -x $BUILD_ROOT/sbin/ldconfig && chroot $BUILD_ROOT /sbin/ldconfig 2>&1 |
| 1002 |
|
| 1003 |
MAIN_LIST="$PACKAGES_TO_INSTALL" |
| 1004 |
progress_setup MAIN_LIST |
| 1005 |
for PKG in $MAIN_LIST ; do |
| 1006 |
test -f $BUILD_ROOT/installed-pkg/$PKG && continue |
| 1007 |
progress_step MAIN_LIST |
| 1008 |
|
| 1009 |
if test -e "$BUILD_ROOT/.init_b_cache/rpms/$PKG.$PSUF" -a ! -s "$BUILD_ROOT/.init_b_cache/rpms/$PKG.$PSUF" ; then |
| 1010 |
# preinstallimage package, make sure it's in the image |
| 1011 |
if ! test -e $BUILD_ROOT/.preinstall_image/$PKG ; then |
| 1012 |
cleanup_and_exit 1 "Package $PKG is missing from the preinstall image" |
| 1013 |
fi |
| 1014 |
read PKG_HDRMD5 PKGID < $BUILD_ROOT/.preinstall_image/$PKG |
| 1015 |
echo "preinstalled ${PKGID%% *}" |
| 1016 |
echo "$PKGID" > $BUILD_ROOT/installed-pkg/$PKG |
| 1017 |
continue |
| 1018 |
fi |
| 1019 |
|
| 1020 |
# get the hdrmd5 if we want to create a preinstall image |
| 1021 |
PKG_HDRMD5= |
| 1022 |
if test -n "$CREATE_PREINSTALL_DATA" -a ! -e $BUILD_ROOT/.preinstall_image/$PKG ; then |
| 1023 |
PKG_HDRMD5=`perl -I$BUILD_DIR -MBuild -e 'print Build::queryhdrmd5($ARGV[0])' $BUILD_ROOT/.init_b_cache/rpms/$PKG.$PSUF` |
| 1024 |
test -n "$PKG_HDRMD5" || cleanup_and_exit 1 |
| 1025 |
fi |
| 1026 |
|
| 1027 |
test -L $BUILD_ROOT/.init_b_cache/rpms/$PKG.$PSUF || continue |
| 1028 |
|
| 1029 |
if test -s "$BUILD_ROOT/.init_b_cache/rpms/$PKG.$PSUF.buildid" ; then |
| 1030 |
read PKGID < "$BUILD_ROOT/.init_b_cache/rpms/$PKG.$PSUF.buildid" |
| 1031 |
else |
| 1032 |
PKGID=$(perl -I$BUILD_DIR -MBuild -e Build::showquery "$BUILD_ROOT/.init_b_cache/rpms/$PKG.$PSUF" buildid) |
| 1033 |
fi |
| 1034 |
|
| 1035 |
if test -f "$BUILD_ROOT/.init_b_cache/alreadyinstalled/$PKG" ; then |
| 1036 |
read OLDPKGID < "$BUILD_ROOT/.init_b_cache/alreadyinstalled/$PKG" |
| 1037 |
if test "$PKGID" != "$OLDPKGID" && ! test -e "$BUILD_ROOT/.init_b_cache/preinstalls/$PKG" ; then |
| 1038 |
echo "deleting unwanted ${OLDPKGID%% *}" |
| 1039 |
pkg_erase |
| 1040 |
else |
| 1041 |
if test "$VERIFY_BUILD_SYSTEM" != true || pkg_verify_installed ; then |
| 1042 |
echo "keeping ${PKGID%% *}" |
| 1043 |
echo "$PKGID" > $BUILD_ROOT/installed-pkg/$PKG |
| 1044 |
test -n "$PKG_HDRMD5" && echo "$PKG_HDRMD5 $PKGID" > $BUILD_ROOT/.preinstall_image/$PKG |
| 1045 |
continue |
| 1046 |
fi |
| 1047 |
echo "deleting incomplete ${OLDPKGID%% *}" |
| 1048 |
pkg_erase |
| 1049 |
fi |
| 1050 |
if test -e "$BUILD_ROOT/.init_b_cache/preinstalls/$PKG" ; then |
| 1051 |
preinstall "$PKG" |
| 1052 |
fi |
| 1053 |
check_exit |
| 1054 |
fi |
| 1055 |
|
| 1056 |
if pkg_cumulate ; then |
| 1057 |
echo "cumulate ${PKGID%% *}" |
| 1058 |
continue |
| 1059 |
fi |
| 1060 |
|
| 1061 |
# install the package |
| 1062 |
echo "installing ${PKGID%% *}" |
| 1063 |
if ! test "$BUILD_ROOT/.init_b_cache/rpms/$PKG.$PSUF" -ef "$BUILD_ROOT/.init_b_cache/$PKG.$PSUF" ; then |
| 1064 |
rm -f $BUILD_ROOT/.init_b_cache/$PKG.$PSUF |
| 1065 |
cp $BUILD_ROOT/.init_b_cache/rpms/$PKG.$PSUF $BUILD_ROOT/.init_b_cache/$PKG.$PSUF || cleanup_and_exit 1 |
| 1066 |
fi |
| 1067 |
pkg_install |
| 1068 |
check_exit |
| 1069 |
rm -f $BUILD_ROOT/.init_b_cache/$PKG.$PSUF |
| 1070 |
echo "$PKGID" > $BUILD_ROOT/installed-pkg/$PKG |
| 1071 |
test -n "$PKG_HDRMD5" && echo "$PKG_HDRMD5 $PKGID" > $BUILD_ROOT/.preinstall_image/$PKG |
| 1072 |
|
| 1073 |
done |
| 1074 |
|
| 1075 |
# do post-installation work |
| 1076 |
pkg_finalize |
| 1077 |
|
| 1078 |
# devices can vanish if devs got uninstalled |
| 1079 |
test -c $BUILD_ROOT/dev/null || create_devs |
| 1080 |
|
| 1081 |
cd $BUILD_ROOT || cleanup_and_exit 1 |
| 1082 |
|
| 1083 |
# |
| 1084 |
# setup /etc/mtab |
| 1085 |
# |
| 1086 |
rm -f $BUILD_ROOT/etc/mtab |
| 1087 |
cp /proc/mounts $BUILD_ROOT/etc/mtab |
| 1088 |
chmod 644 $BUILD_ROOT/etc/mtab |
| 1089 |
|
| 1090 |
# |
| 1091 |
# make sure that our nis is not present in the chroot system |
| 1092 |
# |
| 1093 |
if test -e $BUILD_ROOT/etc/nsswitch.conf ; then |
| 1094 |
sed -e "s:nis::g" < $BUILD_ROOT/etc/nsswitch.conf > $BUILD_ROOT/etc/nsswitch.conf.tmp |
| 1095 |
mv $BUILD_ROOT/etc/nsswitch.conf.tmp $BUILD_ROOT/etc/nsswitch.conf |
| 1096 |
fi |
| 1097 |
|
| 1098 |
# |
| 1099 |
# create some default directories and files |
| 1100 |
# |
| 1101 |
for DIR in /usr/share/doc/packages \ |
| 1102 |
/usr/X11R6/include/X11/pixmaps \ |
| 1103 |
/usr/X11R6/include/X11/bitmaps ; do |
| 1104 |
mkdir -p $BUILD_ROOT/$DIR |
| 1105 |
done |
| 1106 |
for FILE in /var/run/utmp /var/log/wtmp /etc/fstab ; do |
| 1107 |
mkdir -p $BUILD_ROOT/${FILE%/*} |
| 1108 |
touch $BUILD_ROOT/$FILE |
| 1109 |
done |
| 1110 |
|
| 1111 |
echo now finalizing build dir... |
| 1112 |
if test -x $BUILD_ROOT/sbin/ldconfig ; then |
| 1113 |
CHROOT_RETURN="`chroot $BUILD_ROOT /sbin/ldconfig 2>&1`" |
| 1114 |
case "$CHROOT_RETURN" in |
| 1115 |
*warning:*) |
| 1116 |
chroot $BUILD_ROOT /sbin/ldconfig |
| 1117 |
echo |
| 1118 |
echo chroot $BUILD_ROOT /sbin/ldconfig |
| 1119 |
echo |
| 1120 |
echo "$CHROOT_RETURN" |
| 1121 |
echo |
| 1122 |
echo "Problem with ldconfig. It's better to reinit the build system..." |
| 1123 |
echo |
| 1124 |
cleanup_and_exit 1 |
| 1125 |
;; |
| 1126 |
esac |
| 1127 |
fi |
| 1128 |
|
| 1129 |
if test -x $BUILD_ROOT/usr/sbin/Check && ! grep -q "/usr/sbin/Check is obsolete" $BUILD_ROOT/usr/sbin/Check ; then |
| 1130 |
chroot $BUILD_ROOT /usr/sbin/Check |
| 1131 |
fi |
| 1132 |
|
| 1133 |
mkdir -p $BUILD_ROOT/var/adm/packages |
| 1134 |
touch $BUILD_ROOT/var/adm/packages |
| 1135 |
|
| 1136 |
if test -x $BUILD_ROOT/sbin/SuSEconfig ; then |
| 1137 |
if grep norestarts $BUILD_ROOT/sbin/SuSEconfig > /dev/null ; then |
| 1138 |
chroot $BUILD_ROOT /sbin/SuSEconfig --norestarts --force |
| 1139 |
else |
| 1140 |
chroot $BUILD_ROOT /sbin/SuSEconfig --force |
| 1141 |
fi |
| 1142 |
fi |
| 1143 |
|
| 1144 |
if test -x $BUILD_ROOT/usr/X11R6/bin/switch2mesasoft ; then |
| 1145 |
chroot $BUILD_ROOT /usr/X11R6/bin/switch2mesasoft |
| 1146 |
fi |
| 1147 |
|
| 1148 |
for PROG in /usr/bin/TeX/texhash /usr/bin/texhash ; do |
| 1149 |
test -x $BUILD_ROOT/$PROG && \ |
| 1150 |
chroot $BUILD_ROOT bash -c ". /etc/profile ; $PROG" |
| 1151 |
done |
| 1152 |
|
| 1153 |
if test -e $BUILD_ROOT/usr/share/zoneinfo/UTC ; then |
| 1154 |
for PROG in /usr/sbin/zic /usr/bin/zic /bin/zic /sbin/zic ; do |
| 1155 |
test -x $BUILD_ROOT/$PROG && chroot $BUILD_ROOT bash -c "$PROG -l \$(readlink -f /usr/share/zoneinfo/UTC)" |
| 1156 |
done |
| 1157 |
fi |
| 1158 |
|
| 1159 |
if test -d $BUILD_ROOT/usr/lib/build/finalize-system ; then |
| 1160 |
for PROG in $BUILD_ROOT/usr/lib/build/finalize-system/* ; do |
| 1161 |
test -e "$PROG" || continue |
| 1162 |
echo "... running ${PROG##*/}" |
| 1163 |
chroot $BUILD_ROOT "/usr/lib/build/finalize-system/${PROG##*/}" || cleanup_and_exit 1 |
| 1164 |
done |
| 1165 |
fi |
| 1166 |
|
| 1167 |
test -e $BUILD_ROOT/.build/init_buildsystem.data || HOST=`hostname` |
| 1168 |
test -e $BUILD_ROOT/etc/hosts || echo "127.0.0.1 localhost" > $BUILD_ROOT/etc/hosts |
| 1169 |
if ! grep -F "127.0.0.1 $HOST" $BUILD_ROOT/etc/hosts > /dev/null ; then |
| 1170 |
# this makes a reverse lookup on 127.0.0.1 return the host name, |
| 1171 |
# which is bad, but 127.0.0.2 does not work on all unix systems |
| 1172 |
echo "127.0.0.1 $HOST" > $BUILD_ROOT/etc/hosts.new |
| 1173 |
test -f $BUILD_ROOT/etc/hosts && cat $BUILD_ROOT/etc/hosts >> $BUILD_ROOT/etc/hosts.new |
| 1174 |
mv $BUILD_ROOT/etc/hosts.new $BUILD_ROOT/etc/hosts |
| 1175 |
fi |
| 1176 |
|
| 1177 |
rm -f $BUILD_ROOT/.rpmmacros $BUILD_ROOT/root/.rpmmacros |
| 1178 |
rm -rf "$BUILD_ROOT/.init_b_cache" |
| 1179 |
rm -f $BUILD_IS_RUNNING |
| 1180 |
rm -f $TMPFILE |
| 1181 |
|
| 1182 |
cleanup_and_exit 0 |
| 1183 |
|
| 1184 |
# vim: set tabstop=8 softtabstop=4 shiftwidth=4 noexpandtab: |