#!/bin/bash

HOME__DIR="/home/dustin"
SITES_DIR="/var/www"
NGINX_DIR="/etc/nginx/sites-enabled/"
SERVER_IP="54.201.110.209"
clear
echo "======================================================="
echo "======================================================="
echo "======================================================="
echo "Enter a name for your site: (i.e. www.srk9.com )"
read SITENAME
echo "======================================================="
SITE="$SITES_DIR/$SITENAME"
echo "Creating site directory: $SITE"
mkdir $SITE
touch $SITE/index.html
echo $SITENAME>>$SITE/index.html

echo "Creating nginx site configuration file..."
NGINX_CONFIG_FILE="$NGINX_DIR/$SITENAME"
touch $NGINX_CONFIG_FILE
echo 'server{'  >>$NGINX_CONFIG_FILE
echo '  listen 80;'>>$NGINX_CONFIG_FILE
echo "  server_name $SITENAME;">>$NGINX_CONFIG_FILE
echo '  location / {'>>$NGINX_CONFIG_FILE
echo "    root $SITES_DIR/$SITENAME;">>$NGINX_CONFIG_FILE
echo "    index index.html;">>$NGINX_CONFIG_FILE
echo '  }'>>$NGINX_CONFIG_FILE
echo '}'>>$NGINX_CONFIG_FILE

echo "======================================================="
echo "Restarting NGINX..."
sudo service nginx restart
cd /home/git
REPO_NAME="$SITENAME.git"
sudo mkdir $REPO_NAME
cd $REPO_NAME
sudo git init --bare
#sudo echo "Push the site into production by: git push origin master" > $REPO_NAME/README
cd ../
sudo chown -R git:git $REPO_NAME 
#cd $SITE 
#git init
#echo "node_modules" > .gitignore
#echo "======================================================="
#echo "======================================================="
#echo "======================================================="
#echo "======================================================="
#echo "Copying config files"
#sudo cp $UPSTART_CONFIG_FILE /etc/init/$APPNAME.conf

#sudo cp $NGINX_CONFIG_FILE /etc/nginx/sites-available/$APPNAME
#sudo ln -s /etc/nginx/sites-available/$APPNAME /etc/nginx/sites-enabled/$APPNAME
#echo "Starting demaon"
#sudo service $APPNAME start
#echo "Restarting nginx"
#sudo service nginx restart
echo "======================================================="
echo "Done! Now you can download the app and start building!"
echo "======================================================="
echo
echo "Final Steps:
echo "  - Create an A record for $SITENAME and point to $SERVER_IP"
echo "  - git clone git@gabby.srk9.com:$REPO_NAME"
echo "  --or--
echo "  - git remote add origin git@gabby.srk9.com$:$REPO_NAME"      
# ADD MONGO DB REST ENDPOINT
echo
echo "======================================================="
echo "======================================================="
echo "======================================================="
