Skip to content

Instantly share code, notes, and snippets.

@soutar
Last active August 29, 2015 14:01
Show Gist options
  • Save soutar/21c8fbc3ad082c10015d to your computer and use it in GitHub Desktop.
Save soutar/21c8fbc3ad082c10015d to your computer and use it in GitHub Desktop.
Colestrap
#!/bin/bash
blue="\e[0;34m"
purple="\e[0;35m"
orange="\e[0;33m"
green="\e[0;32m"
white="\e[0;37m"
red="\e[0;31m"
echo "-------------------------------------------"
echo -e "${white}Welcome to the ${purple}C${green}o${blue}l${orange}e${white} AD project bootstrapper"
echo "-------------------------------------------"
# Which client?
echo -e "${green}> What is the name of the client?${white}"
echo -e "${green}> (this should be the same as the folder name in live web jobs)${white}"
read -p "> " client_name
while [[ -z $client_name ]]; do
echo -e "${red}> Please enter a valid client name${white}"
read -p "> " client_name
done
set -- $client_name
client_name_web=$1
client_name_escaped=$(echo ${client_name} | sed -e 's/\\/\\\\/g' -e 's/\//\\\//g' -e 's/&/\\\&/g')
echo ${client_name_escaped}
if [ ! -d "/mnt/Sites/$client_name" ]; then
echo -e "${red}Unable to find a client folder in live web jobs under \"$client_name\"${white}"
echo -e "${green}Would you like to create the folder now? y/n${white}"
read -n 1 create_directory
echo
if [[ $create_directory =~ ^[Yy]$ ]]; then
mkdir "/mnt/Sites/$client_name"
echo -e "${green}Client folder created in live web jobs${white}"
else
echo -e "${red}No client folder. Quitting..${white}"
exit
fi
fi
# Which folder?
echo -e "${green}> What folder would you like to serve? (press enter for \"Site\")${white}"
read -p "> " serve_directory
serve_directory=${serve_directory:-Site}
serve_directory=$(echo ${serve_directory} | sed -e 's/\\/\\\\/g' -e 's/\//\\\//g' -e 's/&/\\\&/g')
if [ ! -d "/mnt/Sites/$client_name/$serve_directory" ]; then
echo -e "${red}The client folder for \"$client_name\" contains no folder \"$serve_directory\"${white}"
echo -e "${green}Would you like to create the folder now?${white} y/n"
read -n 1 create_directory
echo
if [[ $create_directory =~ ^[Yy]$ ]]; then
mkdir "/mnt/Sites/$client_name/$serve_directory"
echo -e "${green}Folder \"$serve_directory\" created in client folder for \"$client_name\"${white}"
else
echo -e "${red}No client folder. Quitting..${white}"
exit
fi
fi
# Check for an existing vhost which may conflict with the one we're setting up
conflicts=$(grep -r --include=*.conf "/mnt/Sites/${client_name}/${serve_directory}" /etc/apache2/ | wc -l)
if [ $conflicts -gt 0 ]; then
echo -e "${red}There is already a vhost pointing at this folder${white}"
exit
else
echo -e "${green}> What address would you like to give this site? (press enter for \"${client_name_web,,}.dev\")${white}"
read -p "> " server_name
server_name=${server_name:-${client_name_web,,}.dev}
fi
# Create a config for our new vhost
config_file="/etc/apache2/sites-available/${server_name}.conf"
cp /etc/apache2/sites-available/default.conf ${config_file}
sed -i "s/server_name/${server_name}/g" ${config_file}
sed -i "s/client_name/${client_name_escaped}/g" ${config_file}
sed -i "s/serve_directory/${serve_directory}/g" ${config_file}
echo -e "${green}Enabling site.."
a2ensite ${server_name}
echo -e "${green}> Would you like to restart Apache now?${white} y/n"
read -n 1 -p "> " restart_apache
if [[ $restart_apache =~ ^[Yy]$ ]]; then
echo
echo -e "${green}Restarting Apache..${white}"
apachectl restart
echo -e "${green}All done! You should be able to see the folder at http://${server_name}${white}"
else
echo -e "${green}All done! Restart Apache to see the folder served at http://${server_name}${white}"
fi
echo -e "${green}> Would you like to install WordPress on this site?${white} y/n"
read -n 1 -p "> " install_wp
if [[ $install_wp =~ ^[Yy]$ ]]; then
install-wp "${client_name}" "${serve_directory}" "${server_name}"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment