Skip to content

Instantly share code, notes, and snippets.

@mastercoms
Created July 31, 2015 19:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mastercoms/c92de4a40f4bea4d99a7 to your computer and use it in GitHub Desktop.
Save mastercoms/c92de4a40f4bea4d99a7 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Constants
mozillaHome=${HOME}/.mozilla/
sqlite=sqlite3
# Check that the environment is ready to perform the optimisation
which ${sqlite} >/dev/null 2>&1
if [ $? -ne 0 ]
then
echo "Error: ${sqlite} was not found on this system."
echo " Check your PATH, or install ${sqlite}, try: sudo apt-get install ${sqlite}"
exit 1
fi
proc=$(ps ux | grep -v $0 | egrep -i 'firefox|fennec|seamonkey' | grep -v grep | wc -l)
if [ ${proc} -gt 0 ]
then
echo "Error: Firefox is running. Please shutdown firefox before running this script"
exit 1
fi
# Start the optimisation
# Check where the Firefox (Fennec & SeaMonkey) profiles are
ffProfiles=$(find ${mozillaHome} -mindepth 1 -maxdepth 1 -type d ! -name eclipse -a ! -name extensions 2>/dev/null)
for ffProf in ${ffProfiles}
do
if [ -f "${ffProf}/profiles.ini" ]
then
for profileDir in $(cat "${ffProf}/profiles.ini" | grep Path= | sed -e 's/Path=//')
do
ffProfDir="${ffProf}/${profileDir}"
if [ -d "${ffProfDir}" ]
then
echo "Info: Processing directory ${ffProfDir}"
echo " optimising local files..."
i=1
cd "${ffProfDir}"
for sqlFile in $(find . -type f -name '*.sqlite' -print)
do
echo -n " ${i}. processing file ${sqlFile} "
${sqlite} ${sqlFile} "VACUUM;" 2>/dev/null
if [ $? -ne 0 ]
then
echo -e " failed\nWarning: file ${sqlFile} could not be optimised."
else
echo " done."
fi
i=$((i+1))
done
echo " optimisation done."
else
echo "Warning: profile ${ffProfDir} not found!"
fi
done
else
echo "Warning: Firefox profile not found: ${ffProf}/profiles.ini"
fi
done
echo "Info: optimization done"
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment