Move more tests to the top

Test for teh bash version and root at the top as well, to avoid errors from
commands that otherwise get run before the tests.
This commit is contained in:
Peter Ajamian 2021-06-13 00:30:05 +12:00
parent 5051fc5312
commit b587a7e7a4

View file

@ -32,15 +32,25 @@
## Rocky is RC status. Using this script means you accept all risks of system
## instability.
# This check needs to be right at the top because we start with bash-isms right
# These checks need to be right at the top because we start with bash-isms right
# away in this script.
# We need bash version >= 4 for associative arrays. This will also verify
# that we're actually running bash.
if [ -n "$POSIXLY_CORRECT" ] || [ -z "$BASH_VERSION" ]; then
printf '%s\n' "bash >= 4.0 is required for this script." >&2
exit 1
fi
# Make sure we're root.
if (( EUID != 0 )); then
printf '%s\n' "You must run this script as root. Either use sudo or 'su -c ${0}'" >&2
exit 1
fi
# We need bash version >= 4 for associative arrays.
if (( BASH_VERSINFO < 4 )); then
printf '%s\n' "bash >= 4.0 is required for this script." >&2
exit 1
fi
# Path to logfile
logfile=/var/log/migrate2rocky.log
@ -124,17 +134,6 @@ pre_check () {
# work unless it's severly broken. This is just a simple check that will cause
# the script to bail if any expected system utilities are missing.
bin_check() {
# Make sure we're root.
if (( EUID != 0 )); then
exit_message "You must run this script as root. Either use sudo or 'su -c ${0}'"
fi
# We need bash version >= 4 for associative arrays. This will also verify
# that we're actually running bash.
if (( BASH_VERSINFO < 4 )); then
exit_message "bash >= 4.0 is required for this script."
fi
# Check the platform.
if [[ $(os-release PLATFORM_ID) != "$SUPPORTED_PLATFORM" ]]; then
exit_message "This script must be run on an EL8 distribution. Migration from other distributions is not supported."