Last active
December 16, 2015 05:09
-
-
Save richardsweeney/5382003 to your computer and use it in GitHub Desktop.
Install latest WordPress, setup database, get latest ölab starter theme, commit it all to gitlab, setup virtual host, makes you a coffee (ok not the last one)
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
#!/bin/bash | |
# Initializes a git repo & adds gitlab repo as origin. | |
# For this to work the directory contining the repo has | |
echo "Enter the directory/database directory name:" | |
read directory | |
basedir="/Users/richardsweeney/s/" | |
MYSQL=`which mysql` | |
SQLCREATE="CREATE DATABASE IF NOT EXISTS $directory;" | |
TEMP_FILE="out.tmp" | |
DB_NAME="$directory" | |
DB_USER="root" | |
DB_PASSWORD="root" | |
DB_HOST="localhost" | |
#See if the database exists | |
RESULT=`mysqlshow --user=root --password=root $directory| grep -v Wildcard | grep -o $directory` | |
if [ "$RESULT" == "$directory" ]; then | |
echo "A database with that name already exists" | |
else | |
"$MYSQL" -uroot --password=root -e "$SQLCREATE" | |
echo '' | |
echo '*********************************************************' | |
echo '' | |
echo "=> The database $directory has been successfully created" | |
echo '' | |
echo '*********************************************************' | |
echo '' | |
fi | |
#Create a directory if it doesn't exist | |
if [ -d "$basedir$directory" ]; then | |
echo '' | |
echo '*********************************************************' | |
echo '' | |
echo "WOAH! A directory named '$directory' already exists!" | |
echo 'This installer will now exit, please remove or rename the directory and re-run the installer.' | |
echo '' | |
echo '*********************************************************' | |
echo '' | |
exit 0 | |
else | |
mkdir $basedir$directory && cd $basedir$directory && curl http://wordpress.org/latest.tar.gz | tar xvz && mv wordpress/* . | |
rm -R wordpress | |
rm license.txt | |
rm readme.html | |
echo '' | |
echo '*********************************************************' | |
echo '' | |
echo '=> Gotcha!' | |
echo '' | |
echo '*********************************************************' | |
echo '' | |
fi | |
echo '' | |
echo '*********************************************************' | |
echo '' | |
echo '=> Fetching .gitignore' | |
echo '' | |
echo '*********************************************************' | |
echo '' | |
git clone https://gist.github.com/5292478.git gitignore && mv gitignore/.gitignore . && sudo rm -R gitignore/ | |
echo '' | |
echo '*********************************************************' | |
echo '' | |
echo '=> Configuring wp-config.php' | |
echo '' | |
echo '*********************************************************' | |
echo '' | |
# Setup wp-config.php | |
cp wp-config-sample.php wp-config.php | |
touch $TEMP_FILE | |
# Set database connection | |
DB_DEFINES=( 'DB_NAME' 'DB_USER' 'DB_PASSWORD' 'DB_HOST' ) | |
for DB_PROPERTY in ${DB_DEFINES[@]} ; | |
do | |
OLD="define('$DB_PROPERTY', '.*')" | |
NEW="define('$DB_PROPERTY', '${!DB_PROPERTY}')" # Will probably need some pretty crazy escaping to allow for better passwords | |
sed "s/$OLD/$NEW/g" wp-config.php > $TEMP_FILE && mv $TEMP_FILE wp-config.php | |
done | |
#Fix permissions + owership | |
sudo chown -R richardsweeney:admin * | |
echo '' | |
echo '*********************************************************' | |
echo '' | |
echo '=> Wordpress has been succesfully installed and configured' | |
echo '' | |
echo '*********************************************************' | |
echo '' | |
echo "127.0.0.1 $directory.dev" >> /etc/hosts | |
cat >> /Applications/MAMP/conf/apache/httpd.conf <<EOL | |
<VirtualHost *> | |
ServerName ${directory}.dev | |
DocumentRoot "/Applications/MAMP/htdocs/${directory}" | |
</VirtualHost> | |
EOL | |
echo "Initialize git (yes or no)?" | |
read bool | |
if [ "$bool" == 'yes' ]; then | |
git init | |
git add . | |
git commit -m 'Initial commit'; | |
echo "Add the gitlab repo name (eg reponame.git)" | |
read reponame | |
git remote add origin [email protected]:richard.sweeney/$reponame | |
git push -u origin master | |
echo '' | |
echo '*********************************************************' | |
echo '' | |
echo '=> Succesfully pushed to gitlab' | |
echo '' | |
echo '*********************************************************' | |
echo '' | |
fi | |
echo "Do you want to add the Örestad Linux starter theme 'for fun and profit®' (yes or no)?" | |
read olabTheme | |
if [ "$olabTheme" == 'yes' ]; then | |
git clone [email protected]:richard.sweeney/wordpress-base-theme.git $basedir$directory/wp-content/themes/$directory-theme | |
sudo rm -R $basedir$directory/wp-content/themes/$directory-theme/.git | |
git add . | |
git commit -m 'Added theme to git' | |
git push origin master | |
echo '' | |
echo '*********************************************************' | |
echo '' | |
echo '=> Starter theme added' | |
echo '' | |
echo '*********************************************************' | |
echo '' | |
fi | |
echo "Add stage as git remote (yes or no)?" | |
read stageBool | |
if [ "$stageBool" == 'yes' ]; then | |
echo "Enter the name of the remote directory on stage" | |
read stageDir | |
git remote add stage ssh://[email protected]/stage/www/$stageDir | |
git push -u stage master | |
echo '' | |
echo '*********************************************************' | |
echo '' | |
echo '=> Succesfully added and pushed to stage' | |
echo '' | |
echo '*********************************************************' | |
echo '' | |
fi | |
# Restart Apache | |
/Applications/MAMP/bin/apache2/bin/apachectl graceful | |
# Open in sublime | |
subl $basedir$directory |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment