Merge pull request #8 from carterpeel/main

Added logging facility & non-builtin package sanity checks
This commit is contained in:
Louis Abel 2021-05-03 16:02:01 -07:00 committed by GitHub
commit 00a3f2864d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 37 additions and 4 deletions

41
centos2rocky.sh Normal file → Executable file
View File

@ -1,17 +1,30 @@
#!/bin/bash
#!/usr/bin/env bash
# label <label@rockylinux.org>
# Supports only CentOS 8.3
## 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
unset CDPATH
if [ "$(id -u)" -ne 0 ]; then
if [[ "$(id -u)" -ne 0 ]]; then
echo "You must run this script as root."
echo "Either use sudo or 'su -c ${0}'"
fi
if [[ "$(wget 2>/dev/null || echo $?)" == 127 ]]; then
echo "Wget is not installed! Installing it..."
dnf -y install wget
fi
if [[ "$(curl 2>/dev/null || echo $?)" == 127 ]]; then
echo "Curl is not installed! Installing it..."
dnf -y install curl libcurl
fi
export LANG=en_US.UTF-8
SUPPORTED_RELEASE="8.3"
@ -59,6 +72,11 @@ exit_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."
logmessage
}
logmessage(){
echo "A log of this installation can be found at /var/log/centos2rocky.log"
}
## The actual work
@ -69,6 +87,7 @@ bin_hash() {
bin_check() {
if ! bin_hash "$1"; then
exit_message "'${1}' command not found. Please ensure you are running bash or that your PATH is set correctly."
logmessage
fi
}
@ -85,7 +104,7 @@ package_swaps() {
pushd /root/release
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
# Remove packages we need to swap
@ -103,7 +122,9 @@ package_swaps() {
dnf distro-sync -y
else
exit_message "We failed to install the release package."
logmessage
fi
popd
}
@ -130,7 +151,8 @@ module_check() {
select yn in "Yes" "No"; do
case $yn in
Yes)
echo "Ensure how to switch modules, so we are leaving."
echo "Unsure how to switch modules, so we are leaving."
logmessage
exit 1
;;
No)
@ -151,6 +173,7 @@ module_fix() {
;;
*)
echo "Unsure how to deal with the module presented."
logmessage
;;
esac
# Final update
@ -158,6 +181,7 @@ module_fix() {
done
}
## End actual work
while getopts "hrVR" option; do
@ -189,14 +213,17 @@ done
echo "Ensuring your version of CentOS is supported"
if ! old_release=$(rpm -q --whatprovides /etc/redhat-release); then
exit_message "You are not running a supported distribution."
logmessage
fi
if [ "$(echo "${old_release}" | wc -l)" -ne 1 ]; then
exit_message "You seem to have package issues. More than one package provides redhat-release."
logmessage
fi
if ! grep ${SUPPORTED_RELEASE} -q /etc/redhat-release; then
exit_message "${SUPPORTED_RELEASE} is only supported for conversion at this time. Stream is not supported."
logmessage
fi
if "${verify_all_rpms}"; then
@ -207,9 +234,11 @@ case "${old_release}" in
centos-linux-release*);;
rocky-release*)
exit_message "You are already running Rocky."
logmessage
;;
*)
exit_message "You are running an unsupported distribution. Good bye."
logmessage
esac
# Check our modules before a swap
@ -243,3 +272,7 @@ if "${verify_all_rpms}"; then
fi
echo "Done, please reboot your system."
logmessage
) | tee /var/log/centos2rocky.log
# Pipe output to /var/log/centos2rocky.log