frenchmaid

Submitted scripts and programs
Forum rules
Your own work only.
User avatar
GekkoP
Emacs Sancho Panza
Posts: 5878
Joined: Tue Sep 03, 2013 7:05 am

frenchmaid

Unread post by GekkoP » Tue Jan 07, 2014 6:12 pm

Since I got a Debian sid with cwm and absolutely no GTK/Qt/Gir1/etc dependencies on my old Aspire 1304XC, I needed something to keep my system clean. I usually go with bleachbit, but this time I wrote a small script that could help me with the cleaning without forcing me to install funny GUI things. I named it frenchmaid, just to be politically correct, believe you me.

I stole the emacs cleanings from DebianJoe (so, thank you DJ).
At first I thought it would be better to run it as root, but since I always launch bleachbit with sudo I tried to do something similar here. Obviously better ways to do what I had in mind, but as for printfile: it works for me, do whatever you want with it.
I don't know, a better version of this could become 'bbqmaid'? :)

Code: Select all

#!/bin/bash

clean_pkg()
{
    echo "
Cleaning packages..."
    sudo apt-get clean > /dev/null 2>&1
    sudo apt-get autoclean > /dev/null 2>&1
    sudo apt-get autoremove > /dev/null 2>&1
}

clean_cache()
{
    echo "
Cleaning cache..."
    sudo rm -rf /var/cache/apt/archives/*
    sudo rm -rf /var/cache/apt-listbugs/*
}

clean_logs()
{
    echo "
Cleaning logs..."
    sudo rm -rf /var/log/Xorg.0.log.*
    sudo rm -rf /var/log/dmesg.*
    sudo rm -rf /var/log/cups/*
}

clean_emacsbak()
{
    echo "
Cleaning emacs backups..."
    backs=$(find ~/ -name "*~" -print0 | xargs -0)
    dotbacks=$(find ~/ -name ".*~" -print0 | xargs -0)
    sharpbacks=$(find ~/ -name "#*#" -print0 | xargs -0)

    if [ -n "$backs" ]; then
	find ~/ -name "*~" -exec rm -i {} \;
    fi;

    if [ -n "$dotbacks" ]; then
	find ~/ -name ".*~" -exec rm -i {} \;
    fi;

    if [ -n "$sharpbacks" ]; then
	find ~/ -name "#*#" -exec rm -i {} \;
    fi;
}

echo "
###########################################
# frenchmaid                              #
# Script for cleaning the system          #
# Use -y to run all the cleanings at once #
###########################################"

sudo -v # gets user password for next sudos

if [ "$1" == "-y" ]; then
    clean_pkg
    clean_cache
    clean_logs
    clean_emacsbak
else
    read -n1 -p '
Clean packages? (y/n) '
    if [ $REPLY = 'y' ]; then
	clean_pkg
    fi

    read -n1 -p '
Clean cache? (y/n) '
    if [ $REPLY = 'y' ]; then
	clean_cache
    fi

    read -n1 -p '
Clean logs? (y/n) '
    if [ $REPLY = 'y' ]; then
	clean_logs
    fi

    read -n1 -p '
Clean emacs backups? (y/n) '
    if [ $REPLY = 'y' ]; then
	clean_emacsbak
    fi
fi
echo "
System cleaned
"
And a random scrot to show it at work.
Image
Last edited by GekkoP on Thu Jan 09, 2014 9:07 pm, edited 1 time in total.

User avatar
wuxmedia
Grasshopper
Posts: 6454
Joined: Wed Oct 17, 2012 11:32 am
Location: Back in Blighty
Contact:

Re: frenchmaid

Unread post by wuxmedia » Tue Jan 07, 2014 9:10 pm

sexy :)
"Seek, and Ye shall find"
"Github | Chooons | Site"

User avatar
rhowaldt
Dog
Posts: 4565
Joined: Wed Oct 17, 2012 9:01 am
Contact:

Re: frenchmaid

Unread post by rhowaldt » Tue Jan 07, 2014 11:31 pm

nice work Gekko. consider adding commandline parameters to skip the questionnaire?
All statements are true in some sense, false in some sense, meaningless in some sense, true and false in some sense, true and meaningless in some sense, false and meaningless in some sense, and true and false and meaningless in some sense.

User avatar
dkeg
Configurator
Posts: 3782
Joined: Sun Nov 18, 2012 9:23 pm
Location: Mid-Atlantic Grill

Re: frenchmaid

Unread post by dkeg » Wed Jan 08, 2014 2:09 am

great contribution GP!

Work hard; Complain less

User avatar
DebianJoe
Frame Buffer
Posts: 1915
Joined: Mon Jul 01, 2013 5:41 am
Location: emacs.d

Re: frenchmaid

Unread post by DebianJoe » Wed Jan 08, 2014 6:52 am

While there are a few ways to deal with root uid in a script, I actually like "in-line sudo" if you're using sudo on the system. Cool script. I'm sure that there's 900 ways to make it "better," but if it does what you want it to do then I'd call it done. "sharpbacks" is possibly the greatest variable name ever.
|>>BBQ Roaster, Alpha Branch<< | >> clinky << | >> X11 must die << |
Thanks BASIC

User avatar
GekkoP
Emacs Sancho Panza
Posts: 5878
Joined: Tue Sep 03, 2013 7:05 am

Re: frenchmaid

Unread post by GekkoP » Wed Jan 08, 2014 7:48 am

Thanks guys.
Nice suggestion about parameters, might work on that.

User avatar
GekkoP
Emacs Sancho Panza
Posts: 5878
Joined: Tue Sep 03, 2013 7:05 am

Re: frenchmaid

Unread post by GekkoP » Thu Jan 09, 2014 9:07 pm

Slightly fixed it with a -y option.

machinebacon
Baconator
Posts: 10253
Joined: Thu Sep 16, 2010 11:03 am
Location: Pfälzerwald
Contact:

Re: frenchmaid

Unread post by machinebacon » Fri Jan 24, 2014 11:14 am

Is added in newest release ;)

Thanks for the contribution!
..gnutella..

User avatar
GekkoP
Emacs Sancho Panza
Posts: 5878
Joined: Tue Sep 03, 2013 7:05 am

Re: frenchmaid

Unread post by GekkoP » Fri Jan 24, 2014 2:42 pm

Thanks to you for using it. I'm very glad to help.

User avatar
GekkoP
Emacs Sancho Panza
Posts: 5878
Joined: Tue Sep 03, 2013 7:05 am

Re: frenchmaid

Unread post by GekkoP » Fri Apr 24, 2015 3:34 pm

I "took" Pidsley's idea from his great multi-sysup, and applied it to my frenchmaid. Yes, I want my maid to be pretty and colorful.
So Thanks Pidsley for the input.

Code: Select all

#!/bin/bash

red="\e[31m"
grn="\e[32m"
cyn="\e[36m"
rst="\e[0m"    # reset
all=""

yna() {
    while true; do
        read -n1 -p "$1? (y/n/a) "
        echo
        case $REPLY in
            [aA] )
                echo -e $red'abort'$rst
                exit 1;;
            [yY] )
                return 0;;
            [nN] )
                return 1;;
            * )
                echo -e $red'please answer y/n/a'$rst;;
        esac
    done
}

announce() {
    echo -e $grn"cleaning $1"$rst
}

dostep() {
    step=$1
    cmd=$2
    echo
    echo -e $grn"step $step: $cyn$cmd$rst"
    if [[ $all == "" ]] ; then
        if yna "run $cmd"; then
            echo -e $cyn"running $cmd$rst"
            echo
            sudo $cmd
        fi
    else
        echo -e $cyn"running $cmd$rst"
        echo
        sudo $cmd
    fi
}

clean_pkg() {
    dostep 1 "apt-get -y -q clean"
    dostep 2 "apt-get -y -q autoclean"
    dostep 3 "apt-get -y -q autoremove"
}

clean_cache() {
    dostep 1 "rm -rf /var/cache/apt/archives/*"
    dostep 2 "rm -rf /var/cache/apt-listbugs/*"
}

clean_tmp() {
    dostep 1 "rm -rf ~/tmp/*"
}

clean_logs() {
    dostep 1 "rm -rf /var/log/Xorg.0.log.*"
    dostep 2 "rm -rf /var/log/dmesg.*"
    dostep 3 "rm -rf /var/log/cups/*"
    dostep 4 "rm -rf /var/log/upstart/*"
    dostep 5 "rm -rf /var/log/kern.*"
    dostep 6 "rm -rf /var/log/pm-*"
    dostep 7 "rm -rf /var/log/dpkg.*"
}

if [ "$1" == "-y" ]; then
    all="-y"
fi

announce PACKAGES
clean_pkg
announce CACHE
clean_cache
announce TMP
clean_tmp
announce LOGS
clean_logs

echo -e $grn"system cleaned"$rst
https://github.com/manuel-uberti/script ... frenchmaid

pidsley
Hermit
Posts: 2539
Joined: Wed Oct 17, 2012 12:31 pm

Re: frenchmaid

Unread post by pidsley » Mon Apr 27, 2015 8:20 pm

Very nice GekkoP.

I need to come up with better names for my scripts -- "frenchmaid" sounds so much better than "multi-sysup" :)

User avatar
GekkoP
Emacs Sancho Panza
Posts: 5878
Joined: Tue Sep 03, 2013 7:05 am

Re: frenchmaid

Unread post by GekkoP » Mon Apr 27, 2015 8:37 pm

Thank you. Well, frenchmaid is a subtle homage to everyone's not-so-secret erotic dream, of course.

Post Reply