Added log output and Wget/Curl sanity checks

This commit is contained in:
Carter Peel 2021-05-03 16:47:10 -04:00
parent 4f36ce43a5
commit 626cef11ab

View File

@ -4,18 +4,28 @@
## Rocky is RC status. Using this script means you accept all risks of system instability. ## Rocky is RC status. Using this script means you accept all risks of system instability.
(
# Pass everything to a subshell so the output can be piped to /var/log/centos2rocky.log
set -e set -e
unset CDPATH unset CDPATH
if [ "$(id -u)" -ne 0 ]; then if [[ "$(id -u)" -ne 0 ]]; then
echo "You must run this script as root." echo "You must run this script as root."
echo "Either use sudo or 'su -c ${0}'" echo "Either use sudo or 'su -c ${0}'"
fi fi
export LANG=en_US.UTF-8 if [[ "$(wget 2>/dev/null || echo $?)" == 127 ]]; then
echo "Wget is not installed! Installing it..."
dnf -y install wget
fi
# Add logfile for debugging later down the line if [[ "$(curl 2>/dev/null || echo $?)" == 127 ]]; then
logfile=/var/log/centos2rocky.log echo "Curl is not installed! Installing it..."
dnf -y install curl libcurl
fi
export LANG=en_US.UTF-8
SUPPORTED_RELEASE="8.3" SUPPORTED_RELEASE="8.3"
SUPPORTED_MAJOR="8" SUPPORTED_MAJOR="8"
@ -42,7 +52,6 @@ convert_info_dir=/root/convert
reinstall_all_rpms=false reinstall_all_rpms=false
verify_all_rpms=false verify_all_rpms=false
usage() { usage() {
echo "Usage: ${0##*/} [OPTIONS]" echo "Usage: ${0##*/} [OPTIONS]"
echo echo
@ -57,12 +66,17 @@ usage() {
exit_message() { exit_message() {
echo "$1" echo "$1"
log final_message final_message
exit 1 exit 1
} >&2 } >&2
final_message() { final_message() {
echo "An error occurred while we were attempting to convert your system to Rocky Linux. Your system may be unstable. Script will now exit to prevent possible damage." echo "An error occurred while we were attempting to convert your system to Rocky Linux. Your system may be unstable. Script will now exit to prevent possible damage."
logmessage
}
logmessage(){
echo "A log of this installation can be found at /var/log/centos2rocky.log"
} }
## The actual work ## The actual work
@ -72,7 +86,8 @@ bin_hash() {
bin_check() { bin_check() {
if ! bin_hash "$1"; then if ! bin_hash "$1"; then
log exit_message "'${1}' command not found. Please ensure you are running bash or that your PATH is set correctly." exit_message "'${1}' command not found. Please ensure you are running bash or that your PATH is set correctly."
logmessage
fi fi
} }
@ -89,7 +104,7 @@ package_swaps() {
pushd /root/release pushd /root/release
for x in "${release_to_install[@]}"; do for x in "${release_to_install[@]}"; do
wget -q "${current_url}/${x}" || { echo "failed to download ${x}" ; exit 20; } wget -q "${current_url}/${x}" || { echo "failed to download ${x}" && logmessage ; exit 20; }
done done
# Remove packages we need to swap # Remove packages we need to swap
@ -106,17 +121,19 @@ package_swaps() {
dnf config-manager --set-enabled ${list_enabled[@]} || { echo "Repo name missing?" ; exit 25; } dnf config-manager --set-enabled ${list_enabled[@]} || { echo "Repo name missing?" ; exit 25; }
dnf distro-sync -y dnf distro-sync -y
else else
log exit_message "We failed to install the release package." exit_message "We failed to install the release package."
logmessage
fi fi
popd popd
} }
sig_swaps() { sig_swaps() {
log exit_message "Not Available" exit_message "Not Available"
} }
module_check() { module_check() {
echo "Finding our modules that are enabled" &2>1 | tee -a $logfile echo "Finding our modules that are enabled"
for module in "${enabled_modules[@]}"; do for module in "${enabled_modules[@]}"; do
case ${module} in case ${module} in
container-tools|go-toolset|jmc|llvm-toolset|rust-toolset|virt) container-tools|go-toolset|jmc|llvm-toolset|rust-toolset|virt)
@ -128,13 +145,14 @@ module_check() {
done done
if [ ${#unknown_modules[@]} -gt 0 ]; then if [ ${#unknown_modules[@]} -gt 0 ]; then
for x in "${unknown_modules[@]}"; do for x in "${unknown_modules[@]}"; do
echo "${x}" &2>1 | tee -a $logfile echo "${x}"
done done
echo "There are some modules that are unsure of how to handle. This normally shouldn't happen. Do you want to resolve this yourself (Yes) or continue (No)?" &2>1 | tee -a $logfile echo "There are some modules that are unsure of how to handle. This normally shouldn't happen. Do you want to resolve this yourself (Yes) or continue (No)?"
select yn in "Yes" "No"; do select yn in "Yes" "No"; do
case $yn in case $yn in
Yes) Yes)
echo "Ensure how to switch modules, so we are leaving." &2>1 | tee -a $logfile echo "Unsure how to switch modules, so we are leaving."
logmessage
exit 1 exit 1
;; ;;
No) No)
@ -148,31 +166,24 @@ module_check() {
# This is just in case. There is a likelihood this will have to be done. # This is just in case. There is a likelihood this will have to be done.
module_fix() { module_fix() {
for module in "${enabled_modules[@]}"; do for module in "${enabled_modules[@]}"; do
dnf module reset -y "${module}" &2>1 | tee -a $logfile dnf module reset -y "${module}"
case ${module} in case ${module} in
container-tools|go-toolset|jmc|llvm-toolset|rust-toolset|virt) container-tools|go-toolset|jmc|llvm-toolset|rust-toolset|virt)
dnf module install "${module}" -y &2>1 | tee -a $logfile dnf module install "${module}" -y
;; ;;
*) *)
echo "Unsure how to deal with the module presented." &2>1 | tee -a $logfile echo "Unsure how to deal with the module presented."
logmessage
;; ;;
esac esac
# Final update # Final update
dnf update -y &2>1 | tee -a $logfile dnf update -y
done done
} }
## End actual work ## End actual work
# Pipe output of script to $logfile
log(){
printf "\e[1;34m$(date): \e[0m$@\n" >> "$logfile"
"$@" 2>> "$logfile"
}
while getopts "hrVR" option; do while getopts "hrVR" option; do
case "$option" in case "$option" in
h) h)
@ -188,71 +199,80 @@ while getopts "hrVR" option; do
reinstall_all_rpms=true reinstall_all_rpms=true
;; ;;
*) *)
echo "Invalid switch." &2>1 | tee -a $logfile echo "Invalid switch."
usage usage
;; ;;
esac esac
done done
echo "Ensuring rpm, yum, and wget are here." &2>1 | tee -a $logfile echo "Ensuring rpm, yum, and wget are here."
for pkg in rpm yum wget curl; do for pkg in rpm yum wget curl; do
log bin_check "${pkg}" bin_check "${pkg}"
done done
echo "Ensuring your version of CentOS is supported" &2>1 | tee -a $logfile echo "Ensuring your version of CentOS is supported"
if ! old_release=$(rpm -q --whatprovides /etc/redhat-release); then if ! old_release=$(rpm -q --whatprovides /etc/redhat-release); then
log exit_message "You are not running a supported distribution." exit_message "You are not running a supported distribution."
logmessage
fi fi
if [ "$(echo "${old_release}" | wc -l)" -ne 1 ]; then if [ "$(echo "${old_release}" | wc -l)" -ne 1 ]; then
log exit_message "You seem to have package issues. More than one package provides redhat-release." exit_message "You seem to have package issues. More than one package provides redhat-release."
logmessage
fi fi
if ! grep ${SUPPORTED_RELEASE} -q /etc/redhat-release; then if ! grep ${SUPPORTED_RELEASE} -q /etc/redhat-release; then
log exit_message "${SUPPORTED_RELEASE} is only supported for conversion at this time. Stream is not supported." exit_message "${SUPPORTED_RELEASE} is only supported for conversion at this time. Stream is not supported."
logmessage
fi fi
if "${verify_all_rpms}"; then if "${verify_all_rpms}"; then
log generate_rpm_info begin generate_rpm_info begin
fi fi
case "${old_release}" in case "${old_release}" in
centos-linux-release*);; centos-linux-release*);;
rocky-release*) rocky-release*)
log exit_message "You are already running Rocky." exit_message "You are already running Rocky."
logmessage
;; ;;
*) *)
log exit_message "You are running an unsupported distribution. Good bye." exit_message "You are running an unsupported distribution. Good bye."
logmessage
esac esac
# Check our modules before a swap # Check our modules before a swap
module_check module_check
# Actually do the swap and distro-sync # Actually do the swap and distro-sync
log package_swaps package_swaps
# Fix up modules # Fix up modules
module_fix module_fix
# Warning, this is potentially dangerous. # Warning, this is potentially dangerous.
if "${reinstall_all_rpms}"; then if "${reinstall_all_rpms}"; then
echo "!! THIS MAY CAUSE ISSUES WITH YOUR SYSTEM !!" &2>1 | tee -a $logfile echo "!! THIS MAY CAUSE ISSUES WITH YOUR SYSTEM !!"
rpm_list=("$(rpm -qa --qf "%{NAME}-%{VERSION}-%{RELEASE} %{VENDOR}\n" | grep CentOS | awk '{print $1}')") rpm_list=("$(rpm -qa --qf "%{NAME}-%{VERSION}-%{RELEASE} %{VENDOR}\n" | grep CentOS | awk '{print $1}')")
if [[ -n "${rpm_list[*]}" ]]; then if [[ -n "${rpm_list[*]}" ]]; then
echo "Reinstalling rpms: ${rpm_list[*]}" &2>1 | tee -a $logfile echo "Reinstalling rpms: ${rpm_list[*]}"
dnf reinstall "${rpm_list[@]}" -y &2>1 | tee -a $logfile dnf reinstall "${rpm_list[@]}" -y
fi fi
non_rocky_rpm=("$(rpm -qa --qf "%{NAME}-%{VERSION}-%{RELEASE}|%{VENDOR}|%{PACKAGER}\n" |grep -iv Rocky)") non_rocky_rpm=("$(rpm -qa --qf "%{NAME}-%{VERSION}-%{RELEASE}|%{VENDOR}|%{PACKAGER}\n" |grep -iv Rocky)")
if [[ -n ${non_rocky_rpm[*]} ]]; then if [[ -n ${non_rocky_rpm[*]} ]]; then
echo "Non-Rocky packages are installed. This is generally not an issue. If you see centos packages, you may need to address them and file a bug report at https://bugs.rockylinux.org" &2>1 | tee -a $logfile echo "Non-Rocky packages are installed. This is generally not an issue. If you see centos packages, you may need to address them and file a bug report at https://bugs.rockylinux.org"
printf '\t%s\n' "${non_rocky_rpm[@]}" &2>1 | tee -a $logfile printf '\t%s\n' "${non_rocky_rpm[@]}"
fi fi
fi fi
if "${verify_all_rpms}"; then if "${verify_all_rpms}"; then
log generate_rpm_info finish generate_rpm_info finish
echo "You may review the following files:" &2>1 | tee -a $logfile echo "You may review the following files:"
find /root/convert -type f -name "$(hostname)-rpms-*.log" &2>1| tee -a $logfile find /root/convert -type f -name "$(hostname)-rpms-*.log"
fi fi
echo "Done, please reboot your system." &2>1 | tee -a $logfile echo "Done, please reboot your system."
logmessage
) | tee /var/log/centos2rocky.log
# Pipe output to /var/log/centos2rocky.log