Advertisement
vonschutter

Untitled

May 24th, 2024
766
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 5.38 KB | None | 0 0
  1.  
  2. rtd_oem_release_upgrade() {
  3. # Description: Function to attempt to perform a release upgade on several Linux distributions.
  4. # Supported distributions are: Ubuntu, Pop! OS, Debian, SUSE, and fedora.
  5. # This function does not require any arguments but will respect "interactive". The "interactive"
  6. # parameter will force the function to pause if a supported distribution is not found.
  7. # It will check for a supported distribution and attempt the upgrade if possible.
  8. # If a supported distribution is not detected the function will do nothing.
  9. #
  10. # Globals:
  11. # Arguments: None
  12. # Outputs:
  13. # Returns:
  14. # Usage:  (in a script):
  15. #  rtd_oem_release_upgrade [ string ]
  16. #
  17. # [ string ] : interactive
  18. #
  19. # End of Documentation
  20.  
  21.  
  22.     ensure_admin
  23.     local interactive=$1
  24.     local distro=$(hostnamectl | grep -Eo 'Ubuntu|Pop!_OS|Debian|SUSE|fedora|TUXEDO|Zorin')
  25.  
  26.     case $distro in
  27.         "Ubuntu"|"Pop!_OS"|"TUXEDO|Zorin")
  28.             # Common update steps for Ubuntu and derivativres
  29.             write_warning "This may take some time, please be patient!"
  30.             apt clean && apt update -m ; dpkg --configure -a ; apt install -f ; apt dist-upgrade ; apt autoremove --purge
  31.             if [[ "$interactive" == "interactive" ]]; then
  32.                 $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
  33.                 case $? in
  34.                 0 ) do-release-upgrade | tee -a ${_LOGFILE} ;;
  35.                 1|255 ) return 1 ;;
  36.                 esac
  37.             else
  38.                 do-release-upgrade --quiet | tee -a ${_LOGFILE}
  39.             fi
  40.         ;;
  41.         "Debian")
  42.             write_error "Debian does not provide an upgrade tool between major releases. Please use the manual upgrade method."
  43.             return 1
  44.         ;;
  45.         "SUSE")
  46.             # SUSE upgrade steps
  47.             if current_version=$(cat /etc/os-release | grep VERSION_ID | cut -d '"' -f2) ; then
  48.                 write_status "Current SUSE version: $current_version"
  49.             else
  50.                 write_error "unable to query /etc/os-release for current version of SUSE! "
  51.                 return 1
  52.             fi
  53.  
  54.             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
  55.                 write_status "Latest SUSE version: $latest_version"
  56.             else
  57.                 write_error "unable to query opensuse.org for latest version of SUSE! Check access to internet and try again."
  58.                 return 1
  59.             fi
  60.  
  61.             if [ "$(printf '%s\n' "$current_version" "$latest_version" | sort -V | head -n1)" != "$current_version" ]; then
  62.                 write_status "A newer version of SUSE is available: $latest_version"
  63.                 write_warning "This REALLY may take some time, please be patient!"
  64.                 write_information "These are the current repositories:"
  65.                 {
  66.                     zypper repos --uri
  67.                     zypper modifyrepo --enable repo-update
  68.                     zypper repos --uri
  69.                     zypper refresh
  70.                 } | tee -a ${_LOGFILE}
  71.  
  72.                 write_status "Checking if it is possible to upgrade to ${SUSE_VER}"
  73.                 if zypper --releasever="${SUSE_VER}" lr -u ; then
  74.                     zypper --releasever="${SUSE_VER}" ref
  75.                     write_status "Attempting upgrade of system now..."
  76.                     zypper --releasever="${SUSE_VER}" dup --force-resolution
  77.                     wait
  78.                     [[ "$interactive" == "interactive" ]] && read -p "$ERRMSG: Press  [ ENTER ] to REBOOT:"
  79.                     reboot
  80.                 else
  81.                     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}"
  82.                     [[ "$interactive" == "interactive" ]] && read -p "$ERRMSG: Press  [ ENTER ] to continue:"
  83.                 fi
  84.             else
  85.                 write_information "You are using the latest version of SUSE: $current_version"
  86.                 [[ "$interactive" == "interactive" ]] && read -p "$ERRMSG: Press  [ ENTER ] to continue:"
  87.             fi
  88.         ;;
  89.         "fedora")
  90.             # Fedora upgrade steps
  91.             if [[ "$interactive" == "interactive" ]]; then
  92.                 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)
  93.                 releasever=$($RTD_GUI --title "Fedora Distribution Upgrade Confirmation" \
  94.                     --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)
  95.             else
  96.                 releasever=$(curl -s https://dl.fedoraproject.org/pub/fedora/linux/releases/ | cut -d' ' -f5 |grep -Eo '[0-9][5-9]' | sort -V | tail -n1)
  97.             fi
  98.  
  99.             # Validate input
  100.             if [[ ! $releasever =~ ^[0-9]+$ ]]; then
  101.                 write_error "Invalid version number. Upgrade aborted."
  102.                 return 1
  103.             fi
  104.  
  105.             # Upgrade process
  106.             write_status "Starting upgrade process for Fedora. This may take some time."
  107.             {
  108.                 dnf clean all
  109.                 dnf upgrade --refresh -y
  110.                 dnf install dnf-plugin-system-upgrade -y
  111.                 if ! dnf system-upgrade download --refresh --releasever="${releasever}"; then
  112.                     write_error "Failed to download system upgrade packages."
  113.                     return 1
  114.                 fi
  115.             } | tee -a ${_LOGFILE}
  116.  
  117.             # Confirmation for reboot
  118.             if [[ "$interactive" == "interactive" ]]; then
  119.                 read -p "$ERRMSG: Press [ ENTER ] to REBOOT and install the upgrade:"
  120.             fi
  121.  
  122.             # Rebooting to apply upgrade
  123.             dnf system-upgrade reboot
  124.             return $?
  125.         ;;
  126.         *)
  127.         system::log_item "This distribution is not supported for release upgrade."
  128.         [[ "$interactive" == "interactive" ]] && read -p "This distribution is not supported. Press [Enter] key to return to menu."
  129.         return 1
  130.         ;;
  131.     esac
  132.     return
  133.  
  134. }
  135.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement