mySystemHealth update script

Hello friends,

I made a script. It is a tool designed to ensure the optimal performance and security of my system. This script automates the process of updating my system by executing a series of essential tasks. It refreshes the package list, downloads, and installs available updates, and efficiently removes outdated packages and obsolete configuration files.

Can you please check it out and let me know what you think?
Thanks in advance.

The address is

Usage

  1. Download the file.
  2. Make it executable with the command.
chmod +x mysystemhealth
  1. You can run it using the command
sudo ./mysystemhealth

You can also put it to /usr/bin and run it as a command.

PS: If it is not the right discussion category, can you please move it to the right one? Thanks

Following command can be dangerous as it can remove packages that should not be removed.

    ## Removes unneeded packages
    sudo dnf autoremove -y;
    echo
    echo "###################################"
    echo "Finished removing unneeded packages"
    echo "###################################"
    sleep 1
    echo

If you ever run dnf autoremove, please verify that it does not remove too much.

3 Likes

If you remove -y you have some chances to interfere if needed. Otherwise it will brake your system as soon it removes a dependency where you really need for your system (as @vekruse already mentioned ).

A few changes I would make

  1. Make sure the user is NOT root before using rather forcing the user to be root. Most commands in the script use sudo regardless so it is not needed.
  2. The reaaon the first point is needed is because flatpaks are not meant to be updated in root. So it might be a good idea to remove the sudo from the flatpak commands. If you don’t have to use root for something, it’s probably better to not use root for said thing.
  3. As others have mentioned, appending ā€˜-y’ to the autoremove command can be dangerous. I’m not sure what else you could to keep the functionality without requiring user input though.

A few notes:

  • You probably don’t need the dnf check-update since dnf upgrade automatically updates the metadata.
  • As mentioned earlier, dnf autoremove shouldn’t be run unsupervised, dnf already removes unused dependencies while removing a package.
  • Removing old kernels is not a good idea since they are useful to have as a backup in case the latest kernel has issues.

Thank you all for the input. Will make the changes ASAP.

Consider using dnf update --refresh to force the latest meta data to be used.

A bit off topic, but updating your system should be something that happens automatically, we have dnf-automatic for that.

This may be a problem.

    ## Removes old kernels
    dnf --setopt=protected_packages= remove -y $(rpm -q kernel-core | grep -v $(uname -r));
    echo
    echo "###################################"
    echo "Finished removing old kernels"
    echo "###################################"
    sleep 1
    echo

It seems like it would remove all kernels except the one actually running at that point and overrides the dnf config of installonly_limit=3 which is the default.

I just did a test of that and it would actually remove every kernel installed except the one actually running at that time, including the newer one just installed by doing a ā€œdnf upgradeā€. That part seems very dangerous to me and probably should not be included.

It also would remove (on my system) all these ā€˜unused dependencies’ – many of which are required.

 VirtualBox-kmodsrc                                 noarch           7.0.10-1.fc38                               @rpmfusion-free-updates                      906 k
 fakeroot                                           x86_64           1.31-1.fc38                                 @fedora                                      158 k
 fakeroot-libs                                      x86_64           1.31-1.fc38                                 @fedora                                      134 k
 http-parser                                        x86_64           2.9.4-8.fc38                                @fedora                                      100 k
 kernel-devel-matched                               x86_64           6.4.7-200.fc38                              @System                                        0  
 kmodtool                                           noarch           1.1-7.fc38                                  @fedora                                       28 k
 koji                                               noarch           1.33.0-1.fc38                               @updates                                     816 k
 libgit2                                            x86_64           1.6.4-1.fc38                                @updates                                     1.2 M
 python3-babel                                      noarch           2.11.0-2.fc38                               @fedora                                       29 M
 python3-decorator                                  noarch           5.1.1-5.fc38                                @fedora                                       83 k
 python3-gssapi                                     x86_64           1.7.3-4.fc38                                @fedora                                      2.3 M
 python3-koji                                       noarch           1.33.0-1.fc38                               @updates                                     2.2 M
 python3-progressbar2                               noarch           3.53.2-7.fc38                               @fedora                                      269 k
 python3-pygit2                                     x86_64           1.12.2-1.fc38                               @updates                                     1.1 M
 python3-pytz                                       noarch           2023.3-1.fc38                               @fedora                                      234 k
 python3-requests-gssapi                            noarch           1.2.3-7.fc38                                @fedora                                       63 k
 python3-rpmautospec                                noarch           0.3.5-1.fc38                                @fedora                                      143 k
 python3-utils                                      noarch           3.3.3-2.fc38                                @fedora                                      144 k
 rpmdevtools                                        noarch           9.6-3.fc38                                  @fedora                                      214 k
 xorg-x11-drv-nvidia-kmodsrc                        x86_64           3:535.86.05-1.fc38                          @rpmfusion-nonfree-updates-testing            47 M