The idea is to automate WordPress installs via Plesk.
I've got Plesk setup with a cronjob to download the latest.tar.gz from wordpress.com and extract it every morning and now I'm trying to get the database creation side of things automated.
I have the following bash script:
#!/bin/bash/
#To whoever is working on this
#this script simply sets up the DATABASE for the new domain added to the server
#it then logs it, mails the details and clears the log
genpasswd() {
local pass=`cat /dev/urandom | tr -cd "[:punct:]" | head -c 2`
echo "$pass"
}
echo $NEW_DOMAIN_NAME >> /usr/games/newdomain.txt
DOMAINNAME=`echo $NEW_DOMAIN_NAME | grep -oE '/[^/]+' | cut -c6- | rev | cut -c4- | rev`
rndChr=$(genpasswd)
CHAR2=${$DOMAINNAME:1:1}
CHAR4=${$DOMAINNAME:3:1}
echo $CHAR2$CHAR4 >> /usr/games/passChar.txt
#get our db stuff
DATABASENAME='exsite_'$DOMAINNAME
DATABASEUSER='exsite_'$DOMAINNAME
DATABASEPASS='[exSite_'$CHAR2$rndChr$CHAR4']'
#create our mail content
CONTENTS="<strong>New MySQL Database created</strong> - <i>see the login details below.<i><p><strong>dbname</strong> $DATABASENAME<br><strong>dbuser</strong> $DATABASEUSER<br><strong>dbpass<strong> $DATABASEPASS"
#log it
echo -e $CONTENTS > /usr/games/dbLog.txt
#mail it
sendMail() {
cat << 'EOF' - /usr/games/dbLog.txt | /usr/sbin/sendmail -t
To: [email protected]
From: Enterprise
Reply-to: [email protected]
Subject: [DB Info] for $NEW_DOMAIN_NAME on enterprise.exsite.co
Content-Type: text/html
EOF
printf "STATUS: Mail sent!"
}
if [[ $(sendMail) ]]
then
printf "STATUS: Doing mail thing!"
else
printf "STATUS: MAIL-FAIL!!"
fi
#clear dbLog.txt
exit
Two problems are occuring but I don't understand why;
The CHAR2 and CHAR4 variables don't seem to pick up the 2nd and 4th characters of $DOMAINNAME - they just output empty into passChat.txt
$NEW_DOMAIN_NAME goes to newdomain.txt but then the next line where I try to return just the 2nd level domain seems to fail. It was working at an earlier point but it's not now. I hadn't changed that part though.
CHAR2=${DOMAINNAME:1:1}
$NEW_DOMAIN_NAME
look like? I can't really grok what that grep|cut|rev|... line is supposed to do