File: /home/httpd/html/gaycreampieass.com/public_html/wp-upgrade.sh
#!/bin/bash
#Generate a random hash to use for backup filenames, makeing sure its unique
r=`cat /dev/urandom | tr -dc A-Za-z0-9 | head -c12`
while [ -e ../$r.sql ]
do
r=`cat /dev/urandom | tr -dc A-Za-z0-9 | head -c12`
done
#Read the wordpress config
echo -n Scanning wordpress config...
dname=`grep DB_NAME wp-config.php | awk -F \' '{print($4)}'`
echo -n .
dpass=`grep DB_PASSWORD wp-config.php | awk -F \' '{print($4)}'`
echo -n .
duser=`grep DB_USER wp-config.php | awk -F \' '{print($4)}'`
echo -n .
dhost=`grep DB_HOST wp-config.php | awk -F \' '{print($4)}'`
echo -n .
#Make sure we have the database info
if [ -z "$dname" ]; then echo Unable to find database name;exit 1;fi
echo -n .
if [ -z "$dpass" ] ;then echo Unable to find database password;exit 1;fi
echo -n .
if [ -z "$duser" ] ;then echo Unable to find database user;exit 1;fi
echo -n .
if [ -z "$dhost" ] ;then echo Unable to find database host;exit 1;fi
echo ... found $dname with user $duser on server $dhost
echo -n Creating backup with hash $r ...
echo -n MySQL.. ;
#Make a non-locking dump of the database (many users dont have LOCK priv)
if `mysqldump -f -Q -q -c --lock-tables=false -u $duser -p"$dpass" -h $dhost $dname > ../$r.sql `; then
echo -n ...MySQL completed
else
echo ... MySQL error ;exit 1
fi
#Tar up the files we are going to replace
echo -n ...Files...;
#Get the files out of the new tarball
filesnew=`wget --no-check-certificate -q -O - wordpress.org/latest.tar.gz | tar -z -t | awk -F / '{print($2)}' | sort | uniq | grep -v ^$ | tr '\n' ' '`
for x in $filesnew;do
[ -e "$x" ] &&files="$files"" ""$x"
done
#Use those files to tar existing files
#if `tar -f ../$r.tar -c $files `
#then
# echo -n Complete;
#else
# echo Files failed...;exit 1
#fi
echo ... Done
#unpack the new wordpress
echo -n Downloading and extracting new WordPress...
(wget --no-check-certificate -q -O - wordpress.org/latest.tar.gz | tar -z -x --strip-components=1) && echo ...Complete || echo ...failure
#chown it to the owner of the paren folder
#echo -n Chowning... ; chown -R --reference=./ ./ && echo ...Complete || echo ...failure
#chmod everything to safe perms
#echo -n Chmoding... ; chmod -R u=rwX,g=rX,o=rX ./ && echo ...Complete || echo ...failure
#chmod wp-content so wordpress can use it
#echo -n Chmoding wp-content... ;chmod -R u=rwX,g=rwX,o=rX ./wp-content/ && echo ...Complete || echo ...failure
echo "finished"