Fix various issues found by shellcheck

Shellcheck found various issues that have cropped up over time.  This commit
fixes those issues.
This commit is contained in:
Peter Ajamian 2021-06-04 02:16:43 +12:00
parent f2da5e4a8c
commit ef1cfd1fb9

View File

@ -43,7 +43,9 @@ exec > >(tee -a "$logfile") 2> >(tee -a "$logfile" >&2)
#errcolor=$(tput setaf 1) #errcolor=$(tput setaf 1)
#blue=$(tput setaf 4) #blue=$(tput setaf 4)
#nocolor=$(tput op) #nocolor=$(tput op)
unset errcolor blue nocolor errcolor=
blue=
nocolor=
export LANG=en_US.UTF-8 export LANG=en_US.UTF-8
shopt -s nullglob shopt -s nullglob
@ -95,7 +97,7 @@ os-release () (
# be adequate for our needs here. # be adequate for our needs here.
pkg_ver() ( pkg_ver() (
ver=$(rpm -q --qf '%{VERSION}\n' "$1") || return 2 ver=$(rpm -q --qf '%{VERSION}\n' "$1") || return 2
if [[ $(sort -V <<<"$ver"$'\n'"$2" | head -1) != $2 ]]; then if [[ $(sort -V <<<"$ver"$'\n'"$2" | head -1) != "$2" ]]; then
return 1 return 1
fi fi
return 0 return 0
@ -112,7 +114,7 @@ bin_check() {
fi fi
# Check the platform. # Check the platform.
if [[ $(os-release PLATFORM_ID) != $SUPPORTED_PLATFORM ]]; then 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." exit_message "This script must be run on an EL8 distribution. Migration from other distributions is not supported."
fi fi
@ -142,7 +144,7 @@ bin_check() {
fi fi
if (( ${#missing[@]} )); then if (( ${#missing[@]} )); then
exit_message "Commands not found: ${missing[@]}. Possible bad PATH setting or corrupt installation." exit_message "Commands not found: ${missing[*]}. Possible bad PATH setting or corrupt installation."
fi fi
} }
@ -150,7 +152,8 @@ bin_check() {
# info for the resulting package. Note that we explicitly disable the epel repo # info for the resulting package. Note that we explicitly disable the epel repo
# as a special-case below to avoid having the extras repository map to epel. # as a special-case below to avoid having the extras repository map to epel.
repoquery () { repoquery () {
local name val prev result=$( local name val prev result
result=$(
dnf -q --setopt=epel.excludepkgs=epel-release repoquery -i "$1" || dnf -q --setopt=epel.excludepkgs=epel-release repoquery -i "$1" ||
exit_message "Failed to fetch info for package $1." exit_message "Failed to fetch info for package $1."
) )
@ -330,13 +333,13 @@ collect_system_info () {
for pkg in "${!provides_pkg_map[@]}"; do for pkg in "${!provides_pkg_map[@]}"; do
printf '.' printf '.'
prov=${provides_pkg_map[$pkg]} prov=${provides_pkg_map[$pkg]}
pkg_map[$pkg]=$(provides_pkg $prov) || pkg_map[$pkg]=$(provides_pkg "$prov") ||
exit_message "Can't get package that provides $prov." exit_message "Can't get package that provides $prov."
done done
for prov in "${addl_provide_removes[@]}"; do for prov in "${addl_provide_removes[@]}"; do
printf '.' printf '.'
local pkg; local pkg;
pkg=$(provides_pkg $prov) || continue pkg=$(provides_pkg "$prov") || continue
addl_pkg_removes+=("$pkg") addl_pkg_removes+=("$pkg")
done done
@ -554,13 +557,13 @@ EOF
if (( ${#enabled_modules[@]} )); then if (( ${#enabled_modules[@]} )); then
printf '%s\n' "${blue}Enabling modules$nocolor" '' printf '%s\n' "${blue}Enabling modules$nocolor" ''
dnf -y module enable "${enabled_modules[@]}" || dnf -y module enable "${enabled_modules[@]}" ||
exit_message "Can't enable modules ${enabled_modules[@]}" exit_message "Can't enable modules ${enabled_modules[*]}"
fi fi
# Make sure that excluded repos are disabled. # Make sure that excluded repos are disabled.
printf '%s\n' "${blue}Disabling excluded modules$nocolor" '' printf '%s\n' "${blue}Disabling excluded modules$nocolor" ''
dnf -y module disable "${module_excludes[@]}" || dnf -y module disable "${module_excludes[@]}" ||
exit_message "Can't disable modules ${module_excludes[@]}" exit_message "Can't disable modules ${module_excludes[*]}"
printf '%s\n' '' "${blue}Syncing packages$nocolor" '' printf '%s\n' '' "${blue}Syncing packages$nocolor" ''
dnf -y distro-sync || exit_message "Error during distro-sync." dnf -y distro-sync || exit_message "Error during distro-sync."
@ -665,7 +668,7 @@ fi
printf '\n\n\n' printf '\n\n\n'
if [[ $convert_to_rocky ]]; then if [[ $convert_to_rocky ]]; then
cat /etc/issue | awk 'NR<=15' awk 'NR<=15' < /etc/issue
printf '%s\n' "$blue" "Done, please reboot your system.$nocolor" printf '%s\n' "$blue" "Done, please reboot your system.$nocolor"
fi fi
logmessage logmessage