You are not logged in.

#1 2024-09-21 11:16:16

Light InAugust
Member
Registered: 2024-02-10
Posts: 21

I need a second opinion on this script I wrote. Can anyone help?

#!/bin/bash

# Clear the package cache

echo "Clearing package cache..."

sudo pacman -Scc --noconfirm

# Check for and remove unused orphaned packages

orphans=$(pacman -Qtdq)

if [ -n "$orphans" ]; then

echo "Removing unused dependencies..."

sudo pacman -Rns $orphans

else

echo "No orphaned packages to remove."

fi

# Clear the user's cache directory

echo "Clearing user cache..."

rm -rf ~/.cache/*

# Run rmlint to find and flag unnecessary files

echo "Running rmlint..."

rmlint /home/***

# Execute the script generated by rmlint

if [ -f "/home/***/rmlint.sh" ]; then

echo "Executing rmlint.sh to remove flagged files..."

sh /home/***/rmlint.sh -d

else

echo "rmlint.sh not found. Skipping file removal."

fi

# delete rmlint.json

rm /home/***/rmlint.json

# Vacuum the system journal to limit its size

echo "Vacuuming system journal to 50M..."

sudo journalctl --vacuum-size=50M

# Delete trash

rm -rf ./.local/share/Trash/*

echo "? System cleanup completed! ?"

Last edited by Light InAugust (2024-09-21 16:58:47)

Offline

#2 2024-09-21 13:51:51

seth
Member
From: Won't reply 2 private help req
Registered: 2012-09-03
Posts: 75,807

Re: I need a second opinion on this script I wrote. Can anyone help?

1. less newlines, more indentation
2. What *exactly* does this do? (don't tell me, tell yourself)

rm -rf ./.local/share/Trash/*

3. Ewww.

sudo pacman -Rns $orphans

I'd not.
* I'd read the orphans into an array
* I'd do this as very first thing and fork it (because it's slow) and then "man wait" for the job before
* stepping through the package, read whether you want to [k]eep|[d]elete|[i]nspect it
  - last one posting

pacman --color=always -Qi $orphan | less -rF

and ask again)
* generally fork off fire-and-forget jobs and collect the sudo calls to re-use the credentials
* Do you want to explicitly sh this? No bashism?
   

sh /home/smurfette/rmlint.sh -d

Edit: though it's not really a security issue

Last edited by seth (2024-09-21 22:22:25)

Offline

#3 2024-09-21 22:07:24

Light InAugust
Member
Registered: 2024-02-10
Posts: 21

Re: I need a second opinion on this script I wrote. Can anyone help?

Always a pleasure seeing your posts, Seth! Much obliged, Sir, for the excellent feedback.

I just realized that having my username out there on the Internet is not exactly best security practice, so could you please blot it out in your reply?

Also, will try to rewrirte my script again, as per your sensible indications.

Offline

Board footer

Powered by FluxBB