mirror of
https://abf.rosa.ru/djam/livecd-tools.git
synced 2025-02-23 15:42:58 +00:00
133 lines
4.1 KiB
Bash
Executable file
133 lines
4.1 KiB
Bash
Executable file
#!/bin/sh
|
|
# Author: Mikhail Novosyolov <m.novosyolov@rosalinux.ru>
|
|
# This script tries to "solve" problems with bootstrapping chroot,
|
|
# where urpmi fails due to failed dependencies,
|
|
# but, if we run it for multiple times, it does bootstrap all required packages.
|
|
# Unfortunately, we currently don't have enought time to solve bootstrapping issues properly,
|
|
# so let's make this ugly hack.
|
|
# Sometimes it's possible to understand which dependencies fail,
|
|
# bacause the last iteration after several failed ones will install those failing packages.
|
|
# I previously made this hack in
|
|
# https://github.com/mikhailnov/docker-rosa/blob/master/mkimage-urpmi.sh
|
|
set -xefu
|
|
failed_pkgs=""
|
|
|
|
urpmi_exec(){
|
|
urpmi \
|
|
--urpmi-root "$urpmiRoot" \
|
|
--root "$rpmRoot" \
|
|
--debug --no-verify-rpm \
|
|
${urpmi_options} \
|
|
${packagesList}
|
|
# TODO: reenable verifying RPM signatures after they are fixed in repos
|
|
urpmi_return_code="$?"
|
|
}
|
|
|
|
urpmi_bootstrap(){
|
|
urpmi_options="--auto --no-suggests"
|
|
urpmi_exec && return 0
|
|
# If normal operation was not successfull, try to force
|
|
# and then retry without forcing
|
|
for urpmi_options in \
|
|
"--auto --no-suggests --allow-force --allow-nodeps --split-length 500" \
|
|
"--auto --no-suggests"
|
|
do
|
|
urpmi_exec
|
|
done
|
|
}
|
|
|
|
diagnostics(){
|
|
# Now, when packages have been installed successfully,
|
|
# verify that really all of them have been installed.
|
|
# Can't redirect to >/dev/null here, because errors are also in stdout.
|
|
chroot "$rpmRoot" /bin/rpm -q ${packagesList_orig}
|
|
|
|
# Perform a check
|
|
# TODO: we should fail if there are errors, but will just print to log for now
|
|
chroot "$rpmRoot" /bin/rpm -Va || :
|
|
}
|
|
|
|
process_packages(){
|
|
|
|
# This will validate that all requested packages do exist
|
|
# and will print a list of not existing ones.
|
|
# Returns 0 only if all packages do exist.
|
|
urpmq --whatprovides --urpmi-root "$urpmiRoot" ${packagesList} >/dev/null
|
|
|
|
# temporarily don't fail the whole scripts when not last iteration of urpmi fails
|
|
set +e
|
|
for i in $(seq 1 2)
|
|
do
|
|
echo "Starting urpmi bootstrap iteration #${i}..."
|
|
urpmi_bootstrap
|
|
if [ "${urpmi_return_code}" = 0 ]
|
|
then
|
|
echo "urpmi iteration #${i} was successfull."
|
|
break
|
|
else
|
|
echo "urpmi iteration #${i} failed."
|
|
fi
|
|
done
|
|
# now check the return code of the _last_ urpmi iteration
|
|
if [ "${urpmi_return_code}" != 0 ]; then
|
|
echo "urpmi bootstrapping failed!"
|
|
if [ "$EXIT" = 1 ]; then
|
|
exit "${urpmi_return_code}"
|
|
fi
|
|
return "${urpmi_return_code}"
|
|
fi
|
|
# return failing the whole script on any error
|
|
set -e
|
|
}
|
|
|
|
packagesList_orig="${packagesList}"
|
|
|
|
# list connected repositories (for debugging)
|
|
echo "Connected repositories:"
|
|
urpmq --list-url
|
|
|
|
# bootstrap basesystem first (it's not really necessary, but let's do it)
|
|
if echo "${packagesList_orig}" | grep -qE 'basesystem | basesystem'; then
|
|
( packagesList="$(echo "${packagesList_orig}" | tr ' ' '\n' | grep ^basesystem | tr '\n' ' ')"
|
|
# Exit the whole script if even bootstrapping basesystem failed
|
|
EXIT=1
|
|
process_packages )
|
|
fi
|
|
|
|
# now let's try to bootstrap the whole list of packages
|
|
packagesList="${packagesList_orig}"
|
|
EXIT=0
|
|
process_packages
|
|
# exit if all packages have been installed
|
|
if [ "$urpmi_return_code" = 0 ]; then
|
|
diagnostics && \
|
|
exit 0
|
|
fi
|
|
|
|
# If installing packages still failed, let's try to install them one-by-one
|
|
packagesList_sorted="$(echo "${packagesList_orig}" | tr ' ' '\n' | sort -u)"
|
|
for i in ${packagesList_sorted}
|
|
do
|
|
set +e
|
|
packagesList="$i"
|
|
urpmi_options="--auto --no-suggests --allow-force --allow-nodeps"
|
|
urpmi_exec
|
|
if [ "$urpmi_return_code" != 0 ]; then failed_pkgs="${failed_pkgs} ${i}"; fi
|
|
set -e
|
|
done
|
|
|
|
if [ -n "${failed_pkgs}" ]; then
|
|
echo "Failed packages: ${failed_pkgs}"
|
|
# If there were failed packages, let's install all RPMs in cache.
|
|
# It will be done without potentially buggy perl-URPM.
|
|
( set +f
|
|
urpmi_cache="${urpmiRoot}/var/cache/urpmi/rpms"
|
|
#rpm -Uvh --nodeps ${urpmi_cache}/*.rpm || :
|
|
urpmi --auto --no-suggests ${urpmi_cache}/*.rpm || : )
|
|
fi
|
|
|
|
# Now, regardless success of installing one-by-one, let's install all packages and see if it will be successfull
|
|
# and exit with error, if it failed
|
|
packagesList="${packagesList_orig}"
|
|
EXIT=1
|
|
process_packages
|