livecd-tools/urpmi-bootstrapper.sh
2019-03-09 02:57:31 +03:00

96 lines
2.9 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
urpmi_exec(){
urpmi \
--urpmi-root "$urpmiRoot" \
--root "$rpmRoot" \
--debug \
${urpmi_options} \
${packagesList}
urpmi_return_code="$?"
}
urpmi_bootstrap(){
for urpmi_options in \
"--auto --no-suggests --allow-force --allow-nodeps --split-length 500" \
"--auto --no-suggests"
do
urpmi_exec
done
}
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 5)
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}"
# 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 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
set -e )
done
# 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