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
Download the file.
Make it executable with the command.
chmod +x mysystemhealth
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
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 ).
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.
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.
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.
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
Regarding kernel removal, the latest kernel must be running. I only keep the latest kernel & the rescue kernel based on the latest. If you are keeping 2 kernels, then you need to initialize KERNEL_LIMIT=3
I have been running this daily.
Enjoy!!
Removes old kernels
# Check if the number of installed kernels, including rescue is > KERNEL_LIMIT
KERNEL_LIMIT=2
NUM_KERNELS=`find /boot/vmlinuz-* | wc -l`
echo "Kernel limit: $KERNEL_LIMIT | Number of installed Kernels, including rescue: $NUM_KERNELS"
if [ "$NUM_KERNELS" -gt "$KERNEL_LIMIT" ]; then
# Remove if the latest version of installed kernels is running
HIGHEST_KERNEL=`find /boot/vmlinuz-* | sort -V | tail -n 1 | sed 's|.*vmlinuz-||'`
RUNNING_KERNEL=`uname -r`
echo "Highest Kernel: $HIGHEST_KERNEL | Running Kernel: $RUNNING_KERNEL"
if [ "$HIGHEST_KERNEL" == "$RUNNING_KERNEL" ]; then
dnf remove $(dnf repoquery --installonly --latest-limit=-1 -q) -y;
echo
echo "##############################"
echo "Finished removing old kernels"
echo "##############################"
echo
sleep 1
# Recreate/Align rescue kernel with the currently running
echo "Aligning rescue kernel with the currently running..."
rm -f /boot/*-rescue-*;
kernel-install add $(uname -r) /lib/modules/$(uname -r)/vmlinuz;
echo
echo "###########################################################"
echo "Finished aligning rescue kernel with the currently running"
echo "###########################################################"
echo
sleep 1
else
echo ""
echo "Latest version of the installed kernels is not running."
echo "** Reboot Required **"
echo "Now I will just exit..." 1>&2
echo ""
sleep 2
exit 1
fi
else
echo "Kernel maintenance is not required..."
fi