Skip to content

Commit

Permalink
reports the total amount of space recovered after the clean operation
Browse files Browse the repository at this point in the history
  • Loading branch information
graysky2 committed Nov 30, 2012
1 parent 448280f commit a939f33
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 33 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG
@@ -1,3 +1,7 @@
v1.83
30-Nov-2012
Now reports a total amount of space recovered.

v1.82
29-Nov-2012
Streamlined code and added support for midori.
Expand Down
6 changes: 3 additions & 3 deletions README-for_other_distros
Expand Up @@ -39,8 +39,6 @@ Size before: 154.17 Mbytes

Size after: 99.11 Mbytes

Recovered: 55.06 Mbytes


$ profile-cleaner f
/home/facade/.mozilla/firefox/zee52krz.default/cookies.sqlite reduced by .87 Mbytes
Expand All @@ -58,6 +56,8 @@ Recovered: 55.06 Mbytes
/home/facade/.mozilla/firefox/zee52krz.default/search.sqlite reduced by 0 Mbytes
/home/facade/.mozilla/firefox/zee52krz.default/places.sqlite reduced by 9.98 Mbytes

firefox profile reduced by 55.06 Mbytes

CONTRIBUTE
Should you wish to contribute to this code, please fork and send a pull request. Source is freely available on github: https://github.com/graysky2/profile-cleaner

Expand All @@ -68,4 +68,4 @@ AUTHOR
graysky (graysky AT archlinux DOT us)

SEE ALSO
profile-sync-deamon (8)
profile-sync-deamon (1)
3 changes: 2 additions & 1 deletion README.md
Expand Up @@ -14,7 +14,6 @@ AUR Link: https://aur.archlinux.org/packages/profile-cleaner

Size before: 154.17 Mbytes
Size after: 99.11 Mbytes
Recovered: 55.06 Mbytes

$ profile-cleaner f

Expand All @@ -33,6 +32,8 @@ AUR Link: https://aur.archlinux.org/packages/profile-cleaner
/home/facade/.mozilla/firefox/zee52krz.default/search.sqlite reduced by 0 Mbytes
/home/facade/.mozilla/firefox/zee52krz.default/places.sqlite reduced by 9.98 Mbytes

firefox profile reduced by 55.06 Mbytes

## Speed Comparison
28-Nov-2012 Profile-cleaner has been rewritten to use GNU Parallel for processing.

Expand Down
78 changes: 53 additions & 25 deletions profile-cleaner
@@ -1,13 +1,15 @@
#!/bin/bash

VERS="1.82"
VERS="1.83"

if [[ -z $(which parallel) ]]; then
echo "GNU Parallel is now a requirement of this script."
echo "Please install it and try again."
exit 1
fi

[[ -f /tmp/accounting.db ]] && rm -f /tmp/accounting.db

echo -en "\E[31mprofile-cleaner v$VERS"
tput sgr0
echo
Expand All @@ -20,12 +22,16 @@ do_clean() {
asize=$(ls -l "$1" | awk {'print $5'})
dsize=$(echo "scale=2; ($bsize-$asize)/1048576" | bc)
echo "$1" reduced by $dsize Mbytes
echo "$name,$dsize" >> /tmp/accounting.db
}

do_chromebased() {
[[ -h "$prepath" ]] && profilepath=$(readlink $prepath) || profilepath="$prepath"
[[ ! -d "$profilepath" ]] && echo "Error: no profile directory found." && exit 1
find ${profilepath} -maxdepth 2 -type f -name 'Histor*' -o -name 'Archiv*' -o -name 'Safe*' | SHELL=/bin/bash parallel do_clean 2>/dev/null
[[ ! -d "$profilepath" ]] && echo "Error: no profile directory for $name found." && exit 1
find "$profilepath" -maxdepth 2 -type f -name 'Histor*' -o -name 'Archiv*' -o -name 'Safe*' | SHELL=/bin/bash parallel do_clean 2>/dev/null
echo
echo "$name profile reduced by $(grep $name /tmp/accounting.db | gawk -F, '{ print $2 }' | paste -sd+ - | bc) Mbytes"
[[ -f /tmp/accounting.db ]] && rm -f /tmp/accounting.db
}

do_xulbased() {
Expand All @@ -35,12 +41,15 @@ do_xulbased() {
profilepath="$prepath"
fi

[[ "$name" = "aurora" ]] && name="heftig aurora"

if [[ ! -d "$profilepath" ]]; then
echo "Error: cannot locate $profilepath"
echo "This is the default path for $name and where $0 expects to find it."
exit 1
fi

[[ ! -f $profilepath/profiles.ini ]] && echo "Error: cannot locate $profilepath/profiles.ini to determine names of profiles." && exit 1
[[ ! -f $profilepath/profiles.ini ]] && echo "Error: cannot locate $profilepath/profiles.ini to determine names of profiles for $name." && exit 1

# workArr is a raw list of profiles
workArr=( $(grep '[P,p]'ath $profilepath/profiles.ini | sed -e 's/[P,p]ath=//' -e 's/\r//') ) # read each profile into the work array
Expand All @@ -59,61 +68,80 @@ do_xulbased() {

# here is the actual worker
find -L ${FinalArr[@]} -maxdepth 2 -name '*.sqlite' | SHELL=/bin/bash parallel do_clean 2>/dev/null
echo
echo "$name profile(s) reduced by $(grep $name /tmp/accounting.db | gawk -F, '{ print $2 }' | paste -sd+ - | bc) Mbytes"
[[ -f /tmp/accounting.db ]] && rm -f /tmp/accounting.db
}

do_dbbased() {
[[ -h "$prepath" ]] && profilepath=$(readlink $prepath) || profilepath="$prepath"
[[ ! -d "$profilepath" ]] && echo "Error: no profile directory for midori found." && exit 1
[[ ! -d "$profilepath" ]] && echo "Error: no profile directory for $name found." && exit 1
find ${profilepath} -maxdepth 2 -type f -name '*.db' | SHELL=/bin/bash parallel do_clean 2>/dev/null
echo
echo "$name profile reduced by $(grep $name /tmp/accounting.db | gawk -F, '{ print $2 }' | paste -sd+ - | bc) Mbytes"
}

export -f do_clean

case "$1" in
c)
prepath=$XDG_CONFIG_HOME/chromium
C|c)
name="chromium" ; export name
prepath=$XDG_CONFIG_HOME/$name
do_chromebased
exit 0
;;
gc)
prepath=$XDG_CONFIG_HOME/google-chrome
Gc|gC|GC|gc)
name="google-chrome" ; export name
prepath=$XDG_CONFIG_HOME/$name
do_chromebased
exit 0
;;
f)
prepath=$HOME/.mozilla/firefox
F|f)
name="firefox"; export name
prepath=$HOME/.mozilla/$name
do_xulbased
exit 0
;;
ck)
prepath=$HOME/.conkeror.mozdev.org/conkeror
CK|cK|Ck|ck)
name="conkeror"; export name
prepath=$HOME/.conkeror.mozdev.org/$name
do_xulbased
exit 0
;;
h)
H|h)
name="heftig aurora"; export name
prepath=$HOME/.mozilla/aurora
do_xulbased
exit 0
;;
t)
prepath=$HOME/.thunderbird
T|t)
name="thunderbird"; export name
prepath=$HOME/.$name
do_xulbased
exit 0
;;
m)
prepath=$XDG_CONFIG_HOME/midori
M|m)
name="midori"; export name
prepath=$XDG_CONFIG_HOME/$name
do_dbbased
exit 0
;;
Q|q)
name="qupzilla"; export name
prepath=$HOME/.$name/profiles
do_dbbased
exit 0
;;
*)
echo "$0 {a|c|ck|f|gc|t}"
echo " c) chromium"
echo "ck) conkeror"
echo " f) firefox"
echo "gc) google chrome"
echo " h) heftig's aurora"
echo " m) midori"
echo " t) thunderbird"
echo " c) Chromium"
echo "ck) Conkeror"
echo " f) Firefox"
echo "gc) Google Chrome"
echo " h) Heftig's Aurora"
echo " m) Midori"
echo " t) Thunderbird"
echo " q) QupZilla"
exit 0
;;
esac
8 changes: 4 additions & 4 deletions profile-cleaner.manpage
@@ -1,5 +1,5 @@
.\" Text automatically generated by txt2man
.TH profile-cleaner 1 "29 November 2012" "" ""
.TH profile-cleaner 1 "30 November 2012" "" ""
.SH NAME
\fBprofile-cleaner \fP- Reduce the size of browser and some email program's profiles by organizing their sqlite databases using sqlite3's vacuum and reindex functions.
\fB
Expand Down Expand Up @@ -66,8 +66,6 @@ Midori
Size before: 154.17 Mbytes
.PP
Size after: 99.11 Mbytes
.PP
Recovered: 55.06 Mbytes
.RE
.PP

Expand All @@ -89,6 +87,8 @@ Recovered: 55.06 Mbytes
/home/facade/.mozilla/firefox/zee52krz.default/search.sqlite reduced by 0 Mbytes
/home/facade/.mozilla/firefox/zee52krz.default/places.sqlite reduced by 9.98 Mbytes

firefox profile reduced by 55.06 Mbytes

.fam T
.fi
.SH CONTRIBUTE
Expand All @@ -98,4 +98,4 @@ None known.
.SH AUTHOR
graysky (graysky AT archlinux DOT us)
.SH SEE ALSO
profile-sync-deamon (8)
profile-sync-deamon (1)

0 comments on commit a939f33

Please sign in to comment.