Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- rtd_oem_release_upgrade() {
- # Description: Function to attempt to perform a release upgade on several Linux distributions.
- # Supported distributions are: Ubuntu, Pop! OS, Debian, SUSE, and fedora.
- # This function does not require any arguments but will respect "interactive". The "interactive"
- # parameter will force the function to pause if a supported distribution is not found.
- # It will check for a supported distribution and attempt the upgrade if possible.
- # If a supported distribution is not detected the function will do nothing.
- #
- # Globals:
- # Arguments: None
- # Outputs:
- # Returns:
- # Usage: (in a script):
- # rtd_oem_release_upgrade [ string ]
- #
- # [ string ] : interactive
- #
- # End of Documentation
- ensure_admin
- local interactive=$1
- local distro=$(hostnamectl | grep -Eo 'Ubuntu|Pop!_OS|Debian|SUSE|fedora|TUXEDO|Zorin')
- case $distro in
- "Ubuntu"|"Pop!_OS"|"TUXEDO|Zorin")
- # Common update steps for Ubuntu and derivativres
- write_warning "This may take some time, please be patient!"
- apt clean && apt update -m ; dpkg --configure -a ; apt install -f ; apt dist-upgrade ; apt autoremove --purge
- if [[ "$interactive" == "interactive" ]]; then
- $RTD_GUI --title "$distro Distribution Upgrade Confirmation" --yesno "Please confirm that you want to upgrade to the next version of $distro. This may take some time, please be patient!" 8 78
- case $? in
- 0 ) do-release-upgrade | tee -a ${_LOGFILE} ;;
- 1|255 ) return 1 ;;
- esac
- else
- do-release-upgrade --quiet | tee -a ${_LOGFILE}
- fi
- ;;
- "Debian")
- write_error "Debian does not provide an upgrade tool between major releases. Please use the manual upgrade method."
- return 1
- ;;
- "SUSE")
- # SUSE upgrade steps
- if current_version=$(cat /etc/os-release | grep VERSION_ID | cut -d '"' -f2) ; then
- write_status "Current SUSE version: $current_version"
- else
- write_error "unable to query /etc/os-release for current version of SUSE! "
- return 1
- fi
- if latest_version=$(curl -s https://download.opensuse.org/distribution/openSUSE-current/iso/ | grep -Eo '1[5-9]\.[0-9]|20\.[0-9]+' | sort -V | tail -n1) ; then
- write_status "Latest SUSE version: $latest_version"
- else
- write_error "unable to query opensuse.org for latest version of SUSE! Check access to internet and try again."
- return 1
- fi
- if [ "$(printf '%s\n' "$current_version" "$latest_version" | sort -V | head -n1)" != "$current_version" ]; then
- write_status "A newer version of SUSE is available: $latest_version"
- write_warning "This REALLY may take some time, please be patient!"
- write_information "These are the current repositories:"
- {
- zypper repos --uri
- zypper modifyrepo --enable repo-update
- zypper repos --uri
- zypper refresh
- } | tee -a ${_LOGFILE}
- write_status "Checking if it is possible to upgrade to ${SUSE_VER}"
- if zypper --releasever="${SUSE_VER}" lr -u ; then
- zypper --releasever="${SUSE_VER}" ref
- write_status "Attempting upgrade of system now..."
- zypper --releasever="${SUSE_VER}" dup --force-resolution
- wait
- [[ "$interactive" == "interactive" ]] && read -p "$ERRMSG: Press [ ENTER ] to REBOOT:"
- reboot
- else
- write_error "It is not possible to upgrade to Open Suse ${SUSE_VER} since there does not appear to be a release server available for ${SUSE_VER}"
- [[ "$interactive" == "interactive" ]] && read -p "$ERRMSG: Press [ ENTER ] to continue:"
- fi
- else
- write_information "You are using the latest version of SUSE: $current_version"
- [[ "$interactive" == "interactive" ]] && read -p "$ERRMSG: Press [ ENTER ] to continue:"
- fi
- ;;
- "fedora")
- # Fedora upgrade steps
- if [[ "$interactive" == "interactive" ]]; then
- latest_version=$(curl -s https://dl.fedoraproject.org/pub/fedora/linux/releases/ | cut -d' ' -f5 |grep -Eo '[0-9][5-9]' | sort -V | tail -n1)
- releasever=$($RTD_GUI --title "Fedora Distribution Upgrade Confirmation" \
- --inputbox "Please enter the Fedora version you want to upgrade to. Latest version is . Current version: $latest_version $(hostnamectl | grep -oP '(?<=Operating System: Fedora\s)\d+')\nOnly numbers are valid." 10 78 3>&1 1>&2 2>&3)
- else
- releasever=$(curl -s https://dl.fedoraproject.org/pub/fedora/linux/releases/ | cut -d' ' -f5 |grep -Eo '[0-9][5-9]' | sort -V | tail -n1)
- fi
- # Validate input
- if [[ ! $releasever =~ ^[0-9]+$ ]]; then
- write_error "Invalid version number. Upgrade aborted."
- return 1
- fi
- # Upgrade process
- write_status "Starting upgrade process for Fedora. This may take some time."
- {
- dnf clean all
- dnf upgrade --refresh -y
- dnf install dnf-plugin-system-upgrade -y
- if ! dnf system-upgrade download --refresh --releasever="${releasever}"; then
- write_error "Failed to download system upgrade packages."
- return 1
- fi
- } | tee -a ${_LOGFILE}
- # Confirmation for reboot
- if [[ "$interactive" == "interactive" ]]; then
- read -p "$ERRMSG: Press [ ENTER ] to REBOOT and install the upgrade:"
- fi
- # Rebooting to apply upgrade
- dnf system-upgrade reboot
- return $?
- ;;
- *)
- system::log_item "This distribution is not supported for release upgrade."
- [[ "$interactive" == "interactive" ]] && read -p "This distribution is not supported. Press [Enter] key to return to menu."
- return 1
- ;;
- esac
- return
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement