Announcement

Collapse
No announcement yet.

Script to get rid of Snap

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Script to get rid of Snap

    ########
    ## -> Please note that the support for Kubuntu™ 24.04 LTS is preliminary as long as it has not been officially released!
    ########
    ​​

    Purpose of this script

    This is a little helper script for Kubuntu™ users who want to get rid of and block Snap entirely (like Linux Mint and TUXEDO OS do), including the Firefox Snap in 22.04 LTS & later and e.g. the Thunderbird and Firmware Updater Snaps in 24.04 LTS.
    It has been tested many times with Kubuntu™ 20.04 LTS up to 23.10.

    I hope you find the script useful! Yours respectfully, Schwarzer Kater

    Installation and usage of this script
    1. You can download the script from here: https://gitlab.com/scripts94/kubuntu-get-rid-of-snap
      Click on its name in the file list and on the next page use the download button on the far right side of the script name.
      OR
      Copy and paste the code of the script into a blank Kate text editor document and save it as "Kubuntu_get_rid_of_Snap.sh" to e.g. your home directory.
    2. Make the file Kubuntu_get_rid_of_Snap.sh executable in the Dolphin file manager:
      go to the directory you downloaded/saved the script to, right-click on the file and choose Properties -> Permissions -> enable Is executable -> choose OK.
      OR
      Make the file Kubuntu_get_rid_of_Snap.sh executable in the Konsole terminal emulator:
      go to the directory you downloaded/saved the script to (cd [path to]/[name of directory], e.g. cd ~/Downloads) and enter:
      chmod +x Kubuntu_get_rid_of_Snap.sh.
    3. To run the script in the Konsole terminal emulator go to the directory you downloaded/saved the script to and enter:
      ./Kubuntu_get_rid_of_Snap.sh.

    Important
    • This script is best run after a fresh installation of Kubuntu™ but has also been written to be run directly after a release-upgrade to the next main Kubuntu™ version (e.g. from 23.10 to 24.04 LTS).
      It should also work with a Kubuntu™ installation that has been used for a while - depending on your own system modifications - but BE AWARE THAT ALL PROGRAMS YOU ADDITIONALLY INSTALLED AS SNAPS WILL BE REMOVED TOO!
      It has been designed to be run in combination with the reinstall_Snap_for_release-upgrade script.
    • A full upgrade of the system (either with Discover or in Konsole with sudo snap refresh && sudo apt update && sudo apt full-upgrade) AND a reboot is strongly recommended prior to running this script.
    You will be asked twice for confirmation before the removal of Snaps and snapd is started and/or APT pinning to block future installation of Snap is applied - and if you answer "n" or "N" no changes at all are made to your system.​

    For some more information about what is done in detail see the comments within the script itself.

    Known issues / bugs
    • After removing Snap there can be an empty icon (which looks like a white sheet of paper) in the Plasma Panel, if e.g. the Firefox Snap was pinned there before.
      -> The solution is to simply right-click on this icon and choose "Unpin from Task Manager".


    Additional tip

    Flatpak is a good alternative (and IMHO better suited for desktop usage than Snap) if you have removed Snap but still want to use a containerized format for certain desktop applications or get newer versions of programs than the *Ubuntu™ repositories provide.
    Please know that both Flatpaks and Snaps use up more space of your storage medium than "traditional" binaries.​
    For Kubuntu™ 22.04 LTS absolutely read this post!
    1. Flatpak is easy to install - open your Konsole terminal emulator and enter:
      sudo apt update && sudo apt install flatpak
    2. To enable the Flathub repository for Flatpaks (which is currently the largest one and is supported by e.g. KDE and GNOME) enter:
      flatpak remote-add --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo
      You can enable other Flatpak repositories like e.g. the one from Fedora or from individual developers later on if you wish to do so.
    3. To be able to find, update, install and remove Flatpaks with the Discover software center you should additionally install the Discover support for Flatpak - enter:
      sudo apt install plasma-discover-backend-flatpak
    4. To manage Flatpak permission from Kubuntu™ 23.04 onwards you can install the Flatpak Permissions Settings module for System Settings:
      sudo apt install kde-config-flatpak
      To manage Flatpak permissions for Kubuntu™ 20.04 to 22.10 you can install the Flatseal Flatpak.
    5. Reboot your system or at least log out and in again.
    Also see https://flatpak.org/setup/Kubuntu.

    Other Ubuntu™-based distributions

    No other Ubuntu™-based distributions/flavours but Kubuntu™ are officially supported.

    In its current state my script does not work with Ubuntu™ (Gnome) or other GTK/Gnome based flavours like Xubuntu™, Ubuntu MATE™, etc. as they use the Snap Store or the Gnome Software Center instead of Discover - to name just one example.
    Due to the amount of time it would take to change and thoroughly test this script accordingly I will probably also not support them in the future.
    But by all means feel free to use my script as a template to do so.

    That said the script does work with Lubuntu™ and Ubuntu Studio™ (KDE Plasma) so far.
    Last edited by Schwarzer Kater; Apr 15, 2024, 09:44 AM.
    Debian KDE & LXQt • Kubuntu & Lubuntu • openSUSE KDE • Windows • macOS X
    Desktop: Lenovo ThinkCentre M75s • Laptop: Apple MacBook Pro 13" • and others

    get rid of Snap scriptreinstall Snap for release-upgrade scriptinstall traditional Firefox script

    #2
    Changelog
    • Version 2.1.0, released 2024-04-14
      - ADDED FEATURE to block future installation of snapd and Snaps by APT pinning
      even if no snapd or Snaps are installed (like for the "Minimal Installation"
      option of Kubuntu 24.04 LTS)
      - improved code for Kubuntu 24.04 LTS
      - improved language​
    • Version 2.0.1, released 2024-04-07
      - improved code for Kubuntu 24.04 LTS
      - improved comments
      - improved summary for Kubuntu 24.04 LTS​
    • Version 2.0.0, released 2024-04-05
      - REMOVED FEATURE: the Mozilla Team PPA is not supported any longer!
      - ADDED FEATURE to explicitly remove the Thunderbird and Firmware Updater Snaps
      in Kubuntu 24.04 LTS
      - improved code
      - improved language
      - improved comments​
    • Version 1.1.3, released 2023-06-21
      - improved code​
    • Version 1.1.2, released 2023-04-25
      - improved language
    • Version 1.1.1, released 2023-04-06
      - removed confirmation (unnecessary second question) to deinstall Snap, if it is
      not installed
      - improved code
      - cleaned up code
      - improved comments
    • Version 1.1.0, released 2023-04-03
      - ADDED FEATURE to save summary as a text file for future reference, if the
      script had changed anything
      - CORRECTED BUG IN CODE (now a situation is prevented when Firefox from the
      Mozilla Team PPA could be reinstalled by the script although Firefox from
      Mozilla.org had been installed by the user in the meantime)
      - CORRECTED BUG IN CODE (removed unnecessary "sudo")
      - improved summary
      - changed version number to semantic versioning
    • Version 290323, released 2023-03-29
      - initial public release​


    Some questions have already been answered here: https://www.kubuntuforums.net/forum/...600#post669600

    The script has been tested extensively, but I appreciate it if you report any errors you come across (concerning the coding or the English language).


    Thank you very much!

    Code:
    #!/bin/bash
    
    ################################################################################
    #                                                                              #
    #                                                                              #
    #         $$     $$                                                $$          #
    #         $$     $$  $$$$$$$$$  $$         $$          $$$$$$$     $$          #
    #         $$     $$  $$         $$         $$         $$     $$    $$          #
    #         $$$$$$$$$  $$$$$$$$   $$         $$         $$     $$    $$          #
    #         $$     $$  $$         $$         $$         $$     $$    $$          #
    #         $$     $$  $$         $$         $$         $$     $$                #
    #         $$     $$  $$$$$$$$$  $$$$$$$$$  $$$$$$$$$   $$$$$$$     $$          #
    #                                                                              #
    #                                                                              #
    # This is a little helper script for Kubuntu™ users who want to get rid of     #
    # and block Snap entirely (like Linux Mint and TUXEDO OS do), including the    #
    # Firefox Snap in 22.04 LTS & later and e.g. the Thunderbird and Firmware      #
    # Updater Snaps in 24.04 LTS.                                                  #
    # It has been tested many times with Kubuntu™ 20.04 LTS up to 23.10.           #
    #                                                                              #
    # -> IMPORTANT:                                                                #
    #    This script is best run after a fresh installation of Kubuntu™ but has    #
    #    also been written to be run directly after a release-upgrade to the next  #
    #    main Kubuntu™ version (e.g. from 23.10 to 24.04 LTS).                     #
    #    It should also work with a Kubuntu™ installation that has been used for a #
    #    while - depending on your own system modifications - but BE AWARE THAT    #
    #    ALL PROGRAMS YOU ADDITIONALLY INSTALLED AS SNAPS WILL BE REMOVED TOO!     #
    #    It has been designed to be run in combination with the                    #
    #    "reinstall_Snap_for_release-upgrade" script.                              #
    #                                                                              #
    # -> A full upgrade of the system (either with Discover or in Konsole with     #
    #    "sudo snap refresh && sudo apt update && sudo apt full-upgrade") AND a    #
    #    reboot is strongly recommended prior to running this script.              #
    #                                                                              #
    # You will be asked twice for confirmation before the removal of Snaps and     #
    # snapd is started and/or APT pinning to block future installation of Snap is  #
    # applied - and if you answer "n" or "N" no changes at all are made to your    #
    # system.                                                                      #
    #                                                                              #
    # For some more information about what is done in detail see the comments      #
    # within this script.                                                          #
    #                                                                              #
    # My scripts are in no way associated with Canonical™, Ubuntu™ or Kubuntu™.    #
    # This script comes with ABSOLUTELY NO WARRANTY OF ANY KIND.                   #
    # It may be used, shared, copied and modified freely.                          #
    #                                                                              #
    # You can download my scripts from here: https://gitlab.com/scripts94          #
    #                                                                              #
    # I hope you find the script useful! Yours respectfully, Schwarzer Kater       #
    #                                                                              #
    ################################################################################
    
    versionnr="2.1.0"
    
    ########
    ## During this session let's make sure no "exotic" or interfering aliases can be
    ## used in this script
    ########
    shopt -u expand_aliases
    
    ########
    ## Display purpose of this script
    ########
    clear
    echo -e "########"
    echo -e "## This is a little helper script for Kubuntu™ users who want to get rid of"
    echo -e "## and block Snap entirely (like Linux Mint and TUXEDO OS do), including the"
    echo -e "## Firefox Snap in 22.04 LTS & later and e.g. the Thunderbird and Firmware"
    echo -e "## Updater Snaps in 24.04 LTS."
    echo -e "## It has been tested many times with Kubuntu™ 20.04 LTS up to 23.10."
    echo -e "##"
    echo -e "## -> IMPORTANT:"
    echo -e "##    This script is best run after a fresh installation of Kubuntu™ but has"
    echo -e "##    also been written to be run directly after a release-upgrade to the next"
    echo -e "##    main Kubuntu™ version (e.g. from 23.10 to 24.04 LTS)."
    echo -e "##    It should also work with a Kubuntu™ installation that has been used for a"
    echo -e "##    while - depending on your own system modifications - but BE AWARE THAT"
    echo -e "##    ALL PROGRAMS YOU ADDITIONALLY INSTALLED AS SNAPS WILL BE REMOVED TOO!"
    echo -e "##    It has been designed to be run in combination with the"
    echo -e "##    \"reinstall_Snap_for_release-upgrade\" script."
    echo -e "## -> A full upgrade of the system (either with Discover or in Konsole with"
    echo -e "##    \"sudo snap refresh && sudo apt update && sudo apt full-upgrade\") AND a"
    echo -e "##    reboot is strongly recommended prior to running this script."
    echo -e "##"
    echo -e "## You will be asked twice for confirmation before the removal of Snaps and"
    echo -e "## snapd is started and/or APT pinning to block future installation of Snap is"
    echo -e "## applied - and if you answer \"n\" or \"N\" no changes at all are made to your"
    echo -e "## system."
    echo -e "##"
    echo -e "## For some more information about what is done in detail see the comments"
    echo -e "## within the script itself."
    echo -e "##"
    echo -e "## This script comes with ABSOLUTELY NO WARRANTY OF ANY KIND."
    echo -e "## It may be used, shared, copied and modified freely."
    echo -e "##"
    echo -e "## I hope you find the script useful! Yours respectfully, Schwarzer Kater"
    echo -e "########\n"
    read -p "Press [Enter] to continue, press [Ctrl] [c] to exit. "
    
    ########
    ## Remove the Firefox Snap (and Thunderbird and Firmware Updater Snaps), snapd
    ## and additionally installed Snaps entirely, remove remaining Snap support
    ## libraries/tools, remove remaining Snap directories, block future installation
    ## of Snap by APT pinning (like Linux Mint and TUXEDO OS do), remove the Mozilla
    ## Team PPA placeholder files (if they have been installed by a previous version
    ## of the scripts)
    ########
    rmffsnap=0
    rmtbsnap=0
    rmfusnap=0
    rmsnap=0
    snappin=0
    blocksnap=0
    
    # Test if the operating system is Kubuntu 20.04 or later / Ubuntu 20.04 or
    # later-based with KDE Plasma
    if ! cat /etc/os-release | grep -Ei "(^|\s)VERSION=(|\s|\"|\s\")(20.04|20.10|21.04|21.10|22.04|22.10|23.04|23.10|24.04)" &> /dev/null || ! echo "$XDG_CURRENT_DESKTOP" | grep -i KDE &> /dev/null
    then
        echo -e "\n######################################################################\n## This script is meant to be used with Kubuntu™ 20.04 LTS or later ##\n## -> PROCEED AT YOUR OWN RISK!                                     ##\n######################################################################"
    fi
    
    echo -e "\n########\n## Do you want to REMOVE and BLOCK Snap entirely from Kubuntu™?"
    if command -v snap &> /dev/null && snap list 2> /dev/null | grep -i "^core" &> /dev/null && snap list firefox &> /dev/null
    then
        # Warn about installed Snaps including the Firefox Snap that are to be
        # removed
        if ! snap list thunderbird &> /dev/null && ! snap list firmware-updater &> /dev/null
        then
            echo -e "## (Including the Firefox Snap and all additional Snaps you may have installed.)\n## The following Snaps WILL BE REMOVED (\"bare\", \"core…\", etc. are no actual\n## programs you have installed but just Snap \"support stuff\") :\n########\n" && snap list && echo
        # Warn about installed Snaps including the Firefox and Thunderbird Snaps
        # that are to be removed
        elif snap list thunderbird &> /dev/null && ! snap list firmware-updater &> /dev/null
        then
            echo -e "## (Including the Firefox and Thunderbird Snaps and all additional Snaps you may\n## have installed.)\n## The following Snaps WILL BE REMOVED (\"bare\", \"core…\", etc. are no actual\n## programs you have installed but just Snap \"support stuff\") :\n########\n" && snap list && echo
        # Warn about installed Snaps including the Firefox and Firmware Updater
        # Snaps that are to be removed
        elif ! snap list thunderbird &> /dev/null && snap list firmware-updater &> /dev/null
        then
            echo -e "## (Including the Firefox and Firmware Updater Snaps and all additional Snaps\n## you may have installed.)\n## The following Snaps WILL BE REMOVED (\"bare\", \"core…\", etc. are no actual\n## programs you have installed but just Snap \"support stuff\") :\n########\n" && snap list && echo
        # Warn about installed Snaps including the Firefox, Thunderbird and Firmware
        # Updater Snaps that are to be removed
        elif snap list thunderbird &> /dev/null && snap list firmware-updater &> /dev/null
        then
            echo -e "## (Including the Firefox, Thunderbird and Firmware Updater Snaps and all\n## additional Snaps you may have installed.)\n## The following Snaps WILL BE REMOVED (\"bare\", \"core…\", etc. are no actual\n## programs you have installed but just Snap \"support stuff\") :\n########\n" && snap list && echo
        fi
    elif command -v snap &> /dev/null && snap list 2> /dev/null | grep -i "^core" &> /dev/null && ! snap list firefox &> /dev/null
    then
        # Warn about installed Snaps including the Thunderbird and Firmware Updater
        # Snaps that are to be removed
        if snap list thunderbird &> /dev/null && snap list firmware-updater &> /dev/null
        then
            echo -e "## (Including the Thunderbird and Firmware Updater Snaps and all additional\n## Snaps you may have installed.)\n## The following Snaps WILL BE REMOVED (\"bare\", \"core…\", etc. are no actual\n## programs you have installed but just Snap \"support stuff\") :\n########\n" && snap list && echo
        # Warn about installed Snaps including the Thunderbird Snap that are to be
        # removed
        elif snap list thunderbird &> /dev/null && ! snap list firmware-updater &> /dev/null
        then
            echo -e "## (Including the Thunderbird Snap and all additional Snaps you may have\n## installed.)\n## The following Snaps WILL BE REMOVED (\"bare\", \"core…\", etc. are no actual\n## programs you have installed but just Snap \"support stuff\") :\n########\n" && snap list && echo
        # Warn about installed Snaps including the Firmware Updater Snap that are to
        # be removed
        elif ! snap list thunderbird &> /dev/null && snap list firmware-updater &> /dev/null
        then
            echo -e "## (Including the Firmware Updater Snap and all additional Snaps you may have\n## installed.)\n## The following Snaps WILL BE REMOVED (\"bare\", \"core…\", etc. are no actual\n## programs you have installed but just Snap \"support stuff\") :\n########\n" && snap list && echo
        # Warn about installed Snaps that are to be removed
        elif ! snap list thunderbird &> /dev/null && ! snap list firmware-updater &> /dev/null
        then
            echo -e "## (Including all additional Snaps you may have installed.)\n## The following Snaps WILL BE REMOVED (\"bare\", \"core…\", etc. are no actual\n## programs you have installed but just Snap \"support stuff\") :\n########\n" && snap list && echo
        fi
    # Tell that snapd is to be removed
    elif command -v snap &> /dev/null && ! snap list 2> /dev/null | grep -i "^core" &> /dev/null
    then
        echo -e "## No Snaps seem to be installed, but snapd WILL BE REMOVED.\n########"
    else
        echo -e "########"
    fi
    
    # Give option to cancel
    while true
    do
        read -p "[y/n] " answer
        if [[ "${answer}" = [Yy] ]]
        then
            # Only continue if snapd is installed
            if command -v snap &> /dev/null
            then
                # Ask for confirmation
                echo -e "\n########\n## Are you sure you want to GET RID OF and BLOCK Snap?\n########"
                while true
                do
                    read -p "[y/n] " confirm
                    if [[ "${confirm}" = [Yy] ]]
                    then
                        # Uninstall the Firefox Snap first, if it is installed
                        if snap list firefox &> /dev/null ; then echo -e "\n########\n## -> Removing the Firefox Snap …\n########\n" && sudo snap remove --purge firefox && rmffsnap=1 ; fi
    
                        # Uninstall the Chromium Snap first, if it is installed
                        if snap list chromium &> /dev/null ; then echo -e "\n########\n## -> Removing the Chromium Snap …\n########\n" && sudo snap remove --purge chromium ; fi
    
                        # Uninstall the Thunderbird Snap first, if it is installed
                        if snap list thunderbird &> /dev/null ; then echo -e "\n########\n## -> Removing the Thunderbird Snap …\n########\n" && sudo snap remove --purge thunderbird && rmtbsnap=1 ; fi
    
                        # Uninstall the Element Snap first, if it is installed
                        if snap list element-desktop &> /dev/null ; then echo -e "\n########\n## -> Removing the Element Snap …\n########\n" && sudo snap remove --purge element-desktop ; fi
    
                        # Uninstall the Krita Snap first, if it is installed
                        if snap list krita &> /dev/null ; then echo -e "\n########\n## -> Removing the Krita Snap …\n########\n" && sudo snap remove --purge krita ; fi
    
                        # Uninstall the Firmware Updater Snap first, if it is
                        # installed
                        if snap list firmware-updater &> /dev/null ; then echo -e "\n########\n## -> Removing the Firmware Updater Snap …\n########\n" && sudo snap remove --purge firmware-updater && rmfusnap=1 ; fi
    
                        # Disable Snap daemon and remove snapd and remaining Snaps
                        # entirely
                        echo -e "\n########\n## -> Removing snapd …\n########\n"
                        sudo systemctl disable --now snapd.service
                        sudo apt-get purge -y snapd
    
                        # Uninstall Snap support tools, if they are still installed
                        if dpkg -l squashfs-tools 2> /dev/null | grep "^ii" &> /dev/null ; then echo -e "\n########\n## -> Removing Snap support: squashfs-tools …\n########\n" && sudo apt-get purge -y squashfs-tools ; fi
    
                        # Uninstall Discover support for Snap, if it is still
                        # installed
                        if dpkg -l plasma-discover-backend-snap 2> /dev/null | grep "^ii" &> /dev/null ; then echo -e "\n########\n## -> Removing plasma-discover-backend-snap …\n########\n" && sudo apt-get purge -y plasma-discover-backend-snap ; fi
                        if dpkg -l plasma-discover-snap-backend 2> /dev/null | grep "^ii" &> /dev/null ; then echo -e "\n########\n## -> Removing plasma-discover-snap-backend …\n########\n" && sudo apt-get purge -y plasma-discover-snap-backend ; fi
    
                        # Uninstall Snap support libraries, if they are still
                        # installed
                        if dpkg -l libsnapd-qt1 2> /dev/null | grep "^ii" &> /dev/null ; then echo -e "\n########\n## -> Removing Snap support: libsnapd-qt1 …\n########\n" && sudo apt-get purge -y libsnapd-qt1 ; fi
                        if dpkg -l libsnapd-qt-2-1 2> /dev/null | grep "^ii" &> /dev/null ; then echo -e "\n########\n##  Removing Snap support: libsnapd-qt-2-1 …\n########\n" && sudo apt-get purge -y libsnapd-qt-2-1 ; fi
    
                        # Remove all possible and impossible Snap directories that
                        # may exist
                        echo -e "\n########\n## -> Removing Snap directories …\n########"
                        # Remove snap directory from $HOME, if it exists
                        if test -d "$HOME/snap" ; then sudo rm -rf /home/*/snap ; fi
                        # Remove snap directory from /root, if it exists
                        if sudo test -d "/root/snap" ; then sudo rm -rf /root/snap ; fi
                        # Remove snap directory from /var, if it exists
                        if test -d "/var/snap" ; then sudo rm -rf /var/snap ; fi
                        # Remove snapd directory from /var/cache, if it exists
                        if test -d "/var/cache/snapd" ; then sudo rm -rf /var/cache/snapd ; fi
                        # Additionally remove snap directory from /, if it exists
                        if test -d "/snap" ; then sudo rm -rf /snap ; fi
                        # Additionally remove snapd directory from /var/lib, if it
                        # exists
                        if test -d "/var/lib/snapd" ; then sudo rm -rf /var/lib/snapd ; fi
                        # Additionally remove snapd directory from /usr/lib, if it
                        # exists
                        if test -d "/usr/lib/snapd" ; then sudo rm -rf /usr/lib/snapd ; fi
    
                        # Remove broken symbolic links from
                        # /etc/systemd/system/default.target.wants, if they exist
                        for bsymlink in /etc/systemd/system/default.target.wants/snap-* ; do test -L "${bsymlink}" && sudo rm -f "${bsymlink}" && echo -e "\n########\n## -> Removing broken symbolic link :\n##    ${bsymlink} …\n########" ; done
    
                        # Prevent Snap from being installed again by APT pinning in
                        # /etc/apt/preferences.d like Linux Mint and TUXEDO OS do
                        echo -e "\n########\n## -> Writing the following to /etc/apt/preferences.d/no_snapd.pref :\n########\n"
                        echo -e "# To prevent repository packages from triggering the installation of Snap,\n# this file forbids snapd from being installed by APT.\n\nPackage: snapd\nPin: release a=*\nPin-Priority: -10" | sudo tee /etc/apt/preferences.d/no_snapd.pref
    
                        # Test if the "Mozilla Team PPA" placeholder file from a
                        # previous version of the scripts is in $HOME and remove it
                        if test -f "$HOME/.mtppa-placeholder" ; then rm -f "$HOME/.mtppa-placeholder" ; fi
    
                        # Test if the "prefer Firefox from the Mozilla Team PPA APT
                        # pinning" placeholder file from a previous version of the
                        # scripts is in $HOME and remove it
                        if test -f "$HOME/.mtppa-ffpin-placeholder" ; then  rm -f "$HOME/.mtppa-ffpin-placeholder" ; fi
    
                        # Test if the "Firefox from the Mozilla Team PPA"
                        # placeholder file from a previous version of the scripts is
                        # in $HOME and remove it
                        if test -f "$HOME/.mtff-placeholder" ; then rm -f "$HOME/.mtff-placeholder" ; fi
    
                        rmsnap=1
                        break 2
                    elif [[ "${confirm}" = [Nn] ]]
                    then
                        echo -e "\n########\n## You canceled the removal of Snap -> not changing anything …\n########"
                        break 2
                    fi
                done
            else
                # Give option to block future installation of Snaps
                echo -e "\n########\n## Neither snapd nor Snaps seem to be installed -> not removing anything …"
                echo -e "## Do you want to simply BLOCK the future installation of snapd and Snaps?\n########"
                # Give option to cancel
                while true
                do
                    read -p "[y/n] " askblock
                    if [[ "${askblock}" = [Yy] ]]
                    then
                        # Test if there already is relevant APT pinning in
                        # /etc/apt/preferences.d
                        for snappincount in /etc/apt/preferences.d/* ; do if cat "${snappincount}" 2> /dev/null | grep -Ei "(^|\s)Package:(|\s)snapd($|\s)|(^|\s)Package:(|\s)snapd\*($|\s)" &> /dev/null && cat "${snappincount}" 2> /dev/null | grep -Ei "(^|\s)Pin-Priority:(|\s)-" &> /dev/null ; then snappin=1 ; fi ; done
                        if [[ ${snappin} = 1 ]]
                        then
                            echo -e "\n########\n## The future installation of Snap seems to have already been blocked by APT\n## pinning -> not changing anything …\n########"
                            break 2
                        else
                            # Prevent Snap from being installed again by APT pinning
                            # in /etc/apt/preferences.d like Linux Mint and
                            # TUXEDO OS do
                            echo -e "\n########\n## -> Writing the following to /etc/apt/preferences.d/no_snapd.pref :\n########\n"
                            echo -e "\n# To prevent repository packages from triggering the installation of Snap,\n# this file forbids snapd from being installed by APT.\n\nPackage: snapd\nPin: release a=*\nPin-Priority: -10" | sudo tee /etc/apt/preferences.d/no_snapd.pref
                            blocksnap=1
                            break 2
                        fi
                    elif [[ "${askblock}" = [Nn] ]]
                    then
                        echo -e "\n########\n## You canceled to block the future installation of Snap\n## -> not changing anything …\n########"
                        break 2
                    fi
                done
            fi
        elif [[ "${answer}" = [Nn] ]]
        then
            echo -e "\n########\n## You canceled the removal of Snap -> not changing anything …\n########"
            break
        fi
    done
    
    ########
    ## Report what has been done
    ########
    summary_first="\n########\n## -> SUMMARY:"
    summary_nochanges="## The script has made no changes at all to your system!"
    summary_reboot="## -> It is strongly recommended that you reboot your computer now!"
    summary_last="## Have a nice day and enjoy a snap-free Kubuntu™.\n########\n"
    savesummary=0
    
    if [[ ${rmsnap} = 1 ]] && [[ ${rmffsnap} = 1 ]]
    then
        # Tell that Snap including the Firefox Snap (and Thunderbird and Firmware
        # Updater Snaps) has been removed and recommend system reboot
        echo -e "${summary_first}"
        if [[ ${rmtbsnap} = 0 ]] && [[ ${rmfusnap} = 0 ]]
        then
            echo -e "## Snap including the Firefox Snap has been removed from your system and the\n## future installation of Snap has been blocked by APT pinning in\n## /etc/apt/preferences.d - the file is named \"no_snapd.pref\"."
        elif [[ ${rmtbsnap} = 1 ]] && [[ ${rmfusnap} = 0 ]]
        then
            echo -e "## Snap including the Firefox and Thunderbird Snaps has been removed from your\n## system and the future installation of Snap has been blocked by APT pinning in\n## /etc/apt/preferences.d - the file is named \"no_snapd.pref\"."
        elif [[ ${rmtbsnap} = 0 ]] && [[ ${rmfusnap} = 1 ]]
        then
            echo -e "## Snap including the Firefox and Firmware Updater Snaps has been removed from\n## your system and the future installation of Snap has been blocked by APT\n## pinning in /etc/apt/preferences.d - the file is named \"no_snapd.pref\"."
        elif [[ ${rmtbsnap} = 1 ]] && [[ ${rmfusnap} = 1 ]]
        then
            echo -e "## Snap including the Firefox, Thunderbird and Firmware Updater Snaps has been\n## removed from your system and the future installation of Snap has been blocked\n## by APT pinning in /etc/apt/preferences.d - the file is named \"no_snapd.pref\"."
        fi
        echo -e "## -> Be sure to remove any relevant APT pinning and reinstall Snap BEFORE a"
        echo -e "##    release-upgrade to the next main Kubuntu™ version (e.g. from 23.10 to"
        echo -e "##    24.04 LTS)!"
        echo -e "##    You can do both with the \"reinstall_Snap_for_release-upgrade\" script."
        echo -e "${summary_reboot}"
        echo -e "${summary_last}"
        savesummary=1
    elif [[ ${rmsnap} = 1 ]] && [[ ${rmffsnap} = 0 ]]
    then
        # Tell that Snap (including the Thunderbird and Firmware Updater Snaps) has
        # been removed and recommend system reboot
        echo -e "${summary_first}"
        if [[ ${rmtbsnap} = 1 ]] && [[ ${rmfusnap} = 1 ]]
        then
            echo -e "## Snap including the Thunderbird and Firmware Updater Snaps has been removed\n## from your system and the future installation of Snap has been blocked by APT\n## pinning in /etc/apt/preferences.d - the file is named \"no_snapd.pref\"."
        elif [[ ${rmtbsnap} = 1 ]] && [[ ${rmfusnap} = 0 ]]
        then
            echo -e "## Snap including the Thunderbird Snap has been removed from your system and the\n## future installation of Snap has been blocked by APT pinning in\n## /etc/apt/preferences.d - the file is named \"no_snapd.pref\"."
        elif [[ ${rmtbsnap} = 0 ]] && [[ ${rmfusnap} = 1 ]]
        then
            echo -e "## Snap including the Firmware Updater Snap has been removed from your system\n## and the future installation of Snap has been blocked by APT pinning in\n## /etc/apt/preferences.d - the file is named \"no_snapd.pref\"."
        elif [[ ${rmtbsnap} = 0 ]] && [[ ${rmfusnap} = 0 ]]
        then
            echo -e "## Snap has been removed from your system and the future installation of Snap\n## has been blocked by APT pinning in /etc/apt/preferences.d - the file is named\n## \"no_snapd.pref\"."
        fi
        echo -e "## -> Be sure to remove any relevant APT pinning and reinstall Snap BEFORE a"
        echo -e "##    release-upgrade to the next main Kubuntu™ version (e.g. from 23.10 to"
        echo -e "##    24.04 LTS)!"
        echo -e "##    You can do both with the \"reinstall_Snap_for_release-upgrade\" script."
        echo -e "${summary_reboot}"
        echo -e "${summary_last}"
        savesummary=1
    elif ! command -v snap &> /dev/null && [[ ${blocksnap} = 1 ]]
    then
        # Tell that future installation of Snap has been blocked
        echo -e "${summary_first}"
        echo -e "## The future installation of Snap has been blocked by APT pinning in\n## /etc/apt/preferences.d - the file is named \"no_snapd.pref\"."
        echo -e "## -> Be sure to remove any relevant APT pinning and reinstall Snap BEFORE a"
        echo -e "##    release-upgrade to the next main Kubuntu™ version (e.g. from 23.10 to"
        echo -e "##    24.04 LTS)!"
        echo -e "##    You can do both with the \"reinstall_Snap_for_release-upgrade\" script."
        echo -e "${summary_last}"
        savesummary=1
    elif ! command -v snap &> /dev/null && [[ ${blocksnap} = 0 ]]
    then
        # Tell that nothing has changed
        echo -e "${summary_first}"
        echo -e "${summary_nochanges}"
        echo -e "## -> Be sure to remove any relevant APT pinning and reinstall Snap BEFORE a"
        echo -e "##    release-upgrade to the next main Kubuntu™ version (e.g. from 23.10 to"
        echo -e "##    24.04 LTS)!"
        echo -e "##    You can do both with the \"reinstall_Snap_for_release-upgrade\" script."
        echo -e "${summary_last}"
    else
        # Tell that nothing has changed
        echo -e "${summary_first}"
        echo -e "${summary_nochanges}"
        echo -e "## Have a nice day and enjoy Kubuntu™.\n########\n"
    fi
    
    ########
    ## Give option to save the summary, if the script has changed anything
    ########
    appendix="$(date +"%Y-%m-%d_%H:%M")"
    
    if [[ ${savesummary} = 1 ]]
    then
        echo -e "########\n## -> Do you want to save this summary for future reference?\n########"
        while true
        do
            read -p "[y/n] " wantsave
            if [[ "${wantsave}" = [Yy] ]] && [[ ${rmsnap} = 1 ]] && [[ ${rmffsnap} = 1 ]] && [[ ${blocksnap} = 0 ]]
            then
                # Save to text file that Snap including the Firefox Snap (and
                # Thunderbird and Firmware Updater Snaps) has been removed and
                # system reboot is recommended
                echo -e "${summary_first}" > "$HOME/get_rid_of_Snap-SUMMARY_${appendix}.txt"
                if [[ ${rmtbsnap} = 0 ]] && [[ ${rmfusnap} = 0 ]]
                then
                    echo -e "## Snap including the Firefox Snap has been removed from your system and the\n## future installation of Snap has been blocked by APT pinning in\n## /etc/apt/preferences.d - the file is named \"no_snapd.pref\"." >> "$HOME/get_rid_of_Snap-SUMMARY_${appendix}.txt"
                elif [[ ${rmtbsnap} = 1 ]] && [[ ${rmfusnap} = 0 ]]
                then
                    echo -e "## Snap including the Firefox and Thunderbird Snaps has been removed from your\n## system and the future installation of Snap has been blocked by APT pinning in\n## /etc/apt/preferences.d - the file is named \"no_snapd.pref\"." >> "$HOME/get_rid_of_Snap-SUMMARY_${appendix}.txt"
                elif [[ ${rmtbsnap} = 0 ]] && [[ ${rmfusnap} = 1 ]]
                then
                    echo -e "## Snap including the Firefox and Firmware Updater Snaps has been removed from\n## your system and the future installation of Snap has been blocked by APT\n## pinning in /etc/apt/preferences.d - the file is named \"no_snapd.pref\"." >> "$HOME/get_rid_of_Snap-SUMMARY_${appendix}.txt"
                elif [[ ${rmtbsnap} = 1 ]] && [[ ${rmfusnap} = 1 ]]
                then
                    echo -e "## Snap including the Firefox, Thunderbird and Firmware Updater Snaps has been\n## removed from your system and the future installation of Snap has been blocked\n## by APT pinning in /etc/apt/preferences.d - the file is named \"no_snapd.pref\"." >> "$HOME/get_rid_of_Snap-SUMMARY_${appendix}.txt"
                fi
                echo -e "## -> Be sure to remove any relevant APT pinning and reinstall Snap BEFORE a" >> "$HOME/get_rid_of_Snap-SUMMARY_${appendix}.txt"
                echo -e "##    release-upgrade to the next main Kubuntu™ version (e.g. from 23.10 to" >> "$HOME/get_rid_of_Snap-SUMMARY_${appendix}.txt"
                echo -e "##    24.04 LTS)!" >> "$HOME/get_rid_of_Snap-SUMMARY_${appendix}.txt"
                echo -e "##    You can do both with the \"reinstall_Snap_for_release-upgrade\" script." >> "$HOME/get_rid_of_Snap-SUMMARY_${appendix}.txt"
                echo -e "${summary_reboot}" >> "$HOME/get_rid_of_Snap-SUMMARY_${appendix}.txt"
                echo -e "${summary_last}" >> "$HOME/get_rid_of_Snap-SUMMARY_${appendix}.txt"
                echo -e "Script version used: ${versionnr}" >> "$HOME/get_rid_of_Snap-SUMMARY_${appendix}.txt"
                echo -e "\n########\n## -> The summary of what has been done by this script was saved to:\n##    $HOME/get_rid_of_Snap-SUMMARY_${appendix}\n########\n"
                break
            elif [[ "${wantsave}" = [Yy] ]] && [[ ${rmsnap} = 1 ]] && [[ ${rmffsnap} = 0 ]] && [[ ${blocksnap} = 0 ]]
            then
                # Save to text file that Snap (including the Thunderbird and
                # Firmware Updater Snaps) has been removed and system reboot is
                # recommended
                echo -e "${summary_first}" > "$HOME/get_rid_of_Snap-SUMMARY_${appendix}.txt"
                if [[ ${rmtbsnap} = 1 ]] && [[ ${rmfusnap} = 1 ]]
                then
                    echo -e "## Snap including the Thunderbird and Firmware Updater Snaps has been removed\n## from your system and the future installation of Snap has been blocked by APT\n## pinning in /etc/apt/preferences.d - the file is named \"no_snapd.pref\"." >> "$HOME/get_rid_of_Snap-SUMMARY_${appendix}.txt"
                elif [[ ${rmtbsnap} = 1 ]] && [[ ${rmfusnap} = 0 ]]
                then
                    echo -e "## Snap including the Thunderbird Snap has been removed from your system and the\n## future installation of Snap has been blocked by APT pinning in\n## /etc/apt/preferences.d - the file is named \"no_snapd.pref\"." >> "$HOME/get_rid_of_Snap-SUMMARY_${appendix}.txt"
                elif [[ ${rmtbsnap} = 0 ]] && [[ ${rmfusnap} = 1 ]]
                then
                    echo -e "## Snap including the Firmware Updater Snap has been removed from your system\n## and the future installation of Snap has been blocked by APT pinning in\n## /etc/apt/preferences.d - the file is named \"no_snapd.pref\"." >> "$HOME/get_rid_of_Snap-SUMMARY_${appendix}.txt"
                elif [[ ${rmtbsnap} = 0 ]] && [[ ${rmfusnap} = 0 ]]
                then
                    echo -e "## Snap has been removed from your system and the future installation of Snap\n## has been blocked by APT pinning in /etc/apt/preferences.d - the file is named\n## \"no_snapd.pref\"." >> "$HOME/get_rid_of_Snap-SUMMARY_${appendix}.txt"
                fi
                echo -e "## -> Be sure to remove any relevant APT pinning and reinstall Snap BEFORE a" >> "$HOME/get_rid_of_Snap-SUMMARY_${appendix}.txt"
                echo -e "##    release-upgrade to the next main Kubuntu™ version (e.g. from 23.10 to" >> "$HOME/get_rid_of_Snap-SUMMARY_${appendix}.txt"
                echo -e "##    24.04 LTS)!" >> "$HOME/get_rid_of_Snap-SUMMARY_${appendix}.txt"
                echo -e "##    You can do both with the \"reinstall_Snap_for_release-upgrade\" script." >> "$HOME/get_rid_of_Snap-SUMMARY_${appendix}.txt"
                echo -e "${summary_reboot}" >> "$HOME/get_rid_of_Snap-SUMMARY_${appendix}.txt"
                echo -e "${summary_last}" >> "$HOME/get_rid_of_Snap-SUMMARY_${appendix}.txt"
                echo -e "Script version used: ${versionnr}" >> "$HOME/get_rid_of_Snap-SUMMARY_${appendix}.txt"
                echo -e "\n########\n## -> The summary of what has been done by this script was saved to:\n##    $HOME/get_rid_of_Snap-SUMMARY_${appendix}\n########\n"
                break
            elif [[ "${wantsave}" = [Yy] ]] && [[ ${blocksnap} = 1 ]]
            then
                # Save to text file that future installation of Snap has been blocked
                echo -e "${summary_first}" > "$HOME/get_rid_of_Snap-SUMMARY_${appendix}.txt"
                echo -e "## The future installation of Snap has been blocked by APT pinning in\n## /etc/apt/preferences.d - the file is named \"no_snapd.pref\"." >> "$HOME/get_rid_of_Snap-SUMMARY_${appendix}.txt"
                echo -e "## -> Be sure to remove any relevant APT pinning and reinstall Snap BEFORE a" >> "$HOME/get_rid_of_Snap-SUMMARY_${appendix}.txt"
                echo -e "##    release-upgrade to the next main Kubuntu™ version (e.g. from 23.10 to" >> "$HOME/get_rid_of_Snap-SUMMARY_${appendix}.txt"
                echo -e "##    24.04 LTS)!" >> "$HOME/get_rid_of_Snap-SUMMARY_${appendix}.txt"
                echo -e "##    You can do both with the \"reinstall_Snap_for_release-upgrade\" script." >> "$HOME/get_rid_of_Snap-SUMMARY_${appendix}.txt"
                echo -e "${summary_last}" >> "$HOME/get_rid_of_Snap-SUMMARY_${appendix}.txt"
                echo -e "Script version used: ${versionnr}" >> "$HOME/get_rid_of_Snap-SUMMARY_${appendix}.txt"
                echo -e "\n########\n## -> The summary of what has been done by this script was saved to:\n##    $HOME/get_rid_of_Snap-SUMMARY_${appendix}\n########\n"
                break
            elif [[ "${wantsave}" = [Nn] ]]
            then
                echo
                break
            fi
        done
    fi
    
    ########
    ## Give option to reboot, if this has been recommended
    ########
    if [[ ${rmsnap} = 1 ]]
    then
        echo -e "########\n## -> Do you want to reboot your system now as recommended?\n########"
        while true
        do
            read -p "[y/n] " rebootpc
            if [[ "${rebootpc}" = [Yy] ]]
            then
                reboot
                break
            elif [[ "${rebootpc}" = [Nn] ]]
            then
                echo
                break
            fi
        done
    fi
    Last edited by Schwarzer Kater; Yesterday, 02:07 PM. Reason: update to version 2.1.0
    Debian KDE & LXQt • Kubuntu & Lubuntu • openSUSE KDE • Windows • macOS X
    Desktop: Lenovo ThinkCentre M75s • Laptop: Apple MacBook Pro 13" • and others

    get rid of Snap scriptreinstall Snap for release-upgrade scriptinstall traditional Firefox script

    Comment


      #3
      Thank you very much for your feedback.
      Please feel free to post any ideas for improvement or any bugs you may (hopefully not) encounter.
      Debian KDE & LXQt • Kubuntu & Lubuntu • openSUSE KDE • Windows • macOS X
      Desktop: Lenovo ThinkCentre M75s • Laptop: Apple MacBook Pro 13" • and others

      get rid of Snap scriptreinstall Snap for release-upgrade scriptinstall traditional Firefox script

      Comment


      • GreyGeek
        GreyGeek commented
        Editing a comment
        Sweet!!!!!!!

      #4
      Was this just a chatbot?
      Debian KDE & LXQt • Kubuntu & Lubuntu • openSUSE KDE • Windows • macOS X
      Desktop: Lenovo ThinkCentre M75s • Laptop: Apple MacBook Pro 13" • and others

      get rid of Snap scriptreinstall Snap for release-upgrade scriptinstall traditional Firefox script

      Comment


        #5
        His full email address was registered on Stop Forum Spam, so I deleted the account and the post.
        Using Kubuntu Linux since March 23, 2007
        "It is a capital mistake to theorize before one has data." - Sherlock Holmes

        Comment


          #6
          Which post was made by a chat bot?
          "A nation that is afraid to let its people judge the truth and falsehood in an open market is a nation that is afraid of its people.”
          – John F. Kennedy, February 26, 1962.

          Comment


            #7
            Originally posted by GreyGeek View Post
            Which post was made by a chat bot?
            The one I deleted.
            Using Kubuntu Linux since March 23, 2007
            "It is a capital mistake to theorize before one has data." - Sherlock Holmes

            Comment


              #8
              Sorry, I like responses like that. Funny. I hope everyone else has that same sense of humor.

              Comment


                #9
                During the past days I have tested the script with Kubuntu 23.10 and with upgrades from Kubuntu 22.04 -> 23.04 -> 23.10 both on "bare metal" and in virtual machines.
                Works.
                Debian KDE & LXQt • Kubuntu & Lubuntu • openSUSE KDE • Windows • macOS X
                Desktop: Lenovo ThinkCentre M75s • Laptop: Apple MacBook Pro 13" • and others

                get rid of Snap scriptreinstall Snap for release-upgrade scriptinstall traditional Firefox script

                Comment


                  #10
                  I updated the script - it now does not support the Mozilla Team PPA any longer!

                  This version has been prepared and pretested for Kubuntu 24.04 LTS - I will keep testing it until the official release of 24.04, of course.
                  Debian KDE & LXQt • Kubuntu & Lubuntu • openSUSE KDE • Windows • macOS X
                  Desktop: Lenovo ThinkCentre M75s • Laptop: Apple MacBook Pro 13" • and others

                  get rid of Snap scriptreinstall Snap for release-upgrade scriptinstall traditional Firefox script

                  Comment

                  Working...
                  X