Page 1 of 1

frenchmaid

Posted: Tue Jan 07, 2014 6:12 pm
by GekkoP
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

Re: frenchmaid

Posted: Tue Jan 07, 2014 9:10 pm
by wuxmedia
sexy :)

Re: frenchmaid

Posted: Tue Jan 07, 2014 11:31 pm
by rhowaldt
nice work Gekko. consider adding commandline parameters to skip the questionnaire?

Re: frenchmaid

Posted: Wed Jan 08, 2014 2:09 am
by dkeg
great contribution GP!

Re: frenchmaid

Posted: Wed Jan 08, 2014 6:52 am
by DebianJoe
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.

Re: frenchmaid

Posted: Wed Jan 08, 2014 7:48 am
by GekkoP
Thanks guys.
Nice suggestion about parameters, might work on that.

Re: frenchmaid

Posted: Thu Jan 09, 2014 9:07 pm
by GekkoP
Slightly fixed it with a -y option.

Re: frenchmaid

Posted: Fri Jan 24, 2014 11:14 am
by machinebacon
Is added in newest release ;)

Thanks for the contribution!

Re: frenchmaid

Posted: Fri Jan 24, 2014 2:42 pm
by GekkoP
Thanks to you for using it. I'm very glad to help.

Re: frenchmaid

Posted: Fri Apr 24, 2015 3:34 pm
by GekkoP
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

Re: frenchmaid

Posted: Mon Apr 27, 2015 8:20 pm
by pidsley
Very nice GekkoP.

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

Re: frenchmaid

Posted: Mon Apr 27, 2015 8:37 pm
by GekkoP
Thank you. Well, frenchmaid is a subtle homage to everyone's not-so-secret erotic dream, of course.