Skip to content

Commit

Permalink
updated to be compatiable with profile-sync-deamon v5 series
Browse files Browse the repository at this point in the history
updated to use parallel rather than for loops
  • Loading branch information
graysky2 committed Nov 28, 2012
1 parent e8e2b79 commit 62810a2
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 50 deletions.
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
#Profile-cleaner
# Profile-cleaner
Use profile-cleaner to reduce the size of browser profiles by organizing their sqlite databases using sqlite3's vacuum and reindex functions.

Sample output and results using an "uncleaned" firefox profile:
## Dependencies
* bc
* findutils
* sqlite
* parallel (new dependency)

## Sample Output and Results Using an "Uncleaned" Firefox Profile:

Size before: 154.17 Mbytes
Size after: 99.11 Mbytes
Expand Down
86 changes: 38 additions & 48 deletions profile-cleaner
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
#!/bin/bash

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

do_clean() {
bsize=$(ls -l "$1" | awk {'print $5'})
sqlite3 "$1" vacuum &>/dev/null
Expand All @@ -11,68 +17,49 @@ do_clean() {

do_chromium() {
prepath=$HOME/.config/chromium
if [[ -h "$prepath" ]]; then
path=$(readlink $prepath)
else
path="$prepath"
fi

if [[ ! -d "$path" ]]; then
echo "Error: no profile directory for chromium found."
exit 0
fi

for i in History Archived Safe; do
find ${path} -maxdepth 2 -type f -name "$i*" -print0 | xargs -0 -n 1 -I {} bash -c "do_clean {} 2>/dev/null"
done
[[ -h "$prepath" ]] && profilepath=$(readlink $prepath) || profilepath="$prepath"
[[ ! -d "$profilepath" ]] && echo "Error: no profile directory for chromium 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
}

do_chrome() {
prepath=$HOME/.config/google-chrome
if [[ -h "$prepath" ]]; then
path=$(readlink $prepath)
else
path="$prepath"
fi

if [[ ! -d "$path" ]]; then
echo "Error: no profile directory for chrome found."
exit 0
fi

for i in History Archived Safe; do
find ${path} -maxdepth 2 -type f -name "$i*" -print0 | xargs -0 -n 1 -I {} bash -c "do_clean {} 2>/dev/null"
done
[[ -h "$prepath" ]] && profilepath=$(readlink $prepath) || profilepath="$prepath"
[[ ! -d "$profilepath" ]] && echo "Error: no profile directory for chrome 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
}

do_xulbased() {
# prepath should be defined in the do_whatever function
if [[ -h "$prepath" ]]; then
path=$(readlink $prepath)
profilepath=$(readlink $prepath)
else
path="$prepath"
profilepath="$prepath"
fi

if [[ ! -d "$path" ]]; then
echo "Error: cannot locate $path"
exit 0
if [[ ! -d "$profilepath" ]]; then
echo "Error: cannot locate $profilepath"
exit 1
fi

if [[ ! -f $path/profiles.ini ]]; then
echo "Error: cannot locate $path/profiles.ini to determine names of profiles."
exit 0
fi
[[ ! -f $profilepath/profiles.ini ]] && echo "Error: cannot locate $profilepath/profiles.ini to determine names of profiles." && exit 1

# read each profile into the work array
work=( $(grep Path $path/profiles.ini | sed -e 's/Path=//' -e 's/\r//') )
# workArr is a raw list of profiles
workArr=( $(grep '[P,p]'ath $profilepath/profiles.ini | sed -e 's/[P,p]ath=//') ) # read each profile into the work array

for i in "${work[@]}"; do
if [ ! -d ${path}/"$i" ]; then
find $i -maxdepth 2 -name '*.sqlite' -print0 | xargs -0 -n 1 -I {} bash -c "do_clean {} 2>/dev/null"
else
find ${path}/$i -maxdepth 2 -name '*.sqlite' -print0 | xargs -0 -n 1 -I {} bash -c "do_clean {} 2>/dev/null"
# FinalArr is a processed list of profiles
# they are formated to abs paths since some are rel and some are abs
index=0
for i in "${workArr[@]}"; do
if [ ! -d ${profilepath}/"$i" ]; then
FinalArr[index]="$i"
else
FinalArr[index]="$profilepath/$i"
fi
index=$index+1
done

# here is the actual worker
find -L ${FinalArr[@]} -maxdepth 2 -name '*.sqlite' | SHELL=/bin/bash parallel do_clean 2>/dev/null
}

do_firefox() {
Expand All @@ -86,8 +73,8 @@ do_conkeror() {
}

do_heftig-aurora() {
prepath=$HOME/.mozilla/aurora
do_xulbased
prepath=$HOME/.mozilla/aurora
do_xulbased
}

do_thunderbird() {
Expand Down Expand Up @@ -123,7 +110,10 @@ case "$1" in
exit 0
;;
*)
echo "Usage $0 {a|c|ck|f|gc|t}"
echo -en " \E[31m::USAGE::"
tput sgr0
echo
echo "$0 {a|c|ck|f|gc|t}"
echo " c) chromium"
echo "ck) conkeror"
echo " f) firefox"
Expand Down

0 comments on commit 62810a2

Please sign in to comment.