From 8fcca12bcaabe9aa746a29391d34c9dad17d01ec Mon Sep 17 00:00:00 2001 From: tigro Date: Thu, 28 Mar 2024 22:19:02 +0300 Subject: [PATCH] Script adaptation for MSVSphere --- msvsphere-deploy.sh | 209 ++++++++++++++++++++++---------------------- 1 file changed, 105 insertions(+), 104 deletions(-) diff --git a/msvsphere-deploy.sh b/msvsphere-deploy.sh index 1438116..b38ff59 100755 --- a/msvsphere-deploy.sh +++ b/msvsphere-deploy.sh @@ -1,28 +1,30 @@ #!/bin/bash -# Description: EL to AlmaLinux migration script. +# Description: EL to MSVSphere migration script. # License: GPLv3. # Environment variables: -# ALMA_RELEASE_URL - almalinux-release package download URL. -# ALMA_PUBKEY_URL - RPM-GPG-KEY-AlmaLinux download URL. +# ALMA_RELEASE_URL - msvsphere-release package download URL. +# ALMA_PUBKEY_URL - RPM-GPG-KEY-MSVSphere download URL. set -euo pipefail BASE_TMP_DIR='/root' OS_RELEASE_PATH='/etc/os-release' REDHAT_RELEASE_PATH='/etc/redhat-release' -STAGE_STATUSES_DIR='/var/run/almalinux-deploy-statuses' +STAGE_STATUSES_DIR='/var/run/msvsphere-deploy-statuses' ALT_ADM_DIR="/var/lib/alternatives" BAK_DIR="/tmp/alternatives_backup" ALT_DIR="/etc/alternatives" -# AlmaLinux OS 8.5 +# MSVSphere OS 8.5 MINIMAL_SUPPORTED_VERSION='8.4' VERSION='0.1.13' DOWNGRADE='NO' BRANDING_PKGS=("centos-backgrounds" "centos-logos" "centos-indexhtml" \ "centos-logos-ipa" "centos-logos-httpd" \ + "almalinux-backgrounds" "almalinux-logos" "almalinux-indexhtml" \ + "almalinux-logos-ipa" "almalinux-logos-httpd" \ "oracle-backgrounds" "oracle-logos" "oracle-indexhtml" \ "oracle-logos-ipa" "oracle-logos-httpd" \ "oracle-epel-release-el8" "oracle-epel-release-el9" \ @@ -39,6 +41,8 @@ REMOVE_PKGS=("centos-linux-release" "centos-gpg-keys" "centos-linux-repos" \ "libreport-plugin-rhtsupport" "libreport-rhel" "insights-client" \ "libreport-rhel-anaconda-bugzilla" "libreport-rhel-bugzilla" \ "linux-firmware-core" \ + "almalinux-release" "almalinux-gpg-keys" "almalinux-repos" \ + "almalinux-obsolete-packages" "libblockdev-btrfs" \ "oraclelinux-release" "oraclelinux-release-el8" \ "oraclelinux-release-el9" "python3-gobject-base-noarch" \ "redhat-release" "redhat-release-eula" \ @@ -53,8 +57,8 @@ module_list_installed="" is_container=0 setup_log_files() { - exec > >(tee /var/log/almalinux-deploy.log) - exec 5> /var/log/almalinux-deploy.debug.log + exec > >(tee /var/log/msvsphere-deploy.log) + exec 5> /var/log/msvsphere-deploy.debug.log BASH_XTRACEFD=5 } @@ -95,7 +99,7 @@ get_status_of_stage() { is_migration_completed() { if get_status_of_stage "completed"; then - printf '\n\033[0;32mMigration to AlmaLinux was already completed\033[0m\n' + printf '\n\033[0;32mMigration to MSVSphere was already completed\033[0m\n' exit 0 fi } @@ -126,8 +130,8 @@ report_step_error() { # Prints program usage information. show_usage() { - echo -e 'Migrates an EL system to AlmaLinux\n' - echo -e 'Usage: almalinux-deploy.sh [OPTION]...\n' + echo -e 'Migrates an EL system to MSVSphere\n' + echo -e 'Usage: msvsphere-deploy.sh [OPTION]...\n' echo ' -h, --help show this message and exit' echo ' -f, --full perform yum upgrade to 8.5 if necessary' echo ' -d, --downgrade option to allow downgrade from CentOS Stream' @@ -222,7 +226,7 @@ get_panel_info() { echo "${panel_type} ${panel_version}" } -# Terminates the program if a platform is not supported by AlmaLinux. +# Terminates the program if a platform is not supported by MSVSphere. # # $1 - Operational system id (ID). # $2 - Operational system version (e.g. 8 or 8.3). @@ -246,7 +250,7 @@ assert_supported_system() { report_step_error "Check EL${os_version} is supported" exit 1 fi - os_types=("centos" "almalinux" "ol" "rhel" "rocky" "virtuozzo") + os_types=("centos" "almalinux" "msvsphere" "ol" "rhel" "rocky" "virtuozzo") if [[ ! " ${os_types[*]} " =~ ${os_type} ]]; then report_step_error "Check ${os_type} operating system is supported" exit 1 @@ -256,7 +260,7 @@ assert_supported_system() { return 0 } -# Terminates the program if a control panel is not supported by AlmaLinux. +# Terminates the program if a control panel is not supported by MSVSphere. # # $1 - Control panel type. # $2 - Control panel version. @@ -310,56 +314,56 @@ assert_supported_filesystem() { save_status_of_stage "assert_supported_filesystem" } -# Returns a latest almalinux-release RPM package download URL. +# Returns a latest msvsphere-release RPM package download URL. # -# $1 - AlmaLinux major version (e.g. 8). +# $1 - MSVSphere major version (e.g. 8). # $2 - System architecture (e.g. x86_64). # -# Prints almalinux-release RPM package download URL. +# Prints msvsphere-release RPM package download URL. get_release_file_url() { local -r os_version="${1:0:1}" local -r arch="${2}" - echo "${ALMA_RELEASE_URL:-https://repo.almalinux.org/almalinux/almalinux-release-latest-${os_version}.${arch}.rpm}" + echo "${ALMA_RELEASE_URL:-https://rsync.inferitos.ru/msvsphere/sphere-release-server-latest-${os_version}.${arch}.rpm https://rsync.inferitos.ru/msvsphere/sphere-release-identity-server-latest-${os_version}.${arch}.rpm https://rsync.inferitos.ru/msvsphere/sphere-release-common-latest-${os_version}.${arch}.rpm}" } -# Returns a latest almalinux-repos RPM package download URL. +# Returns a latest msvsphere-repos RPM package download URL. # -# $1 - AlmaLinux major version (e.g. 9). +# $1 - MSVSphere major version (e.g. 9). # $2 - System architecture (e.g. x86_64). # -# Prints almalinux-release RPM package download URL. +# Prints msvsphere-release RPM package download URL. get_repos_file_url() { local -r os_version="${1:0:1}" local -r arch="${2}" - echo "${ALMA_REPOS_URL:-https://repo.almalinux.org/almalinux/almalinux-repos-latest-${os_version}.${arch}.rpm}" + echo "${ALMA_REPOS_URL:-https://rsync.inferitos.ru/msvsphere/sphere-repos-latest-${os_version}.${arch}.rpm}" } -# Returns a latest almalinux-gpg-keys RPM package download URL. +# Returns a latest msvsphere-gpg-keys RPM package download URL. # -# $1 - AlmaLinux major version (e.g. 9). +# $1 - MSVSphere major version (e.g. 9). # $2 - System architecture (e.g. x86_64). # -# Prints almalinux-gpg-keys RPM package download URL. +# Prints msvsphere-gpg-keys RPM package download URL. get_gpg_keys_file_url() { local -r os_version="${1:0:1}" local -r arch="${2}" - echo "${ALMA_REPOS_URL:-https://repo.almalinux.org/almalinux/almalinux-gpg-keys-latest-${os_version}.${arch}.rpm}" + echo "${ALMA_REPOS_URL:-https://rsync.inferitos.ru/msvsphere/sphere-gpg-keys-latest-${os_version}.${arch}.rpm}" } -# Downloads and installs the AlmaLinux public PGP key. +# Downloads and installs the MSVSphere public PGP key. # # $1 - Temporary directory path. -# $2 - AlmaLinux major version (e.g. 8). +# $2 - MSVSphere major version (e.g. 8). install_rpm_pubkey() { if get_status_of_stage "install_rpm_pubkey"; then return 0 fi local -r tmp_dir="${1}" local -r os_version="${2:0:1}" - local -r ALMA_PUBKEY_URL="https://repo.almalinux.org/almalinux/RPM-GPG-KEY-AlmaLinux-${os_version}" - local -r pubkey_url="${ALMA_PUBKEY_URL:-https://repo.almalinux.org/almalinux/RPM-GPG-KEY-AlmaLinux}" - local -r pubkey_path="${tmp_dir}/RPM-GPG-KEY-AlmaLinux" - local -r step='Download RPM-GPG-KEY-AlmaLinux' + local -r ALMA_PUBKEY_URL="https://rsync.inferitos.ru/msvsphere/RPM-GPG-KEY-MSVSphere-${os_version}" + local -r pubkey_url="${ALMA_PUBKEY_URL:-https://rsync.inferitos.ru/msvsphere/RPM-GPG-KEY-MSVSphere-8}" + local -r pubkey_path="${tmp_dir}/RPM-GPG-KEY-MSVSphere" + local -r step='Download RPM-GPG-KEY-MSVSphere' local output if ! output=$(curl -f -s -S -o "${pubkey_path}" "${pubkey_url}" 2>&1); then report_step_error "${step}" "${output}" @@ -368,60 +372,60 @@ install_rpm_pubkey() { report_step_done "${step}" fi rpm --import "${pubkey_path}" - report_step_done 'Import RPM-GPG-KEY-AlmaLinux to RPM DB' + report_step_done 'Import RPM-GPG-KEY-MSVSphere to RPM DB' rm -f "${pubkey_path}" save_status_of_stage "install_rpm_pubkey" } -# Downloads almalinux-release package. +# Downloads msvsphere-release package. # # $1 - Temporary directory path. -# $2 - almalinux-release package download URL. +# $2 - msvsphere-release package download URL. # # Prints downloaded file path. download_release_files() { local -r tmp_dir="${1}" local -r release_url="${2}" - local -r release_path="${tmp_dir}/almalinux-release-latest.rpm" + local -r release_path="${tmp_dir}/sphere-release-server-latest.rpm ${tmp_dir}/sphere-release-identity-server-latest.rpm ${tmp_dir}/sphere-release-common-latest.rpm" local output - if ! output=$(curl -f -s -S -o "${release_path}" "${release_url}" 2>&1); then - report_step_error 'Download almalinux packages - release' "${output}" + if ! output=$(for url in ${release_url}; do curl -f -s -S -o "${tmp_dir}/$(echo $url | awk -F/ '{ print $NF }' | sed 's@-[0-9].*$@.rpm@')" "${url}"; done 2>&1); then + report_step_error 'Download msvsphere packages - release' "${output}" exit 1 fi echo "${release_path}" } -# Downloads almalinux-repos package. +# Downloads msvsphere-repos package. # # $1 - Temporary directory path. -# $2 - almalinux-repos package download URL. +# $2 - msvsphere-repos package download URL. # # Prints downloaded file path. download_repos_files() { local -r tmp_dir="${1}" local -r repos_url="${2}" - local -r repos_path="${tmp_dir}/almalinux-repos.rpm" + local -r repos_path="${tmp_dir}/msvsphere-repos.rpm" local output if ! output=$(curl -f -s -S -o "${repos_path}" "${repos_url}" 2>&1); then - report_step_error 'Download almalinux packages - repos' "${output}" + report_step_error 'Download msvsphere packages - repos' "${output}" exit 1 fi echo "${repos_path}" } -# Downloads almalinux-gpg-keys package. +# Downloads msvsphere-gpg-keys package. # # $1 - Temporary directory path. -# $2 - almalinux-gpg-keys package download URL. +# $2 - msvsphere-gpg-keys package download URL. # # Prints downloaded file path. download_gpg_keys_files() { local -r tmp_dir="${1}" local -r gpg_keys_url="${2}" - local -r gpg_keys_path="${tmp_dir}/almalinux-gpg-keys.rpm" + local -r gpg_keys_path="${tmp_dir}/msvsphere-gpg-keys.rpm" local output if ! output=$(curl -f -s -S -o "${gpg_keys_path}" "${gpg_keys_url}" 2>&1); then - report_step_error 'Download almalinux packages - gpg-keys' "${output}" + report_step_error 'Download msvsphere packages - gpg-keys' "${output}" exit 1 fi echo "${gpg_keys_path}" @@ -433,12 +437,13 @@ download_gpg_keys_files() { assert_valid_package() { local -r pkg_path="${1}" local output - if ! output=$(rpm -K "${pkg_path}" 2>&1); then - report_step_error "Verify $(basename "${pkg_path}") package" \ + rpm -K $pkg_path 2>&1 + if ! output=$(rpm -K ${pkg_path} 2>&1); then + report_step_error "Verify ${pkg_path} package" \ "${output}" exit 1 fi - report_step_done 'Verify almalinux-release package' + report_step_done 'Verify msvsphere-release package' } # @@ -492,10 +497,10 @@ dnf_upgrade() { report_step_done 'DNF upgrade' } -# Terminates the program if OS version doesn't match AlmaLinux version. +# Terminates the program if OS version doesn't match MSVSphere version. # # $1 - OS version. -# $2 - almalinux-release package file path. +# $2 - msvsphere-release package file path. assert_compatible_os_version() { if get_status_of_stage "assert_compatible_os_version"; then return 0 @@ -503,7 +508,7 @@ assert_compatible_os_version() { local -r os_version="${1}" local -r release_path="${2}" local alma_version - alma_version=$(rpm -qp --queryformat '%{version}' "${release_path}") + alma_version=$(rpm -qp --queryformat '%{version}' ${release_path}) if [[ "$(get_os_release_var 'NAME')" != 'CentOS Stream' ]]; then if [[ "${os_version:0:1}" -lt "${MINIMAL_SUPPORTED_VERSION:0:1}" ]] && [[ "${os_version:2:3}" -lt "${MINIMAL_SUPPORTED_VERSION:2:3}" ]]; then @@ -581,42 +586,42 @@ remove_not_needed_redhat_dirs() { } -# Install package almalinux-release -install_almalinux_release_package() { - if get_status_of_stage "install_almalinux_release_package"; then +# Install package msvsphere-release +install_msvsphere_release_package() { + if get_status_of_stage "install_msvsphere_release_package"; then return 0 fi local -r release_path="${1}" - rpm -Uvh --nodeps "${release_path}" - report_step_done 'Install almalinux-release package' - save_status_of_stage "install_almalinux_release_package" + rpm -Uvh --nodeps ${release_path} + report_step_done 'Install msvsphere-release package' + save_status_of_stage "install_msvsphere_release_package" } -# Install package almalinux-repos -install_almalinux_repos_package() { - if get_status_of_stage "install_almalinux_repos_package"; then +# Install package msvsphere-repos +install_msvsphere_repos_package() { + if get_status_of_stage "install_msvsphere_repos_package"; then return 0 fi local -r repos_path="${1}" rpm -Uvh --nodeps "${repos_path}" - report_step_done 'Install almalinux-repos package' - save_status_of_stage "install_almalinux_repos_package" + report_step_done 'Install msvsphere-repos package' + save_status_of_stage "install_msvsphere_repos_package" } -# Install package almalinux-gpg-keys +# Install package msvsphere-gpg-keys # -# $1 - full path (including package filename) to the almalinux-gpg-keys package -install_almalinux_gpg_keys_package() { - if get_status_of_stage "install_almalinux_gpg_keys_package"; then +# $1 - full path (including package filename) to the msvsphere-gpg-keys package +install_msvsphere_gpg_keys_package() { + if get_status_of_stage "install_msvsphere_gpg_keys_package"; then return 0 fi local -r gpg_keys_path="${1}" rpm -Uvh --nodeps "${gpg_keys_path}" - report_step_done 'Install almalinux-gpg-keys package' - save_status_of_stage "install_almalinux_gpg_keys_package" + report_step_done 'Install msvsphere-gpg-keys package' + save_status_of_stage "install_msvsphere_gpg_keys_package" } -# Remove brand packages and install the same AlmaLinux packages +# Remove brand packages and install the same MSVSphere packages replace_brand_packages() { if get_status_of_stage "replace_brand_packages"; then return 0 @@ -636,7 +641,7 @@ replace_brand_packages() { ;; *) # shellcheck disable=SC2001 - alma_pkg="$(echo "${pkg_name}" | sed 's#centos\|oracle\|redhat\|rocky\|vzlinux#almalinux#')" + alma_pkg="$(echo "${pkg_name}" | sed 's#centos\|oracle\|redhat\|rocky\|almalinux\|vzlinux#sphere#')" ;; esac alma_pkgs+=("${alma_pkg}") @@ -658,33 +663,25 @@ replace_brand_packages() { } -# Converts a CentOS like system to AlmaLinux +# Converts a CentOS like system to MSVSphere # -# $1 - almalinux-release RPM package path. -# $2 - almalinux-repos RPM package path. -# $3 - almalinux-gpg-keys RPM package path +# $1 - msvsphere-release RPM package path. +# $2 - msvsphere-repos RPM package path. +# $3 - msvsphere-gpg-keys RPM package path migrate_from_centos() { if get_status_of_stage "migrate_from_centos"; then return 0 fi local -r release_path="${1}" - case "${os_version}" in - 9*) - local -r repos_path="${2}" - local -r gpg_keys_path="${3}" - ;; - esac - # replace OS packages with almalinux-release + local -r repos_path="${2}" + local -r gpg_keys_path="${3}" + # replace OS packages with msvsphere-release # and OS centos-specific packages remove_os_specific_packages_before_migration remove_not_needed_redhat_dirs - install_almalinux_release_package "${release_path}" - case "${os_version}" in - 9*) - install_almalinux_repos_package "${repos_path}" - install_almalinux_gpg_keys_package "${gpg_keys_path}" - ;; - esac + install_msvsphere_release_package "${release_path}" + install_msvsphere_repos_package "${repos_path}" + install_msvsphere_gpg_keys_package "${gpg_keys_path}" replace_brand_packages save_status_of_stage "migrate_from_centos" } @@ -776,9 +773,9 @@ install_kernel() { fi if ! output=$(rpm -q kernel 2>&1); then if output=$(dnf -y install kernel 2>&1); then - report_step_done "Install AlmaLinux kernel" + report_step_done "Install MSVSphere kernel" else - report_step_error "Install AlmaLinux kernel" + report_step_error "Install MSVSphere kernel" fi fi save_status_of_stage "install_kernel" @@ -1010,21 +1007,21 @@ add_efi_boot_record() { fi if [[ ${arch} == "x86_64" && $device == *"/dev/md"* ]]; then - efibootmgr -c -L "AlmaLinux" -l "\EFI\almalinux\shimx64.efi" -d "${disk_name1}" -p "${disk_num1}" - efibootmgr -c -L "AlmaLinux" -l "\EFI\almalinux\shimx64.efi" -d "${disk_name2}" -p "${disk_num2}" + efibootmgr -c -L "MSVSphere" -l "\EFI\msvsphere\shimx64.efi" -d "${disk_name1}" -p "${disk_num1}" + efibootmgr -c -L "MSVSphere" -l "\EFI\msvsphere\shimx64.efi" -d "${disk_name2}" -p "${disk_num2}" elif [[ ${arch} == "aarch64" && $device == *"/dev/md"* ]]; then - efibootmgr -c -L "AlmaLinux" -l "\EFI\almalinux\shimaa64.efi" -d "${disk_name1}" -p "${disk_num1}" - efibootmgr -c -L "AlmaLinux" -l "\EFI\almalinux\shimaa64.efi" -d "${disk_name2}" -p "${disk_num2}" + efibootmgr -c -L "MSVSphere" -l "\EFI\msvsphere\shimaa64.efi" -d "${disk_name1}" -p "${disk_num1}" + efibootmgr -c -L "MSVSphere" -l "\EFI\msvsphere\shimaa64.efi" -d "${disk_name2}" -p "${disk_num2}" elif [[ ${arch} == "x86_64" ]]; then - efibootmgr -c -L "AlmaLinux" -l "\EFI\almalinux\shimx64.efi" -d "${disk_name}" -p "${disk_num}" + efibootmgr -c -L "MSVSphere" -l "\EFI\msvsphere\shimx64.efi" -d "${disk_name}" -p "${disk_num}" elif [[ ${arch} == "aarch64" ]]; then - efibootmgr -c -L "AlmaLinux" -l "\EFI\almalinux\shimaa64.efi" -d "${disk_name}" -p "${disk_num}" + efibootmgr -c -L "MSVSphere" -l "\EFI\msvsphere\shimaa64.efi" -d "${disk_name}" -p "${disk_num}" fi - report_step_done "The new EFI boot record for AlmaLinux is added" + report_step_done "The new EFI boot record for MSVSphere is added" save_status_of_stage "add_efi_boot_record" } @@ -1036,16 +1033,16 @@ reinstall_secure_boot_packages() { if [ "$(which grubby)" ] ; then #if this happens on a system with GRUB and related tools, rather than on RPi local kernel_package for pkg in $(rpm -qa | grep -E 'shim|fwupd|grub2'); do - if [[ "AlmaLinux" != "$(rpm -q --queryformat '%{vendor}' "$pkg")" ]]; then + if [[ "MSVSphere" != "$(rpm -q --queryformat '%{vendor}' "$pkg")" ]]; then yum reinstall "${pkg}" -y fi done kernel_package="$(rpm -qf "$(grubby --default-kernel)")" - if [[ "AlmaLinux" != "$(rpm -q --queryformat '%{vendor}' "${kernel_package}")" ]]; then + if [[ "MSVSphere" != "$(rpm -q --queryformat '%{vendor}' "${kernel_package}")" ]]; then yum reinstall "${kernel_package}" -y fi fi - report_step_done "All Secure Boot related packages which were not released by AlmaLinux are reinstalled" + report_step_done "All Secure Boot related packages which were not released by MSVSphere are reinstalled" save_status_of_stage "reinstall_secure_boot_packages" } @@ -1099,7 +1096,7 @@ main() { install_rpm_pubkey "${tmp_dir}" "${os_version}" release_path=$(download_release_files "${tmp_dir}" "${release_url}") - report_step_done 'Download almalinux-release package' + report_step_done 'Download msvsphere-release package' if mount | grep -q fuse.lxcfs || env | grep -q 'container=lxc' || awk '{print $1}' /proc/vz/veinfo 2>/dev/null || @@ -1111,7 +1108,7 @@ main() { assert_compatible_os_version "${os_version}" "${release_path}" case "${os_type}" in - almalinux|centos|ol|rhel|rocky|virtuozzo) + almalinux|centos|msvsphere|ol|rhel|rocky|virtuozzo) backup_issue if [[ "${os_type}" == "rhel" ]]; then @@ -1120,7 +1117,11 @@ main() { case "${os_version}" in 8*) - migrate_from_centos "${release_path}" + repos_url=$(get_repos_file_url "${os_version}" "${arch}") + repos_path=$(download_repos_files "${tmp_dir}" "${repos_url}") + gpg_keys_url=$(get_gpg_keys_file_url "${os_version}" "${arch}") + gpg_keys_path=$(download_gpg_keys_files "${tmp_dir}" "${gpg_keys_url}") + migrate_from_centos "${release_path}" "${repos_path}" "${gpg_keys_path}" ;; 9*) repos_url=$(get_repos_file_url "${os_version}" "${arch}") @@ -1152,7 +1153,7 @@ main() { fi check_custom_kernel save_status_of_stage "completed" - printf '\n\033[0;32mMigration to AlmaLinux is completed\033[0m\n' + printf '\n\033[0;32mMigration to MSVSphere is completed\033[0m\n' } if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then