-
-
Save jstnbr/8a084fd52488a4c6514879fa6f2882e6 to your computer and use it in GitHub Desktop.
WordPress Development Script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# wordpress-dev.sh | |
# | |
# Copyright 2012 Frank Lewandowski <[email protected]> | |
# | |
# This program is free software; you can redistribute it and/or modify | |
# it under the terms of the GNU General Public License as published by | |
# the Free Software Foundation; either version 2 of the License, or | |
# (at your option) any later version. | |
# | |
# This program is distributed in the hope that it will be useful, | |
# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
# GNU General Public License for more details. | |
# | |
# You should have received a copy of the GNU General Public License | |
# along with this program; if not, write to the Free Software | |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, | |
# MA 02110-1301, USA. | |
# | |
# @TODO | |
# v.2 alpha - live testing the script with different projects | |
# v.3 - include ${SITEPATH} | |
# v.3 - Bugfixes, Testing | |
# | |
#!/bin/bash | |
choice=4 | |
echo "" | |
echo "##################################" | |
echo "## WordPress Development Script ##" | |
echo "## by Frank Lewandowski ##" | |
echo "## v.2 Alpha ##" | |
echo "##################################" | |
echo "" | |
echo "1. Create Project" | |
echo "2. Create Database" | |
echo "3. Edit Hosts" | |
echo "0. Exit the Script" | |
echo -n "Please choose your option: " | |
while [ $choice -eq 4 ] ; do | |
read choice | |
# ------------------------------------------------------- | |
# 1. Create Project | |
if [ $choice -eq 1 ] ; then | |
# ------------------------------------------------------- | |
# Get Projectname | |
echo "" | |
echo -n "Your Projectname (.local is included): " | |
read PROJECTNAME | |
# ------------------------------------------------------- | |
# Make Projectfdolder | |
mkdir /var/www/${PROJECTNAME}.local | |
echo "" | |
echo "Create folder /var/www/${PROJECTNAME}.local" | |
# ------------------------------------------------------- | |
# Copy latest WordPress Files | |
echo "" | |
echo "Copying WordPress Files from wordpress.org" | |
echo "Please be patient." | |
echo "" | |
wget -q http://wordpress.org/latest.zip | |
# ------------------------------------------------------- | |
# Unzip WordPress Files | |
echo "Unzipping files" | |
echo "" | |
unzip -q latest.zip | |
sleep 5 | |
# ------------------------------------------------------- | |
#Copy Files to Projectfolder | |
echo "Copying Files to Projectfolder" | |
echo "" | |
cp -r wordpress/* /var/www/${PROJECTNAME}.local | |
sleep 5 | |
# ------------------------------------------------------- | |
# Cleanup | |
echo "Cleaning up files" | |
echo "" | |
rm -r latest.zip | |
rm -r wordpress/ | |
# ------------------------------------------------------- | |
# Finish Create Project | |
echo "Project ${PROJECTNAME} created! Site path /var/www/${PROJECTNAME}.local" | |
else | |
# ------------------------------------------------------- | |
# 2. Create Database | |
if [ $choice -eq 2 ] ; then | |
echo "" | |
echo -n "Name of the Database: " | |
read DATABASE | |
echo -n "Database User: " | |
read USER | |
echo -n "Database Password: " | |
read PASSWORD | |
mysql -u${USER} -p${PASSWORD} -e "create database ${DATABASE};" | |
else | |
# ------------------------------------------------------- | |
# 3. Edit Hosts and Virtualhost | |
if [ $choice -eq 3 ] ; then | |
echo "" | |
echo -n "Name of your Host: (.local is included): " | |
read HOST | |
# ------------------------------------------------------- | |
# Backup /etc/hosts | |
echo "" | |
echo "Backup /etc/hosts /etc/hosts.original" | |
sudo cp /etc/hosts /etc/hosts.original | |
sudo sh -c "echo '127.0.0.1\t${HOST}.local' >> /etc/hosts" | |
# ------------------------------------------------------- | |
# Finish Create Host | |
echo "" | |
echo "Writing ${HOST}.local to /etc/hosts" | |
sleep 1 | |
# ------------------------------------------------------- | |
# Edit httpd-vhost.conf | |
echo "" | |
echo "Creating Apache VirtualHost" | |
# ------------------------------------------------------- | |
# Backup /etc/apache2/httpd-vhosts.conf | |
echo "" | |
echo "Backup httpd-vhosts.conf with conf.original " | |
VHOSTSFILE="/etc/apache2/sites-available/default" | |
sudo cp $VHOSTSFILE ${VHOSTSFILE}.original | |
sudo sh -c "echo '<VirtualHost *:80>' >> $VHOSTSFILE" | |
sudo sh -c "echo '\tDocumentRoot /var/www/${HOST}.local' >> $VHOSTSFILE" | |
sudo sh -c "echo '\tServerName ${HOST}.local' >> $VHOSTSFILE" | |
sudo sh -c "echo '\tServerAlias ${HOST}.localhost' >> $VHOSTSFILE" | |
sudo sh -c "echo '</VirtualHost>' >> $VHOSTSFILE" | |
# ------------------------------------------------------- | |
# Restart Apache | |
echo "" | |
echo "Restarting the Apache Webserver" | |
sudo service apache2 restart | |
# ------------------------------------------------------- | |
# Finish Edit httpd-vhost.conf | |
echo "" | |
echo "Virtual Host ${HOST}.local successfully created!" | |
else | |
# ------------------------------------------------------- | |
# 4. Exit | |
if [ $choice -eq 0 ] ; then | |
echo "" | |
echo "Have a nice day ;-)" | |
exit 0 | |
else | |
# ------------------------------------------------------- | |
# ON ERROR | |
echo "" | |
echo "ERROR!!! CHOOSE BETWEEN OPTION 1,2,3 or 0" | |
echo "" | |
echo "1. Create Project" | |
echo "2. Create Database" | |
echo "3. Edit Hosts and Virtualhost" | |
echo "0. Exit the Script" | |
echo -n "Please choose your option: " | |
choice=4 | |
# ------------------------------------------------------- | |
# Finish | |
fi | |
fi | |
fi | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment