Created
March 2, 2014 18:33
-
-
Save lukaswhite/9311300 to your computer and use it in GitHub Desktop.
A Bash Script for New projects
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
# CONFIGURATION | |
#MYSQL credentials | |
MYSQL_USER="root" | |
MYSQL_PASS="" | |
# The user Apache runs as - e.g. _www, www-data | |
APACHE_RUNAS="_www" | |
#Bitbucket credentials | |
BB_USER="USERNAME" | |
BB_PASS="PASSWORD" | |
#Hostname TLD - e.g. .local, .dev | |
HOSTNAME_TLD=".local" | |
#Slugs are generated by replacing spaces with... (e.g. a dash, or underscore) | |
space_replace_char='-' | |
# CONFIGURATION ENDS | |
# Ask the user for a project name | |
echo "Please enter the project name:" | |
read name | |
# Generate a default slug, e.g. a-project-named-something | |
default_slug=$(echo "$name" | tr A-Z a-z ) | |
default_slug=$(echo "$default_slug" | tr ' ' "$space_replace_char") | |
# Allow the user to override the generated slug | |
echo "Enter the slug, or enter to accept the default: "$default_slug | |
read slug | |
if [ "$slug" = "" ]; then | |
slug=$default_slug | |
fi | |
echo "Using "$slug" as the slug" | |
# Assign the variables | |
host=$slug".local" | |
# Create a project directory | |
directory="/var/www/"$slug | |
# Generate a database name | |
database=$(echo "$name" | tr A-Z a-z ) | |
database=$(echo $database | tr -d ' ') | |
echo "Creating directory "$directory | |
# Create the directory | |
sudo mkdir $directory | |
# Change ownership | |
sudo chown -R $USER:$APACHE_RUNAS $directory | |
echo "Creating virtual host "$host | |
# Create the entry in hosts | |
echo "127.0.0.1\t\t$host\n" >> /etc/hosts | |
# Append the virtual host entry | |
echo "<VirtualHost *:80>\nServerName $host\nDocumentRoot $directory\n\n\t<Directory />\n\t\tAllowOverride All\n\t\tRewriteEngine On\n\t\tRewriteBase /\n\t</Directory>\n\n</VirtualHost>" >> /etc/apache2/extra/httpd-vhosts.conf | |
echo "Creating database "$database | |
# Create a temporary file to create a database schema | |
echo "create database $database;" > temp.sql | |
# Create the schema; of course we'll have to stop and ask for the DB password | |
if [ "$MYSQL_PASS" = "" ]; then | |
mysql -u$MYSQL_USER < temp.sql | |
else | |
mysql -u$MYSQL_USER -p$MYSQL_PASS < temp.sql | |
fi | |
# Remove the temporary SQL file | |
rm temp.sql | |
# Create the git repo | |
curl -u$BB_USER:$BB_PASS -X POST https://api.bitbucket.org/1.0/repositories -d "name=$slug" -d 'is_private=1' -d 'scm=git' | |
# Change into the new project directory | |
cd $directory | |
# Run Git init... | |
git init | |
# ...and point it to Bitbucket | |
git remote add origin ssh://git@bitbucket.org/$BB_USER/$slug.git | |
# Create the Sublime Project | |
echo '{\n\t"folders":\n\t[\n\t\t{\n\t\t\t"path": "'$directory'"\n\t\t}\n\t]\n}' > ~/$name.sublime-project | |
echo "Finished." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
More details in the accompanying blog post.