add function to install wordpress

This commit is contained in:
2015-07-10 22:57:41 +03:00
parent f0746e3178
commit bb6b98a748
2 changed files with 95 additions and 1 deletions

View File

@@ -37,7 +37,7 @@ PASS=$(cat "$3")
## FUNCTIONS
function checkaction {
REGEX="^adduser$|^changepw$|^listusers$|^userdetail$|^deluser$|^sizeall$|^sizeuser$|^viewdata$|^addalias$|^quota$"
REGEX="^adduser$|^changepw$|^listusers$|^userdetail$|^deluser$|^sizeall$|^sizeuser$|^viewdata$|^addalias$|^quota$|^installwp$"
if [[ $1 =~ $REGEX ]]; then
echo "true"
else
@@ -222,6 +222,11 @@ if [ "$ACTION" == "addalias" ]; then
DEST=$PASS
if ! $(checkuser "$USER"); then
echo "Username \"$USER\" invalid"
exit 1
fi
if $(userexists "$USER"); then
echo "User \"$USER\" does already exist!"
exit 1
@@ -382,3 +387,69 @@ if [ "$ACTION" == "deluser" ]; then
fi
fi # /deluser
# # # # #
# INSTALL WORDPRESS
# # # # #
if [ "$ACTION" == "installwp" ]; then
echo "Installing WordPress..."
echo
# $USER: Username for Wordpress
# $PASS: Email address for Wordpress user
if ! $(checkuser "$USER"); then
echo "Username \"$USER\" invalid"
exit 1
fi
WEBDIR=$HOME/html
WPUSER=$USER
WPPASS=$(apg -n 1 -M NCL -m 14)
WPMAIL=$PASS
WPDOMAIN=http://$DOMAIN
# Get MySQL password
LEAD='## > MYSQL'
TAIL='## < MYSQL'
MYSQLUSER=$SYSUSER
MYSQLDB=${MYSQLUSER}_wp
MYSQLPASS=$(sed -n "/$LEAD/,/$TAIL/ p" $NOTES | grep "^Pass:" | awk -F" " '{ print $2 }')
# Check if ready for install: WEBDIR empty, Database available
if [ $(ls -a $WEBDIR | wc -l) -gt 2 ]; then
echo "The website directory \"$WEBDIR\" doesn't seem to be empty."
exit 1
fi
if [ $(mysql -e "SHOW DATABASES;" | tr -d "| " | grep -v Database | grep "^$$WPDB$" ; echo $?) = 0 ]; then
echo "The default database \"${USER}_wp\" already exists."
exit 1
fi
# Downloading wordpress
wget https://wordpress.org/latest.tar.gz
tar xfz latest.tar.gz
mv wordpress/* $WEBDIR
rm -r wordpress latest.tar.gz
# Downloading wp-cli
curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
chmod +x wp-cli.phar
mv wp-cli.phar $HOME/bin/
# Create database
mysql -e "CREATE DATABASE $WPDB;"
# Use wp-cli to create config.php and install WP
wp core config --dbname=${MYSQLDB} --dbpass=${MYSQLPASS} --dbuser=${MYSQLUSER} --path=${WEBDIR}
wp core install --url="$WPDOMAIN" --title="CHANGE THIS TITLE" --admin_user=${WPUSER} --admin_password=${WPPASS} --admin_email=${WPMAIL} --path=${WEBDIR}
# Update datasheet
TAIL='## < WORDPRESS'
sed -i "/$TAIL/i User: $WPUSER\nPass: $WPPASS\n" $NOTES
echo "Wordpress successfully installed to $WPDOMAIN"
echo "You can login on $WPDOMAIN/wp-login.php"
echo "Please take a look into your data sheet for the login data."
fi # /installwp

View File

@@ -164,6 +164,29 @@
<button type="submit" name="action" value="deluser">Delete account</button>
</form>
</div> <!-- /hide -->
<!--
WEB SECTION
-->
<p><strong>Web Applications</strong></p>
<!-- INSTALLWP - Install an empty WordPress -->
<b class="switch"><span class="turn_on">&#187;</span><span class="turn_off">&#171;</span> Install WordPress automatically</b>
<div class="hide">
<p>This install WordPress for your automatically. It only works if
your website directory is still empty and you didn't create a
database called #&lt;yourusername#&gt;_wp.</p>
<form action="submit.php" method="post">
<label>Desired WordPress login name:</label>
<input name="user" title="WordPress Login" />
<label>Your full email address:</label>
<input name="pass" title="Email address" />
<br />
<button type="submit" name="action" value="installwp">Install WordPress</button></button>
<!-- Hidden confirmation box -->
<input type="hidden" name="sure" value="yes" />
</form>
</div> <!-- /hide -->
</div> <!-- /gallery -->