pushing old code

This commit is contained in:
Bradford Morgan White
2026-02-08 13:03:05 -05:00
commit a1cba070d8
17 changed files with 1513 additions and 0 deletions
+24
View File
@@ -0,0 +1,24 @@
#!/bin/bash
POSIT=()
while [[ $# -gt 0 ]]
do
key="$1"
case $key in
-f|--file) FILE=$2; shift;;
-n|--new) NEW=$2; shift;;
-o|--old) OLD=$2; shift;;
*) echo "$1 not implemented" ; POSIT+=("$1") ;;
esac
shift
done
set -- "${POSIT[@]}"
if [ -z $FILE ] || [ -z $NEW ] || [ -z $OLD ]; then
echo "You must provide a file, a new domain, and an old domain"
exit 1
fi
sed 's/;s:/;\ns:/g' $FILE | awk -F'"' '/s:.+'$OLD'/ {sub("'$OLD'", "'$NEW'"); n=length($2)-1; sub(/:[[:digit:]]+:/, ":" n ":")} 1' | sed ':a;N;$!ba;s/;\ns:/;s:/g' | sed "s/$OLD/$NEW/g" > ${FILE}.tmp
mv ${FILE}.tmp ${FILE}
+141
View File
@@ -0,0 +1,141 @@
#######################
# THE BACKUP FUNCTION #
#######################
function backup() {
POSIT=()
while [[ $# -gt 0 ]]; do
KEY="$1"
case $KEY in
-n|--no-compress) NOCOMPRESS="yes" ;;
-d|--delete-old) DELETEOLD="yes" ;;
-s|--skip-uploads) SKIPUPLOADS="yes" ;;
-p|--path) DESTDIR="$2" ; shift ;;
*) echo "$1 not implemented" ; POSIT+=("$1") ;;
esac
shift
done
set -- "${POSIT[@]}"
DELETEOLD="${DELETEOLD:-no}"
SKIPUPLOADS="${SKIPUPLOADS:-no}"
DESTDIR="${DESTDIR:-`pwd`}"
[ -f ${DESTDIR}/wp-config.php ] || echo "this isn't a wordpress installation"
[ -f ${DESTDIR}/wp-config.php ] || exit 1
local DATETIME=`date +%Y%m%d.%H%M`
echo "==WPM BACKUP CALLED ON $DATETIME WITH VERSION $WPMVERSION==" | tee -a $LOGFILE
echo "==UNIQUE IDENTIFIER $INSTANCEID==" | tee -a $LOGFILE
echo "==$INSTANCEID==Executing backup on $DESTDIR" >> $LOGFILE
cd $DESTDIR
local NAME=`echo $DESTDIR | rev | cut -d '/' -f 1 | rev`
if [ "$NAME" == "" ] || [ ${#NAME} -lt 3 ] || [ "$NAME" == "html" ]; then
NAME=`hostname -f`
fi
echo "==$INSTANCEID==The name is ${NAME}" | tee -a $LOGFILE
local DBNAME=`grep DB_NAME wp-config.php | awk -F "'" '{print $4}'`
echo "==$INSTANCEID==The DB name is ${DBNAME}" | tee -a $LOGFILE
if mysql "${DBNAME}" >/dev/null 2>&1 </dev/null; then
echo "==$INSTANCEID==${DBNAME} exists (and I have permission to access it)" | tee -a $LOGFILE
else
echo "==$INSTANCEID==${DBNAME} doesn't exist or I lack access, terminating" | tee -a $LOGFILE
exit 1
fi
echo "==$INSTANCEID==Starting the DB dump" | tee -a $LOGFILE
try mysqldump $DBNAME --single-transaction > $TEMPDIR/${DBNAME}.${DATETIME}.sql
echo "==$INSTANCEID==The database dump is complete." | tee -a $LOGFILE
if [ "$BACKUPPATH" == "PARENTOFGIVEN" ]; then
BACKUPPATH=`dirname $DESTDIR`
DELETEOLD="no"
fi
if [ "$DELETEOLD" == "yes" ]; then
try find $BACKUPPATH -mtime +1 -type f -exec rm -fv '{}' \;;
echo "==$INSTANCEID==removed old backups" | tee -a $LOGFILE;
fi
if [[ "${SKIPUPLOADS}" == "no" ]]; then
local SF=`echo $(($(stat -f --format="%a*%S" .)))`;
local SN=`du -sb .|awk '{print $1}'`;
local SB=${SN}
local SN=`echo $(($SN + $SN))`;
if [ $SF -gt $SN ]; then
echo "==$INSTANCEID==Adequate free space detected" | tee -a $LOGFILE
else
echo "==$INSTANCEID==Insufficient space available. Terminating" | tee -a $LOGFILE
exit 1
fi
fi
echo "==$INSTANCEID==Starting archive creation" | tee -a $LOGFILE
[ `which xz` ] && COMPRESSOR="xz"
[ `which pv` ] && PROGRESS="pv"
if [ "$PROGRESS" == "pv" ]; then
TAROPTIONS="cf"
INTERPRED="pv -per -s${SB} |"
else
TAROPTIONS="cfv"
INTERPRED=""
fi
if [ "$SKIPUPLOADS" == "yes" ]; then
EXCLUDES="--exclude-tag=tagfile --exclude-vcs --exclude-backups"
else
EXCLUDES="--exclude-vcs --exclude-backups"
fi
if [ -d $DESTDIR/wp-content/uploads ]; then
touch $DESTDIR/wp-content/uploads/tagfile
fi
MEMORY=$( echo $((`cat /proc/meminfo | grep MemTotal | awk '{print $2}'`/1024)) )
if [[ $MEMORY -lt 1152 ]]; then
NOCOMPRESS="yes"
else
NOCOMPRESS="${NOCOMPRESS:-no}"
fi
if [ "$NOCOMPRESS" == "yes" ]; then
if [ "$COMPRESSOR" == "xz" ]; then
PRED="xz -0 > $BACKUPPATH/$NAME.$DATETIME.tar.xz"
else
PRED="gzip -1 > $BACKUPPATH/$NAME.$DATETIME.tar.gz"
fi
else
if [ "$COMPRESSOR" == "xz" ]; then
PRED="xz -9 > $BACKUPPATH/$NAME.$DATETIME.tar.xz"
else
PRED="gzip -9 > $BACKUPPATH/$NAME.$DATETIME.tar.gz"
fi
fi
[ `which getfacl` ] && getfacl -R `pwd` > .permissions_backup.${DATETIME}
[ `which getfacl` ] && echo "==$INSTANCEID==Permissions backup completed." | tee -a $LOGFILE
[ `which getfacl` ] && echo "==$INSTANCEID==Restore with setfacl --restore=${DESTDIR}/.permissions_backup.${DATETIME}" | tee -a $LOGFILE
CMD="try tar $TAROPTIONS - $EXCLUDES --transform=\"flags=r;s|^|$DATETIME/|\" --show-transformed * $TEMPDIR/$DBNAME.$DATETIME.sql | $INTERPRED $PRED"
eval $CMD
rm -f $TEMPDIR/$DBNAME.$DATETIME.sql
if [ -f $DESTDIR/wp-content/uploads/tagfile ]; then
rm -f $DESTDIR/wp-content/uploads/tagfile
fi
echo "==$INSTANCEID==The archive is available at $BACKUPPATH/$NAME.$DATETIME.tar.xz"
} # END BACKUP
+96
View File
@@ -0,0 +1,96 @@
#####################
# THE COPY FUNCTION #
#####################
function copy() {
POSIT=()
while [[ $# -gt 0 ]]; do
KEY="$1"
case $KEY in
-o|--oldname) OLDNAME=$2; shift;;
-n|--newname) NEWNAME=$2; shift;;
-s|--source) SOURCE=$2; shift;;
-d|--destination) DESTDIR=$2; shift ;;
*) echo "$1 not implemented" ; POSIT+=("$1") ;;
esac
shift
done
set -- "${POSIT[@]}"
[ -d $SOURCE ] || echo "source directory does not exist"
[ -d $SOURCE ] || exit 1
[ -f $SOURCE/wp-config.php ] || echo "this isn't a wordpress installation"
[ -f $SOURCE/wp-config.php ] || exit 1
local DATETIME=`date +%Y%m%d.%H%M`
echo "==WPM COPY CALLED ON $DATETIME WITH VERSION $WPVERSION==" | tee -a $LOGFILE
echo "==UNIQUE IDENTIFIER $INSTANCEID==" | tee -a $LOGFILE
echo "==$INSTANCEID==Executing copy from $SOURCE to $DESTDIR" | tee -a $LOGFILE
[ -d $DESTDIR ] || try mkdir -p $DESTDIR
try rsync -aq $SOURCE/* $DESTDIR
echo "==$INSTANCEID==File copy complete." | tee -a $LOGFILE
cd $DESTDIR
local DBNAME=`grep DB_NAME wp-config.php | awk -F "'" '{print $4}'`
local DBUSER=`grep DB_USER wp-config.php | awk -F "'" '{print $4}'`
echo "==$INSTANCEID==Database $DBNAME with user $DBUSER." | tee -a $LOGFILE
if mysql "${DBNAME}" >/dev/null 2>&1 </dev/null; then
echo "==$INSTANCEID==DB ${DBNAME} exists and I have access to it" | tee -a $LOGFILE
else
echo "==$INSTANCEID==${DBNAME} doesn't exist, or I can't access it. Terminating." | tee -a $LOGFILE
exit 1
fi
try mysqldump $DBNAME --single-transaction > $TEMPDIR/$DBNAME.sql
echo "==$INSTANCEID==DB dump to SQL file is complete." | tee -a $LOGFILE
echo "==$INSTANCEID==Changing $SOURCE to $DESTDIR with sed" | tee -a $LOGFILE
try find `pwd` -type f -exec sed -i "s/$SOURCE/$DESTDIR/g" '{}' \;
try sed -i "s|$SOURCE|$DESTDIR|g" $TEMPDIR/$DBNAME.sql
echo "==$INSTANCEID==Sed complete." | tee -a $LOGFILE
echo "==$INSTANCEID==Running fixserial on $TEMPDIR/$DBNAME.sql" | tee -a $LOGFILE
try /usr/local/lib/fixserial.sh -o $OLDNAME -n $NEWNAME -f $TEMPDIR/$DBNAME.sql
echo "==$INSTANCEID==Fixserial has been run." | tee -a $LOGFILE
[ -e "$SOURCE/.htaccess" ] && cp -v $SOURCE/.htaccess $DESTDIR/.htaccess
[ -d "$SOURCE/.ssh" ] && cp -vR $SOURCE/.ssh $DESTDIR/
[ -e "$SOURCE/wp-content/uploads/.htaccess" ] && cp -v $SOURCE/wp-content/uploads/.htaccess $DESTDIR/wp-content/uploads/.htaccess
echo "==$INSTANCEID==Dot files copied (if they existed)." | tee -a $LOGFILE
local NEWDB=${DBNAME}
NEWDB+=`openssl rand -hex 2`
echo "==$INSTANCEID==New database name is ${NEWDB}" | tee -a $LOGFILE
if mysql "${NEWDB}" >/dev/null 2>&1 </dev/null;then
echo "==$INSTANCEID==${NEWDB} somehow already exists. Terminating." | tee -a $LOGFILE
exit 1
fi
echo "==$INSTANCEID==Running DB import to ${NEWDB}" | tee -a $LOGFILE
try mysql -e "create database ${NEWDB}"
try mysql -e "grant all on ${NEWDB}.* to ${DBUSER}"
try mysql -e "flush privileges"
try mysql "${NEWDB}" < $TEMPDIR/${DBNAME}.sql
echo "==$INSTANCEID==DB import to ${NEWDB} is complete." | tee -a $LOGFILE
rm -f $TEMPDIR/${DBNAME}.sql
echo "==$INSTANCEID==SQL file has been removed." | tee -a $LOGFILE
try sed -i "s/DB_NAME', '${DBNAME}/DB_NAME', '${NEWDB}/" $DESTDIR/wp-config.php
echo "==$INSTANCEID==Config file updated with new database." | tee -a $LOGFILE
echo "==$INSTANCEID==Running permissions" | tee -a $LOGFILE
try chown --reference=$SOURCE $DESTDIR
permissions $DESTDIR
echo "==$INSTANCEID==Permissions complete." | tee -a $LOGFILE
echo "==$INSTANCEID==Copy of $OLDNAME to $NEWNAME completed." | tee -a $LOGFILE
} # END COPY
+69
View File
@@ -0,0 +1,69 @@
#######################
# THE DELETE FUNCTION #
#######################
function delete() {
POSIT=();
while [[ $# -gt 0 ]]; do
KEY="$1"
case $KEY in
-b|--backup) DOBACKUP="yes" ;;
-p|--path) DIRECTORY=$2 ; shift ;;
*) echo "$1 not implemented" ; POSIT+=("$1") ;;
esac
shift
done
set -- "${POSIT[@]}"
[ -z $DIRECTORY ] && echo "You must provide a full path"
[ -z $DIRECTORY ] && exit 1
[ -d $DIRECTORY ] || echo "directory does not exist"
[ -d $DIRECTORY ] || exit 1
[ -f $DIRECTORY/wp-config.php ] || echo "this isn't a wordpress installation"
[ -f $DIRECTORY/wp-config.php ] || exit 1
local DATETIME=`date +%Y%m%d.%H%M`
echo "==WPM DELETE CALLED ON $DATETIME WITH VERSION $WPMVERSION==" >> $LOGFILE
echo "==UNIQUE IDENTIFIER $INSTANCEID==" >> $LOGFILE
echo "=$INSTANCEID=Executing delete on $DIRECTORY" >> $LOGFILE
if [ "$DOBACKUP" == "yes" ];then
backup -p `pwd`
else
echo "==$INSTANCEID==WARNING: BACKUP HAS BEEN DECLINED!" | tee -a $LOGFILE
fi
cd $DIRECTORY
local DBNAME=`grep DB_NAME wp-config.php | cut -f 2 -d ' ' | awk -F "'" '{print $2}'`
echo "==$INSTANCEID==The DB name is $DBNAME" | tee -a $LOGFILE
local DBUSER=`grep DB_USER wp-config.php | cut -f 2 -d ' ' | awk -F "'" '{print $2}'`
echo "==$INSTANCEID==The DB user is $DBUSER" | tee -a $LOGFILE
if mysql "${DBNAME}" >/dev/null 2>&1 </dev/null; then
echo "==$INSTANCEID==${DBNAME} exists (and I have permission to access it)" | tee -a $LOGFILE
else
echo "==$INSTANCEID==${DBNAME} doesn't exist or I lack access" | tee -a $LOGFILE
fi
mysql -e "DELETE FROM mysql.user WHERE \`user\`=\"${DBUSER}\";"
mysql -e "FLUSH PRIVILEGES;"
echo "==$INSTANCEID==Database user ${DBUSER} has been deleted" | tee -a $LOGFILE
mysql -e "DROP DATABASE IF EXISTS ${DBNAME};"
echo "==$INSTANCEID==Database ${DBNAME} has been dropped" | tee -a $LOGFILE
cd ..
try rm -rf $DIRECTORY/*
try rm -rf $DIRECTORY
echo "==$INSTANCEID==Removal of document root contents completed." | tee -a $LOGFILE
echo "==$INSTANCEID==Deletion: $DIRECTORY, $DBNAME, $DBUSER; completed." | tee -a $LOGFILE
} # END DELETE
+37
View File
@@ -0,0 +1,37 @@
#######################
# THE SEARCH FUNCTION #
#######################
search() {
SEARCHDIR="$1"
SEARCHDIR=${SEARCHDIR:-/}
[ -d $SEARCHDIR ] || SEARCHDIR="/"
local DATETIME=`date +%Y%m%d.%H%M`
echo "==WPM FIND CALLED ON $DATETIME WITH VERSION $WPVERSION==" | tee -a $LOGFILE
echo "==UNIQUE IDENTIFIER $INSTANCEID==" | tee -a $LOGFILE
echo "==$INSTANCEID==Executing find on $SEARCHDIR" | tee -a $LOGFILE
for WPCONFIG in `find $SEARCHDIR -type f -iname "wp-config.php" -exec dirname '{}' \; | xargs -0 -I {} echo {}`; do
DIRECTORY=`echo $WPCONFIG | tr -cd "[:print:]"`
if [ -d "$DIRECTORY/wp-content" ]; then
echo $DIRECTORY | tee -a $TEMPDIR/wordpress_installs.list
else
echo $DIRECTORY >> $TEMPDIR/orphans.list
fi
done
if [ -s $TEMPDIR/orphans.list ]; then
echo "==$INSTANCEID==Orphaned WordPress installs found:" | tee -a $LOGFILE
cat $TEMPDIR/orphans.list | sed "s/^/==$INSTANCEID==" | tee -a $LOGFILE
echo "==$INSTANCEID==Orphans are in $TEMPDIR/orphans.list" | tee -a $LOGFILE
else
echo "==$INSTANCEID==No orphaned WordPress installs found." | tee -a $LOGFILE
fi
echo "==$INSTANCEID==Results are in $TEMPDIR/wordpress_installs.list" | tee -a $LOGFILE
echo "==$INSTANCEID==Search is complete." | tee -a $LOGFILE
} # END SEARCH
+164
View File
@@ -0,0 +1,164 @@
########################
# THE INSTALL FUNCTION #
########################
function install() {
POSIT=();
while [[ $# -gt 0 ]]; do
KEY="$1"
case $KEY in
-d|--domain) DOMAIN="$2"; shift ;;
-p|--path) DESTDIR="$2"; shift ;;
-s|--skip-ftp) SKIPFTP="yes" ;;
*) echo "$1 not implemented" ; POSIT+=("$1") ;;
esac
shift
done
set -- "${POSIT[@]}"
DESTDIR="${DESTDIR:-`pwd`}"
SKIPFTP="${SKIPFTP:-no}"
local DATETIME=`date +%Y%m%d.%H%M`
[ -z $DOMAIN ] && echo "you must provide a domain name"
[ -z $DOMAIN ] && exit 1
[ -f "$DESTDIR/wp-config.php" ] && echo "this is already a wordpress installation"
[ -f "$DESTDIR/wp-config.php" ] && exit 1
[ -d "$DESTDIR/wp-content" ] && echo "this is already a wordpress installation"
[ -d "$DESTDIR/wp-content" ] && exit 1
echo "==WP INSTALL CALLED ON $DATETIME WITH VERSION $WPVERSION==" | tee -a $LOGFILE
echo "==UNIQUE IDENTIFIER $INSTANCEID==" | tee -a $LOGFILE
echo "==$INSTANCEID==starting install in $DESTDIR==" | tee -a $LOGFILE
cd $DESTDIR
local PASSWORD=`openssl rand -hex 5`
local TRIMMEDDOMAIN=`echo $DOMAIN | sed -e 's/\.//g' | tr '-' '_'| cut -c -10`
local TRIMMEDDOMAIN+=`openssl rand -hex 2`
echo "==$INSTANCEID==Password and seed have been generated" | tee -a $LOGFILE
echo "==$INSTANCEID==Checking $TEMPDIR/wp-installer" | tee -a $LOGFILE
[ -d $TEMPDIR/wp-installer ] || try mkdir -p $TEMPDIR/wp-installer
try chmod 1777 $TEMPDIR/wp-installer
echo "==$INSTANCEID==Removing old versions if they exist" | tee -a $LOGFILE
try find $TEMPDIR/wp-installer/ -mtime +1 -iname "wordpress.latest*" -delete
if [ -e $TEMPDIR/wp-installer/wordpress.latest.tar ]; then
echo "==$INSTANCEID==Recent version already present" | tee -a $LOGFILE
else
try wget -O $TEMPDIR/wp-installer/wordpress.latest.tar.gz https://wordpress.org/latest.tar.gz --no-check-certificate &> /dev/null
try gunzip $TEMPDIR/wp-installer/wordpress.latest.tar.gz &> /dev/null
if [ -e $TEMPDIR/wp-installer/wordpress.latest.tar ]; then
try touch $TEMPDIR/wp-installer/wordpress.latest.tar
else
echo "==$INSTANCEID==tar ball of wp not present?!" | tee -a $LOGFILE
exit 1
fi
echo "==$INSTANCEID==Recent version downloaded" | tee -a $LOGFILE
fi
if [ ! -e $TEMPDIR/wp-installer/wordpress.latest.tar ]; then
echo "==$INSTANCEID==Cannot get archive at $TEMPDIR/wp-installer/" | tee -a $LOGFILE
exit 1
fi
echo "==$INSTANCEID==Extracting Wordpress in $DESTDIR" | tee -a $LOGFILE
if tar -f $TEMPDIR/wp-installer/wordpress.latest.tar -x --strip-components=1; then
echo "==$INSTANCEID==Extracting Wordpress in $DESTDIR complete" | tee -a $LOGFILE
else
echo "==$INSTANCEID==Extracting Wordpress in $INSTANCEID failed, trying with legacy tar options" | tee -a $LOGFILE
if tar -f $TEMPDIR/wp-installer/wordpress.latest.tar -x --strip-path=1; then
echo "==$INSTANCEID==Extracting Wordpress in $DESTDIR complete" | tee -a $LOGFILE
else
echo "==$INSTANCEID==Extracting Wordpress completely failed in $DESTDIR" | tee -a $LOGFILE
exit 1
fi
fi
echo "==$INSTANCEID==Generating configuration" | tee -a $LOGFILE
echo -e "<?php\ndefine('DB_NAME', 'database_name_here');\ndefine('DB_USER', 'username_here');\ndefine('DB_PASSWORD', 'password_here');\ndefine('DB_HOST', 'localhost');\ndefine('DB_CHARSET', 'utf8');\ndefine('DB_COLLATE', '');\n"| sed -e "s/database_name_here/""$TRIMMEDDOMAIN""/g" | sed -e "s/username_here/""$TRIMMEDDOMAIN""/g" | sed -e "s/password_here/""$PASSWORD""/g" > wp-config.php
try wget -O - -q https://api.wordpress.org/secret-key/1.1/salt/ >> wp-config.php
if [[ "$SKIPFTP" == "no" ]]; then
echo "==$INSTANCEID==Adding ftp user $TRIMMEDDOMAIN==" | tee -a $LOGFILE
[ -z $SELECTED_USER ] && USERID="9001" || USERID=`id -n $SELECTED_USER`
# THE UIDS WE KNOW WE SHOULDNT BE USING
local BADNESS=("0" "2" "3" "4" "5" "6" "7" "8" "9" "10" "13" "34" "38" "39" "41" "65534" "100")
for BADDY in ${BADNESS[*]}; do
if [ $USERID -eq $BADDY ]; then
echo "UID of $BADDY is not allowed setting to over nine thousand"
USERID="9001"
fi
done # END BADNESS CHECK
try useradd $TRIMMEDDOMAIN -u $USERID -g $SELECTED_GROUP -d $DESTDIR -s /bin/sh -p $(openssl passwd -1 $PASSWORD) -o
echo "==$INSTANCEID==FTP user added" | tee -a $LOGFILE
echo "define('FS_METHOD', 'ftpsockets');" >> wp-config.php
echo "define('FTP_USER', '$TRIMMEDDOMAIN');" >> wp-config.php
echo "define('FTP_PASS', '$PASSWORD');" >> wp-config.php
echo "define('FTP_HOST', '127.0.0.1');" >> wp-config.php
echo "==$INSTANCEID==FTP details and FS_METHOD added to config" | tee -a $LOGFILE
elif [[ "$SKIPFTP" == "yes" ]]; then
echo "==$INSTANCEID==Skipping FTP per user request." | tee -a $LOGFILE
fi
echo -e "\$table_prefix = 'wp_';\n\ndefine ('WPLANG', '');\ndefine('WP_DEBUG', false);\nif ( ! defined('ABSPATH') )\ndefine('ABSPATH', dirname(__FILE__) . '/');\nrequire_once(ABSPATH . 'wp-settings.php');" >> wp-config.php
local DATABASES=`mysql -e "show databases like '$TRIMMEDDOMAIN'" | wc -l`
if [ "$DATABASES" -lt 1 ]; then
echo "==$INSTANCEID==Creating database $TRIMMEDDOMAIN" | tee -a $LOGFILE
echo "create database $TRIMMEDDOMAIN" | mysql
echo "==$INSTANCEID==Granting permissions on $TRIMMEDDOMAIN to $TRIMMEDDOMAIN@localhost" | tee -a $LOGFILE
echo "grant all on $TRIMMEDDOMAIN.* to '$TRIMMEDDOMAIN'@'localhost' identified by '$PASSWORD'" | mysql
else
echo "==$INSTANCEID==Database $TRIMMEDDOMAIN already exists" | tee -a $LOGFILE
exit 1
fi
local DATABASES=`mysql -e "show databases like '$TRIMMEDDOMAIN'" | wc -l`
if [ "$DATABASES" -lt 1 ]; then
echo "==$INSTANCEID==Database creation failed. Terminating." | tee -a $LOGFILE
exit 1
fi
if [[ "$SKIPFTP" == "no" ]]; then
echo "==$INSTANCEID==Setting Permissions on $DESTDIR" | tee -a $LOGFILE
try mkdir $DESTDIR/wp-content/uploads
GROUP="`getent group $SELECTED_GROUP | cut -d ':' -f 1`"
echo "==$INSTANCEID==User: $TRIMMEDDOMAIN, group: $GROUP" | tee -a $LOGFILE
try chown -R $TRIMMEDDOMAIN:$GROUP $DESTDIR
try find $DESTDIR -type d -exec chmod 750 '{}' \;
try find $DESTDIR -type f -exec chmod 640 '{}' \;
[ -d $DESTDIR/wp-content/uploads ] && try chmod 770 $DESTDIR/wp-content/uploads || try install -d -m 0770 $DESTDIR/wp-content/uploads
elif [[ "$SKIPFTP" == "yes" ]]; then
echo "==$INSTANCEID==Permissions were skipped. Potentially very unsafe." | tee -a $LOGFILE
fi
local FPMCHECK=`ps -ef | grep fpm | grep -v grep`
local APACHECHECK=`ps -ef | egrep 'apache|httpd|apache2' | grep -v egrep | grep -v grep`
if [ ${#FPMCHECK} -eq 0 ]; then
if [ ${#APACHECHECK} -gt 0 ]; then
echo "php_flag engine off" > $DESTDIR/wp-content/uploads/.htaccess
echo "==$INSTANCEID==Wrote htaccess file to uploads (mod_php style)" | tee -a $LOGFILE
echo -e "\n\nRewriteEngine On\nRewriteBase /\nRewriteCond %{REQUEST_FILENAME} !-f\nRewriteCond %{REQUEST_FILENAME} !-d\nRewriteRule . /index.php [L]\n\n" > $DESTDIR/.htaccess
echo "==$INSTANCEID==Wrote standard WP htaccess to $DESTDIR/.htaccess" | tee -a $LOGFILE
fi
elif [ ${#FPMCHECK} -gt 0 ]; then
if [ ${#APACHECHECK} -gt 0 ]; then
echo "Options -ExecCGI" > $DESTDIR/wp-content/uploads/.htaccess
echo "==$INSTANCEID==Wrote htaccess file to uploads (fpm style)" | tee -a $LOGFILE
echo -e "\n\nRewriteEngine On\nRewriteBase /\nRewriteCond %{REQUEST_FILENAME} !-f\nRewriteCond %{REQUEST_FILENAME} !-d\nRewriteRule . /index.php [L]\n\n" > $DESTDIR/.htaccess
echo "==$INSTANCEID==Wrote standard WP htaccess to $DESTDIR/.htaccess" | tee -a $LOGFILE
fi
else
echo "==$INSTANCEID==Apache not detected, skipping htaccess" | tee -a $LOGFILE
fi
echo "==$INSTANCEID==Install Complete." | tee -a $LOGFILE
} # END INSTALL
+44
View File
@@ -0,0 +1,44 @@
#######################
# THE MANGLE FUNCTION #
#######################
mangle() {
POSIT=();
while [[ $# -gt 0 ]]; do
KEY="$1"
case $KEY in
-n|--no-backup) BACKUP="no" ;;
-p|--path) DESTDIR=$2 ; shift ;;
-s|--skip-search) SKIPSEARCH="yes" ;;
*) echo "$1 not implemented" ; POSIT+=("$1") ;;
esac
shift
done
set -- "${POSIT[@]}";
SKIPSEARCH="${SKIPSEARCH:-no}"
BACKUP="${BACKUP:-yes}"
DESTDIR="${DESTDIR:-/}"
[ -d $DESTDIR ] || DESTDIR="/"
local DATETIME=`date +%Y%m%d.%H%M`
echo "==WPM MANGLE CALLED ON $DATETIME WITH VERSION $WPVERSION==" | tee -a $LOGFILE
echo "==UNIQUE IDENTIFIER $INSTANCEID==" | tee -a $LOGFILE
echo "==$INSTANCEID==Executing mangle on $DESTDIR" | tee -a $LOGFILE
if [ "$SKIPSEARCH" == "yes" ]; then
[ -f $TEMPDIR/wordpress_installs.list ] || echo "==$INSTANCEID==$TEMPDIR/wordpress_installs.list not found." | tee -a $LOGFILE
exit 1
else
search $DESTDIR
fi
while read LINE
do
if [ "$BACKUP" == "yes" ]; then
backup --path $LINE --skip-uploads
fi
update --path $LINE --plugins
done < $TEMPDIR/wordpress_installs.list
} # END MANGLE
+87
View File
@@ -0,0 +1,87 @@
#########################
# THE PASSWORD FUNCTION #
#########################
function password() {
while [[ $# -gt 0 ]]
do
KEY="$1"
case $KEY in
-d|--duration) DURATION=$2 ; shift ;;
-u|--username) USERNAME=$2 ; shift ;;
-v|--view) VIEW="yes" ;;
-p|--path) DIRECTORY=$2 ; shift ;;
*) echo "$1 not implemented" ; POSIT+=("$1") ;;
esac
shift
done
DIRECTORY=${DIRECTORY:-`pwd`}
USERNAME=${USERNAME:-admin}
VIEW=${VIEW:-no}
DURATION=${DURATION:-600s}
[ -f $DIRECTORY/wp-config.php ] || echo "this isn't a wordpress installation"
[ -f $DIRECTORY/wp-config.php ] || exit 1
local DATETIME=`date +%Y%m%d.%H%M`
echo "==WPM PASSWORD CALLED ON $DATETIME WITH VERSION $WPMVERSION==" | tee -a $LOGFILE
echo "==UNIQUE IDENTIFIER $INSTANCEID==" | tee -a $LOGFILE
echo "==$INSTANCEID==Executing password on $DIRECTORY" | tee -a $LOGFILE
cd $DIRECTORY
local DATABASENAME=`grep DB_NAME wp-config.php | cut -f 2 -d ',' | cut -f 2 -d "'"`
echo "==$INSTANCEID==The DB name is $DATABASENAME" | tee -a $LOGFILE
if mysql "${DATABASENAME}" >/dev/null 2>&1 </dev/null; then
echo "==$INSTANCEID==${DATABASENAME} exists and I have perms to it" | tee -a $LOGFILE
else
echo "==$INSTANCEID==$DATABASENAME does not exist or I do not have access to it. Terminating." | tee -a $LOGFILE
exit 1
fi
if [ "$VIEW" == "yes" ]; then
echo "==$INSTANCEID==View option selected, -d and -u ignored" | tee -a $LOGFILE
try mysql $DATABASENAME -N -e "select \`user_login\` from wp_users where \`user_status\`='0';"
exit 0
fi
if mysql -e "SELECT EXISTS(SELECT 1 FROM $DATABASENAME.wp_users WHERE user_login='$USERNAME' LIMIT 1)"; then
local PREVIOUSPASSWORDHASH=`mysql $DATABASENAME -e "select user_pass from wp_users where user_login='$USERNAME' limit 1;" | grep -v grep | grep -v user_pass`
else
echo "==$INSTANCEID==The specified user $USERNAME was not found. Terminating." | tee -a $LOGFILE
exit 1
fi
if [ -z $PREVIOUSPASSWORDHASH ];then
echo "==$INSTANCEID==Previous password is zero length?! Dying." | tee -a $LOGFILE
exit 1
fi
echo "==$INSTANCEID==Encrypted previous password $PREVIOUSPASSWORDHASH" | tee -a $LOGFILE
local PASSWORD=`openssl rand -hex 10`
printf "%b%s%b%s%b%s%b" "${RED}" "NOT LOGGED:" "${DEFAULT}" "Temporary password will be" "${CIAN}" "$PASSWORD\n" "${DEFAULT}"
try mysql -e "use $DATABASENAME; update wp_users set user_pass = MD5('$PASSWORD') where user_login='$USERNAME';"
echo "==$INSTANCEID==Temporary password has been set @ `date +%Y%m%d.%H%M`" | tee -a $LOGFILE
if [ ! -z $DURATION ] && [ ! "$DURATION" == "0" ];then
echo "==$INSTANCEID==Sleeping for $DURATION" | tee -a $LOGFILE
sleep $DURATION
elif [ "$DURATION" == "0" ]; then
echo "==$INSTANCEID==Duration is zero, password will not revert." | tee -a $LOGFILE
fi
if [ "$DURATION" != "0" ]; then
echo "==$INSTANCEID==Reverting the password." | tee -a $LOGFILE
try mysql -e "use $DATABASENAME; update wp_users set user_pass='$PREVIOUSPASSWORDHASH' where user_login='$USERNAME';"
echo "==$INSTANCEID==Password reverted @ `date +%Y%m%d.%H%M`" | tee -a $LOGFILE
fi
echo "==$INSTANCEID==Password function complete." | tee -a $LOGFILE
} # END PASSWORD
+82
View File
@@ -0,0 +1,82 @@
############################
# THE PERMISSIONS FUNCTION #
############################
function permissions() {
DESTDIR="$1"; DESTDIR=${DESTDIR:-`pwd`}
[ -d $DESTDIR ] || echo "Directory $DESTDIR does not exist."
[ -d $DESTDIR ] || exit 1
[ -f $DESTDIR/wp-config.php ] || echo "This isn't a wordpress installation"
[ -f $DESTDIR/wp-config.php ] || exit 1
local $DATETIME=`date +%Y%m%d.%H%M`
if [ `which getfacl` ]; then
getfacl -R $DESTDIR > .permissions_backup.${DATETIME}
echo "To rollback: setfacl --restore=${DESTDIR}/.permissions_backup.${DATETIME}"
fi
echo "==WPM PERMISSIONS CALLED ON $DATETIME WITH VERSION $WPMVERSION==" | tee -a $LOGFILE
echo "==UNIQUE IDENTIFIER $INSTANCEID==" | tee -a $LOGFILE
echo "==$INSTANCEID==Executing permissions on $DESTDIR" | tee -a $LOGFILE
echo "==$INSTANCEID==Ensuring the uploads directory exists" | tee -a $LOGFILE
[ -d "$DESTDIR/wp-content/uploads" ] || mkdir -p $DESTDIR/wp-content/uploads
echo "==$INSTANCEID==Setting file and directory permissions" | tee -a $LOGFILE
try find $DESTDIR -type d -exec chmod 750 '{}' \;
try find $DESTDIR -type f -exec chmod 640 '{}' \;
echo "==$INSTANCEID==Setting ownership" | tee -a $LOGFILE
[ -z $SELECTED_USER ] && UID="9001" || UID=`id -u -n $SELECTED_USER`
# THE UIDS WE KNOW WE SHOULDNT BE USING
local BADNESS=("0" "2" "3" "4" "5" "6" "7" "8" "9" "10" "13" "34" "38" "39" "41" "65534" "100")
for BADDY in ${BADNESS[*]}; do
if [ "$UID" == "$BADDY" ]; then
echo "UID of $BADDY is not allowed setting to over nine thousand"
UID="9001"
fi
done # END BADNESS CHECK
echo "==$INSTANCEID==User: `id -u -n $UID`, Group: `getent group $SELECTED_GROUP | cut -d: -f1`" | tee -a $LOGFILE
try chown -R `id -u -n $UID`:`getent group $SELECTED_GROUP | cut -d: -f1` $DESTDIR
local FPMCHECK=`ps -ef | grep fpm | grep -v grep`
local APACHECHECK=`ps -ef | egrep 'apache|httpd|apache2' | grep -v egrep | grep -v grep`
if [ ${#FPMCHECK} -eq 0 ]; then
if [ ${#APACHECHECK} -gt 0 ]; then
echo "php_flag engine off" > $DESTDIR/wp-content/uploads/.htaccess
echo "==$INSTANCEID==Wrote htaccess file to uploads (mod_php style)" | tee -a $LOGFILE
try find $DESTDIR/wp-content/uploads/ -type d -exec chmod 770 '{}' \;
echo "==$INSTANCEID==Uploads directory set 770" | tee -a $LOGFILE
fi
elif [ ${#FPMCHECK} -gt 0 ]; then
if [ ${#APACHECHECK} -gt 0 ]; then
echo "Options -ExecCGI" > $DESTDIR/wp-content/uploads/.htaccess
echo "==$INSTANCEID==Wrote htaccess file to uploads (fpm style)" | tee -a $LOGFILE
try find $DESTDIR/wp-content/uploads/ -type d -exec chmod 770 '{}' \;
echo "==$INSTANCEID==Uploads directory set 770" | tee -a $LOGFILE
fi
else
echo "==$INSTANCEID==Apache not running, no htaccess written." | tee -a $LOGFILE
fi
echo "==$INSTANCEID==Checking special directories." | tee -a $LOGFILE
[ -d "$DESTDIR/wp-content/cache" ] && find $DESTDIR/wp-content/cache -type d -exec chmod 770 '{}' \;
[ -d "$DESTDIR/wp-content/w3tc-config" ] && find $DESTDIR/wp-content/w3tc-config -type d -exec chmod 770 '{}' \;
[ -d "$DESTDIR/cache" ] && find $DESTDIR/cache -type d -exec chmod 770 '{}' \;
[ -d "$DESTDIR/w3tc-config" ] && find $DESTDIR/w3tc-config -type d -exec chmod 770 '{}' \;
[ -d "$DESTDIR/stats" ] && chown -R stats $DESTDIR/stats
[ -d "$DESTDIR/wp-content/wflogs" ] && find $DESTDIR/wp-content/wflogs -type d -exec chmod 770 '{}' \;
[ -d "$DESTDIR/wp-content/wfcache" ] && find $DESTDIR/wp-content/wfcache -type d -exec chmod 770 '{}' \;
[ -d "$DESTDIR/wp-content/wflogs" ] && find $DESTDIR/wp-content/wflogs -type f -exec chmod 660 '{}' \;
echo "==$INSTANCEID==Permissions set complete." | tee -a $LOGFILE
} # END PERMISSIONS
+98
View File
@@ -0,0 +1,98 @@
#######################
# THE RENAME FUNCTION #
#######################
function rename() {
POSIT=();
while [[ $# -gt 0 ]]; do
KEY="$1"
case $KEY in
-o|--oldname) OLDNAME=$2; shift;;
-n|--newname) NEWNAME=$2; shift;;
-p|--path) DESTDIR=$2; shift;;
*) echo "$1 not implemented" ; POSIT+=("$1") ;;
esac
shift
done
set -- "${POSIT[@]}"
DESTDIR=${DESTDIR:-`pwd`}
if [ ! -d $DESTDIR ]; then
echo "$DESTDIR doesn't exist"
exit 1
fi
[ -f wp-config.php ] || echo "This isn't a wordpress installation."
[ -f wp-config.php ] || exit 1
local DATETIME=`date +%Y%m%d.%H%M`
echo "==WPM RENAME CALLED ON $DATETIME WITH VERSION $WPVERSION==" | tee -a $LOGFILE
echo "==UNIQUE IDENTIFIER $INSTANCEID==" | tee -a $LOGFILE
echo "==$INSTANCEID==Executing rename from $OLDNAME to $NEWNAME" | tee -a $LOGFILE
local DBNAME=`grep DB_NAME wp-config.php | awk -F "'" '{print $4}'`
echo "==$INSTANCEID==Database is $DBNAME" | tee -a $LOGFILE
if mysql "${DBNAME}" >/dev/null 2>&1 </dev/null; then
echo "==$INSTANCEID==${DBNAME} exists and I have access to it" | tee -a $LOGFILE
else
echo "==$INSTANCEID==$DBNAME doesn't exist, or I can't access it. Terminating." | tee -a $LOGFILE
exit 1
fi
echo "==$INSTANCEID==Doing DB transform" | tee -a $LOGFILE
try mysqldump $DBNAME --single-transaction > ${TEMPDIR}/${DBNAME}.${DATETIME}.sql
sed -i "s/${OLDNAME}/${NEWNAME}/g" ${TEMPDIR}/${DBNAME}.${DATETIME}.sql
try /usr/local/lib/fixserial.sh -o $OLDNAME -n $NEWNAME -f ${TEMPDIR}/${DBNAME}.${DATETIME}.sql
try mysql "$DBNAME" < $TEMPDIR/${DBNAME}.${DATETIME}.sql
try rm -fv ${TEMPDIR}/${DBNAME}.${DATETIME}.sql
echo "==$INSTANCEID==DB transform complete" | tee -a $LOGFILE
echo "==$INSTANCEID==Commencing file operations." | tee -a $LOGFILE
try cp -v $DESTDIR/wp-config.php $DESTDIR/.wp-config.php.$DATETIME.bak
if ! grep -q 'WP_HOME' $DESTDIR/wp-config.php; then
sed -i "s|\$table_prefix.*$|&\n define( 'WP_HOME', 'https://$NEWNAME' );|" $DESTDIR/wp-config.php
else
sed -i "s|^.*WP_HOME.*$|define( 'WP_HOME', 'https://$NEWNAME' );|" $DESTDIR/wp-config.php
fi
if ! grep -q 'WP_SITEURL' $DESTDIR/wp-config.php; then
sed -i "s|\$table_prefix.*$|&\n define( 'WP_SITEURL', 'https://$NEWNAME' );|" $DESTDIR/wp-config.php
else
sed -i "s|^.*WP_SITEURL.*$|define( 'WP_HOME', 'https://$NEWNAME' );|" $DESTDIR/wp-config.php
fi
WPTHEME=$(mysql -sN -e "select \`option_value\` from $DBNAME.\`wp_options\` where \`option_name\`='template';");
if [ -f $DESTDIR/wp-content/themes/$WPTHEME/functions.php ]; then
try cp -v $DESTDIR/wp-content/themes/$WPTHEME/functions.php $DESTDIR/wp-content/themes/$WPTHEME/.functions.php.$DATETIME.bak
sed -i "s|\<\?php$|&\n update_option( 'siteurl', 'https://$NEWNAME' );|" $DESTDIR/wp-content/themes/$WPTHEME/functions.php
sed -i "s|\<\?php$|&\n update_option( 'home', 'https://$NEWNAME' );|" $DESTDIR/wp-content/themes/$WPTHEME/functions.php
REMOVE_LINES="yes"
else
printf "%s\n%s\n%s\n%s" '<?php' "update_option( 'siteurl', 'https://$NEWNAME' );" "update_option( 'home', 'https://$NEWNAME' );" '?>' > $DESTDIR/wp-content/themes/$WPTHEME/functions.php
if [ -f $DESTDIR/wp-content/themes/$WPTHEME/functions.php ]; then
REMOVE_FILE="yes"
else
echo "==$INSTANCEID==Could not create functions.php in $DESTDIR/wp-content/themes/$WPTHEME/" | tee -a $LOGFILE
fi
fi
wget -O/dev/null -q --no-check-certificate https://$NEWNAME;
if [[ "$REMOVE_LINES" == "yes" ]]; then
sed -i 's/^update_option.*$//' $DESTDIR/wp-content/themes/$WPTHEME/functions.php
elif [[ "$REMOVE_FILE" == "yes" ]]; then
if [ -f $DESTDIR/wp-content/themes/$WPTHEME/functions.php ]; then
rm -f $DESTDIR/wp-content/themes/$WPTHEME/functions.php
fi
fi
echo "==$INSTANCEID==File operations complete." | tee -a $LOGFILE
echo "==$INSTANCEID==Rename of $OLDNAME to $NEWNAME complete" | tee -a $LOGFILE
} # END RENAME
+33
View File
@@ -0,0 +1,33 @@
#########################
# THE SETTINGS FUNCTION #
#########################
function settings() {
if [[ "$1" == "list" ]]; then
try egrep -v '^#.*$' /usr/local/etc/wpm/wpm.conf | egrep -v '^$'
exit 0
fi
[ -z "$1" ] && echo "please provide a setting"
[ -z "$1" ] && exit 1
local DATETIME=`date +%Y%m%d.%H%M`
echo "==WPM SETTINGS CALLED ON $DATETIME WITH VERSION $WPVERSION==" | tee -a $LOGFILE
echo "==UNIQUE IDENTIFIER $INSTANCEID==" | tee -a $LOGFILE
echo "==$INSTANCEID==Executing settings on /usr/local/etc/wpm/wpm.conf" | tee -a $LOGFILE
try cp -v /usr/local/etc/wpm/wpm.conf /usr/local/etc/wpm/wpm.${DATETIME}.bak
echo "==$INSTANCEID==Backup of wpm.conf made @ /usr/local/etc/wpm/wpm.${DATETIME}.bak" | tee -a $LOGFILE
for VAR in "$@"; do
MATCH=`echo $VAR | awk -F '=' '{print $1}'`
echo "${VAR}"
try sed -i "s/^${MATCH}.*/${VAR}/g" /usr/local/etc/wpm/wpm.conf
done
echo "==$INSTANCEID==Settings function complete." | tee -a $LOGFILE
} # END SETTINGS
+109
View File
@@ -0,0 +1,109 @@
#######################
# THE UPDATE FUNCTION #
#######################
function update() {
POSIT=();
while [[ $# -gt 0 ]]; do
KEY="$1"
case $KEY in
-b|--backup) BACKUP="yes" ;;
-g|--plugins) PLUGINS="yes" ;;
-s|--skip-ftp) SKIPFTP="yes" ;;
-p|--path) DESTDIR=$2 ; shift ;;
*) echo "$1 not implemented" ; POSIT+=("$1") ;;
esac
shift
done
set -- "${POSIT[@]}";
BACKUP="${BACKUP:-no}"
PLUGINS="${PLUGINS:-no}"
DESTDIR="${DESTDIR:-`pwd`}"
SKIPFTP="${SKIPFTP:-no}"
[ -d $DESTDIR ] || exit 1
cd $DESTDIR
if [ "${BACKUP}" == "yes" ]; then
backup --path $DESTDIR --skip-uploads
fi
[ -f wp-config.php ] || echo "this isn't a wordpress installation"
[ -f wp-config.php ] || exit 1
local DATETIME=`date +%Y%m%d.%H%M`
echo "==WPM UPDATE CALLED ON $DATETIME WITH VERSION $WPMVERSION==" | tee -a $LOGFILE
echo "==UNIQUE IDENTIFIER $INSTANCEID==" | tee -a $LOGFILE
echo "==$INSTANCEID==Executing update on $DESTDIR" | tee -a $LOGFILE
echo "==$INSTANCEID==Checking $TEMPDIR/wp-installer" | tee -a $LOGFILE
[ -d $TEMPDIR/wp-installer ] || mkdir -p $TEMPDIR/wp-installer
echo "==$INSTANCEID==Removing old versions" | tee -a $LOGFILE
find $TEMPDIR/wp-installer/ -mtime +1 -name wordpress.latest.tar -exec rm -fv '{}' \;
if [ -e $TEMPDIR/wp-installer/wordpress.latest.tar ]; then
echo "==$INSTANCEID==Recent version already present" | tee -a $LOGFILE
else
try wget -O $TEMPDIR/wp-installer/wordpress.latest.tar.gz https://wordpress.org/latest.tar.gz --no-check-certificate &> /dev/null
try touch $TEMPDIR/wp-installer/wordpress.latest.tar.gz
try gunzip $TEMPDIR/wp-installer/wordpress.latest.tar.gz &> /dev/null
echo "==$INSTANCEID==Recent version downloaded" | tee -a $LOGFILE
fi
if [ ! -e $TEMPDIR/wp-installer/wordpress.latest.tar ]; then
echo "==$INSTANCEID==Cannot get archive at $TEMPDIR/wp-installer/" | tee -a $LOGFILE
exit 1
fi
if tar -f $TEMPDIR/wp-installer/wordpress.latest.tar -x --strip-components=1; then
echo "==$INSTANCEID==Extracting Wordpress in $DESTDIR complete" | tee -a $LOGFILE
else
echo "==$INSTANCEID==Extracting Wordpress in $DESTDIR failed, trying with legacy tar options" | tee -a $LOGFILE
if tar -f $TEMPDIR/wp-installer/wordpress.latest.tar -x --strip-path=1; then
echo "==$INSTANCEID==Extracting Wordpress in $DESTDIR complete" | tee -a $LOGFILE
else
echo "==$INSTANCEID==Extracting Wordpress completely failed in $DESTDIR" | tee -a $LOGFILE
exit 1
fi
fi
if [ "${PLUGINS}" == "yes" ]; then
PLUGINLIST=$(find wp-content/plugins/ -maxdepth 1 -type d | sed 's#wp-content/plugins/##')
for PLUGINNAME in $PLUGINLIST; do
curl -L -k -s http://api.wordpress.org/plugins/info/1.0/$PLUGINNAME.xml | grep download_link | cut -c40- | sed s/\].*// >> $TEMPDIR/plugin_update.list
done
for FILE in $(cat $TEMPDIR/plugin_update.list); do
curl -L -k -s -o $TEMPDIR/tmp.zip $FILE
unzip -qq -o $TEMPDIR/tmp.zip -d wp-content/plugins/
rm /tmp/tmp.zip
done
rm -f $TEMPDIR/plugin_update.list
THEMELIST=$(find wp-content/themes/ -maxdepth 1 -type d | sed 's#wp-content/themes/##')
for THEMENAME in $THEMELIST; do
THEMENAMELENGTH=$(echo $THEMENAME | wc -c)
THEMENAMELENGTH=$(($THEMENAMELENGTH-1))
curl -L -k -s -d 'action=theme_information&request=O:8:"stdClass":1:{s:4:"slug";s:'$THEMENAMELENGTH':"'$THEMENAME'";}' http://api.wordpress.org/themes/info/1.0/ |sed -n 's|.*http\(.*\)zip.*|http\1zip\n|p' >> $TEMPDIR/theme_update.list
done
for FILE in $(cat $TEMPDIR/theme_update.list); do
curl -L -k -s -o $TEMPDIR/tmp.zip $FILE
unzip -qq -o $TEMPDIR/tmp.zip -d wp-content/themes/
rm $TEMPDIR/tmp.zip
done
fi
if [[ "$SKIPFTP" == "no" ]]; then
echo "==$INSTANCEID==Running permissions" | tee -a $LOGFILE
permissions $DESTDIR
elif [[ "$SKIPFTP" == "yes" ]]; then
echo "==$INSTANCEID==Permission setting skipped." | tee -a $LOGFILE
fi
echo "==$INSTANCEID==Update complete" | tee -a $LOGFILE
} # END UPDATE
+112
View File
@@ -0,0 +1,112 @@
##############
# WPM VERIFY #
##############
function verify() {
POSIT=();
while [[ $# -gt 0 ]]; do
KEY="$1"
case $KEY in
-s|--scan) SCAN="yes" ;;
-m|--md5) HASH="yes" ;;
-b|--backup) BACKUP="yes" ;;
-r|--replace) REPLACE="yes" ;;
-p|--path) DESTDIR="$2" ; shift ;;
*) echo "$1 not implemented" ; POSIT+=("$1") ;;
esac
shift
done
set -- "${POSIT[@]}";
SCAN="${SCAN:-no}"
HASH="${HASH:-no}"
BACKUP="${BACKUP:-no}"
REPLACE="${REPLACE:-no}"
DESTDIR="${DESTDIR:-`pwd`}"
local DATETIME=`date +%Y%m%d.%H%M`
[ -d $DESTDIR ] || echo "directory $DIR does not exist"
[ -d $DESTDIR ] || exit 1
cd $DESTDIR
[ -f wp-config.php ] || echo "this isn't a wordpress installation"
[ -f wp-config.php ] || exit 1
echo "==WPM VERIFY CALLED ON $DATETIME WITH VERSION $WPMVERSION==" | tee -a $LOGFILE
echo "==UNIQUE IDENTIFIER $INSTANCEID==" | tee -a $LOGFILE
echo "==$INSTANCEID==Executing verify on $DESTDIR" | tee -a $LOGFILE
if [ "$BACKUP" == "yes" ]; then
backup -p $DESTDIR -s
fi
##################
# MD5 COMPARISON #
##################
if [ "$HASH" == "yes" ]; then
# FIRST, GET THE LOCALLY INSTALLED VERSION
local VERSION=`grep '$wp_version =' $DESTDIR/wp-includes/version.php | cut -f 2 -d '=' | cut -f 2 -d "'"`
[ -z $VERSION ] && echo "Could not determine the WP version"
[ -z $VERSION ] && exit 1
echo "==$INSTANCEID==Hash called on WP version $VERSION" | tee -a $LOGFILE
# MAKE OUR DIRECTORY FOR WORK
try mkdir -p $TEMPDIR/verify/$VERSION
# GET THE VERSION FROM WP
try wget -O $TEMPDIR/verify/wordpress.$VERSION.tgz https://wordpress.org/wordpress-$VERSION.tar.gz --no-check-certificate &> /dev/null
echo "==$INSTANCEID==Successfully got $TEMPDIR/verify/wordpress.$VERSION.tgz" | tee -a $LOGFILE
# LET'S EXTRACT IT
try tar -xzf $TEMPDIR/verify/wordpress.$VERSION.tgz -C $TEMPDIR/verify/$VERSION/
# MD5 THE VERSION FROM WP
find $TEMPDIR/verify/$VERSION/wordpress/ -type f -exec md5sum {} \; > $TEMPDIR/verify/$VERSION/record.lst
# MD5 THE VERSION CURRENTLY INSTALLED
find . -type f -exec md5sum {} \; > $TEMPDIR/verify/$VERSION/installed.lst
while read LINE; do
RECORD_FIELD_1=`echo $line | cut -f 1 -d ' '`
RECORD_FIELD_2=`echo $line | cut -f 2 -d ' '`
WP_FILE=`echo $RECORD_FIELD_2 | rev | cut -d '/' -f 1 | rev`
INSTALLED_FIELD_1=`grep "$WP_FILE" $TEMPDIR/verify/$VERSION/installed.lst | cut -f 1 -d ' '`
INSTALLED_FIELD_2=`grep "$WP_FILE" $TEMPDIR/verify/$VERSION/installed.lst | cut -f 2 -d ' '`
if [ "$RECORD_FIELD_1" != "$INSTALLED_FIELD_1" ]; then
echo "==$INSTANCEID==$WP_FILE DIFFERENCE DETECTED!" | tee -a $LOGFILE
echo "==$INSTANCEID==DEBUG OUTPUT: record $RECORD_FIELD_2; installed $INSTALLED_FIELD_2" | tee -a $LOGFILE
echo "==$INSTANCEID==DEBUG OUTPUT: md5 record $RECORD_FIELD_1; md5 installed $INSTALLED_FIELD_1" | tee -a $LOGFILE
if [ "$REPLACE" == "yes" ] && [[ ! "${INSTALLED_FIELD_2}" != *"wp-config.php"* ]]; then
try cp $RECORD_FIELD_2 ./$INSTALLED_FIELD_2
echo "==$INSTANCEID==$RECORD_FIELD_2 replaced $INSTALLED_FIELD_2" | tee -a $LOGFILE
fi
fi
done <$TEMPDIR/verify/$VERSION/record.lst
rm -rf $TEMPDIR/verify/$VERSION
fi # END IF HASH
##################
# VIRUS SCANNING #
##################
if [ "$SCAN" == "yes" ]; then
if maldet 1>/dev/null; then
try maldet -u
echo "==$INSTANCEID==Maldet DB updated" | tee -a $LOGFILE
if [ "$REPLACE" == "yes" ]; then
maldet --config-option scan_clamscan=1,quarantine_hits=1
echo "==$INSTANCEID==Maldet config with quarantine" | tee -a $LOGFILE
else
maldet --config-option scan_clamscan=1,quarantine_hits=0
echo "==$INSTANCEID==Maldet config without quarantine" | tee -a $LOGFILE
fi # END IF REPLACE
maldet -a $DESTDIR
echo "==$INSTANCEID==Maldet run on $DESTDIR" | tee -a $LOGFILE
else
echo "==$INSTANCEID==Maldet could not run, because not installed" | tee -a $LOGFILE
fi # END IF MALDET
fi # END IF SCAN
echo "==$INSTANCEID==Verify complete at `date +%Y%m%d.%H%M`" | tee -a $LOGFILE
}