sysclean 1.2.1
A lightweight CLI system cleaner written in Python
Requires Python: >=3.8

# sysclean-sesc191y / system cleaner
**Project** `sesc191y`

**sysclean** is a lightweight CLI program written in Python. This helps user to save time by running post-update and cleaning scripts.

# Installation
**sysclean** can be installed through terminal using `pip`, this requires `Python >= 3.8` and the `pip package manager` 

    pip install sysclean

If it is installed before, it can be upgraded with :

    pip install sysclean --upgrade

As observed in test conducted in Arch Linux, the program does not work due to python path, if it did happen in your system, add the installation path in PATH.

    echo 'export PATH=$HOME/bin:$PATH:~/.local/bin' >> ~/.bashrc
    source ~/.bashrc

If `pip` or `Python` is not installed. You can install it with this command.

**Fedora / RHEL / `.rpm` based systems**

    $ sudo dnf install python3 python-pip

**Arch / Arch-based systems**

    $ sudo pacman -S python python-pip

# Usage

After installing the user can run the program with the terminal command `syscleanup` which will clean the system. The program also supports single cleaning with use of flags, this only works in Fedora / Fedora-based systems. Use `syscleanup--help` to list all of the available flags.

> **NOTE**
> Don't run the program with `[sudo]` command, run it under user previleges only. The program itself will ask for `[sudo]` previliges to execute the command. The program is also case sensitive.

    The script needs [sudo] permission, allow ? [y/N] y
    This is CASE SENSITIVE
    Distro : <Your distro>
    >>> <the program will proceed>
    The script needs [sudo] permission, allow ? [y/N] N (Denied prompt)
    >>> [sudo] Operation not permitted

>**NOTE | Fedora / Fedora-based systems**
The program will first install packages that will help to cleanup the system : [`symlinks`](https://fedora.pkgs.org/33/fedora-aarch64/symlinks-1.7-3.fc33.aarch64.rpm.html), [`dnf-utils`](https://fedora.pkgs.org/33/fedora-updates-aarch64/dnf-utils-4.0.18-1.fc33.noarch.rpm.html) and [`rpmconf`](https://fedora.pkgs.org/33/fedora-x86_64/rpmconf-1.1.1-3.fc33.noarch.rpm.html?), it will also install [`deltarpm`](https://fedora.pkgs.org/33/fedora-aarch64/deltarpm-3.6.2-7.fc33.aarch64.rpm.html) to configure DNF. Every installed packages as well as modification of `/etc/systemd/journald.conf` and `/etc/dnf/dnf.conf` will be echoed to `.sysclean` record file, it also contains distro information (`cat /etc/os-release`).

If the needed packages is already installed :

    Needed packages installed, proceeding to next step.

Else, it will install the packages mentioned above and echo a log to `.sysclean`. 

**syscleanup-b / clean all**

The first command to be issued is `sudo dnf clean all` which in return will output :

    <any number> files removed

**syscleanup-ar / autoremove** 

The program will then execute `sudo dnf autoremove` and the program will prompt for confirmation. The prompt can be rejected, this will return this output :

    Perform autoremove ? [y/N] N (Denied prompt)
    >>> Proceeding to next step

    Perform autoremove ? [y/N] y
    >>> Dependencies resolved.
    >>> Nothing to do.
    >>> Complete!
    >>> Autoremove finished

**syscleanup-d / DNF configuration**

The program will also configure `/etc/dnf/dnf.conf` if allowed by the user, as for the new update the program will make a backup `.backup.dnf.conf`, but if the dnf is already configured, the program will proceed to next step without any output.

If the DNF is not configured, the program will ask to configure DNF :

    Configure DNF ? [y/N] N (Denied prompt)
    >>> Proceeding to next step

    Configure DNF ? [y/N] y
    >>> max_parallel_downloads=20
    >>> fastestmirror=true
    Install deltarpm ? [y/N] y
    >>> deltarpm=true
    >>> DNF is now configured

    Install deltarpm ? [y/N] N (Denied prompt)
    >>> Proceeding to next step
    >>> DNF is now configured

**syscleanup-cj / journals, cache, orphans and leaves, journald.conf configuration**

**Journals and .cache**
The program will ask for confirmation before the removal of broken symlinks, orphans, log files and cache. It will also configure `/etc/systemd/journald.conf`, before it configure the config file, it will make a backup, `.backup.journald.conf`.

    remove cache and journals [y/N] N (Denied prompt)
    >>> Proceeding to next step

    remove cache and journals [y/N] y
    >>> Vacuuming done, freed 0B of archived journals from /var/log/journal/2d2846c17513414b82b7dafc07fd9051.
    >>> Vacuuming done, freed 0B of archived journals from /run/log/journal.
    >>> Vacuuming done, freed 0B of archived journals from /var/log/journal.
    >>> 0 files removed
    Configured journald ? [y/N] y
    >>> ...
    >>> SystemMaxUse=100M

    Configured journald ? [y/N] N (Denied prompt)
    >>> Proceeding to next step

**symlinks and .rpmsave files**

Symlinks and .rpmsave files, the program will install `symlink` and `rpmconf` package and then will list the broken or dangling symlinks in `/usr`. The program will allow the user to review the listed symlinks and then prompt for confirmation if the symlink will be removed or not, as well for the `.rpmsave` files

_**syscleanup-Fs / symlinks**_

    Remove broken symlinks and .rpmsave [y/N] N (Denied Prompt)
    >>> Proceeding to next step

    Remove broken symlinks and .rpmsave [y/N] y
    >>> dangling: /usr/lib/.build-id/20/719c4c3c5419a32efa15e7cb7125fed4a0b73f -> ../../../../usr/lib64/lv2/eg-sampler.lv2/sampler.so
    >>> angling: /usr/lib/.build-id/26/9e62f3991868a2238ac2c85972a3d8b32c70a4 -> ../../../../usr/lib64/lv2/eg-amp.lv2/amp.so
    >>> dangling: /usr/lib/.build-id/a1/fa8efa0d4a4b90af5b503e7301470e352b10bc -> ../../../../usr/lib64/lv2/eg-fifths.lv2/fifths.so
    >>> dangling: /usr/lib/.build-id/a2/6330bc6f8a15bde25360af86fc3f7ae82808c7 -> ../../../../usr/lib64/lv2/eg-midigate.lv2/midigate.so
    >>> dangling: /usr/lib/.build-id/a2/fdfe616fbd6bc7c8764d5bf1ccd86eb4182c2d -> ../../../../usr/lib64/mariadb/plugin/ha_tokudb.so
    >>> dangling: /usr/lib/.build-id/c3/aa44389b28af2518175ca14e85315cba18ceea -> ../../../../usr/lib64/lv2/eg-metro.lv2/metro.so

    Remove the listed symlinks ? [y/N] y
    >>> absolute: /usr/libexec/tracker3/endpoint -> /usr/bin/tracker3
    >>> absolute: /usr/libexec/tracker3/export -> /usr/bin/tracker3
    >>> absolute: /usr/libexec/tracker3/help -> /usr/bin/tracker3
    >>> absolute: /usr/libexec/tracker3/import -> /usr/bin/tracker3
    >>> absolute: /usr/libexec/tracker3/sparql -> /usr/bin/tracker3
    >>> absolute: /usr/libexec/tracker3/sql -> /usr/bin/tracker3

    Remove the listed symlinks ? [y/N] N (Denied Prompt)
    >>> Proceeding to next step

_**syscleanup-Fr / .rpmsave files*_

    !!!Confirmation!!! Remove .rpmsave files ? [y/N] N (Denied Prompt)
    >>> Proceeding to next step

    !!!Confirmation!!! Remove .rpmsave files ? [y/N] y
    >>> <This outputs nothing>

**sysclean-Fo / Orphans and leave packages**

For this part, the program will install `dnf-utils` packages.

    remove orphans ? [y/N] y
    >>> This will install dnf-utils package, if it is already installed, it will output nothing.
    >>> Else : it will install dnf-utils package, and echo it to .sysclean records

    Remove orphans ? [y/N] N (Denied Prompt)
    >>> <End of program>
    >>> The terminal will be cleared and the program will print 'system cleaned'.

And after the installation, the program will remove orphans and leave packages without any prompt. This is also the end of program, it will issue `clear` command in terminal and print

    system cleaned

**Arch / Arch-based systems**

The program will start by cleaning `.cache` folder. It will print the size of `~/.cache` and remove it if the prompt is  accepted by the user.

    212K    /home/test.cache
    Remove .cache files ? [y/N] y
    >>> This returns no output

    Remove .cache files ? [y/N] N (Denied Prompt)
    >>> Proceeding to next step

It will also remove `pacman` cache.

    Remove pacman cache ? [y/N] y
    >>> Cache directory: /var/cache/pacman/pkg/
    >>> :: Do you want to remove ALL files from cache? [y/N] y
    >>>>>> removing all files from cache...

    >>> :: Do you want to remove ALL files from cache? [y/N] N (Denied prompt)
    >>>>>> <Returns none>

    >>> Database directory: /var/lib/pacman/
    >>> Do you want to remove unused repositories? [Y/n] Y
    >>>>>> :: removing unused sync repositories

    >>> Do you want to remove unused repositories? [Y/n] n (Denied prompt)
    >>>>>> :: <Returns none>

    Remove pacman cache ? [y/N] N (Denied prompt)
    >>> Proceeding to next step 

It will also removed cache and journals, it will optimize `/etc/systemd/journald.conf` as well. The same process will be made in Arch, it will make `.backup.journald.conf` in the directory of execution. If `/etc/systemd/journald.conf` if already configured, the program will skip it, but if it is not yet configured the program will prompt a request.

    remove cache and journals ? [y/N] N (Denied prompt)
    >>> Proceeding to next step.
    remove cache and journals ? [y/N] y
    >>> Vacuuming done, freed 0B of archived journals from /run/log/journal.
    >>> Deleted archived journal /var/log/journal/5b8b711dd9fd4d709976d6d1f141add3/system@0005be07a9f86d09-19193e071f825729~ (8.0M).
    >>> Vacuuming done, freed 16.0M of archived journals from /var/log/journal/5b8b711dd9fd4d709976d6d1f141add3.
    >>> Vacuuming done, freed 0B of archived journals from /var/log/journal.
    Configured journald ? [y/N] y
    >>> ...
    >>> SystemMaxUse=100M
    Configured journald ? [y/N] N (Denied prompt)
    >>> Proceeding to next step

It will removed orphans as well :

    Remove orphans ? [y/N] y
    >>> <This ends the program> by issuing 'clear' and printing 'system cleaned'.
    Remove orphans ? [y/N] N
    >>> <This ends the program> by issuing 'clear' and printing 'system cleaned'.

**Known ISSUES/ERROS**

--

# Read
The program is tested and used in Fedora 33 Linux and Arch Linux, and will be developed for other Linux such as Debian systems / Debian-based systems / Ubuntu-based systems.


**PyPI official link**

https://pypi.org/project/sysclean/

**Development version**

**PyPI Link**

https://pypi.org/project/sysclean-devel/

**GitHub**

https://github.com/jamesaaron97248/sysclean-sesc191y/tree/devel-version