Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- # jfindfiles -- Find used and unused content files in your Joomla website
- #
- # This scripts supports Joomla versions 2.5 - 3.x
- #
- # Copyright 2014 Rene Kreijveld - email@renekreijveld.nl
- #
- # This program is free software; you may redistribute it and/or modify it.
- #
- # Warning! This script needs the file jfunctions. This has to be installed in the same directory as this script.
- #
- # general variables
- mypath=$(cd $(dirname ${0}); pwd -P)
- myname=$(basename ${0})
- # include general functions
- . ${mypath}/jfunctions
- # version
- version=2.2
- # Setup Vvariables
- start=./images
- curdir=`pwd`
- echo "Creating database dump..."
- # Dump the database to a .sql file
- if mysqldump --skip-opt --add-drop-table --add-locks --create-options --disable-keys --lock-tables --quick --set-charset --host=${host} --user=${dbuser} --password=${password} ${database} > ${database}.sql
- then
- echo "Database dump ${database}.sql created."
- else
- echo "Error creating database dump."
- exit 1
- fi
- dbdump=${curdir}/${database}.sql
- usedfile=${curdir}/${sitename}-used.txt
- notusedfile=${curdir}/${sitename}-notused.txt
- echo "The following files were mentioned in your Joomla database:" > ${usedfile}
- echo "The following files were NOT mentioned in your Joomla database:" > ${notusedfile}
- echo "Checking for used and unused files..."
- # Move into the images/stories directory
- cd ${start}
- # Find all files and check if they are mentioned in the database dump
- for file in `find . -type f -print | cut -c 3- | sed 's/ /#}/g'`
- do
- file2=`echo $file | sed 's/#}/ /g'`
- file3=`echo $file | sed 's/#}/%20/g'`
- if grep -c "$file2" ${dbdump} > 0; then
- echo $file2 >> ${usedfile}
- elif grep -c "$file3" ${dbdump} > 0; then
- echo $file3 >> ${usedfile}
- else
- echo $file3 >> ${notusedfile}
- fi
- done
- # Move back to the root of the website
- cd ${curdir}
- # Cleanup database dump
- rm ${dbdump}
- # Report findings
- echo "Files checking done."
- echo "Check the following text-files for results:"
- echo "${usedfile}"
- echo "${notusedfile}"
Add Comment
Please, Sign In to add comment