Skip to content

Instantly share code, notes, and snippets.

@shashankgroovy
Last active February 12, 2016 12:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shashankgroovy/346be90deaac298bf4c0 to your computer and use it in GitHub Desktop.
Save shashankgroovy/346be90deaac298bf4c0 to your computer and use it in GitHub Desktop.
Script to automatically create all nginx configurations
#!/bin/bash
# Description:
# Nginx configurations
# Execution:
# First a lot the correct file permissions for the setup file:
# $ chmod 755 setup.sh
# And then simply run
# $ ./nginx-setup.sh
# Written by: Shashank Srivastav <shashankgrovy@gmail.com>
# Github: github.com/shashankgroovy
# Last updated: February 11, 2016
#-----------------------------------------------------------
create_symlink() {
echo "Creating symlink for $1"
mv $1 /etc/nginx/sites-available
ln -s /etc/nginx/sites-available/$1 /etc/nginx/sites-enabled/
}
fetch() {
echo "Fetching $1 configuration"
wget -q $2
}
URI=https://gist.github.com/shashankgroovy
printf "\nInitiate nginx configuration"
printf "\n----------------------------\n"
mkdir sites && cd sites
echo "Fetching all configurations"
fetch musejam.com $URI/44b1593795334b4298b3/raw/800092acd865d76cc5c8ddeaa372e9cca2aaa261/musejam.com
fetch api.musejam.com $URI/a786f098a49292f62c7f/raw/b6c7da495744f459787f0d4ca62f742e7cbf300d/api.musejam.com
fetch admin.musejam.com $URI/182da3061c033bf69433/raw/76538f36d7e6c612f755461640ee55d783e018e9/admin.musejam.com
fetch controlpanel.musejam.com $URI/2a2b7b389f01fa6a2fd6/raw/bce1521ee83ec662dc8be56e86ee549c90dbed00/controlpanel.musejam.com
fetch thumbor.musejam.com $URI/01ea1f8660101558a603/raw/45f1897994dad4628529bea762afb0cf59497bb9/thumbor.musejam.com
fetch old.musejam.com $URI/2b08af0d883c5d2980a4/raw/abbbd292ba84718ee608773e291cee4e6b44399d/old.musejam.com
create_symlink musejam.com
create_symlink api.musejam.com
create_symlink admin.musejam.com
create_symlink controlpanel.musejam.com
create_symlink thumbor.musejam.com
create_symlink old.musejam.com
printf "\nSetting up Museups"
printf "\n------------------\n"
fetch museups.com $URI/7e1a684203fbdf595e37/raw/3772b0e624511d268fe6f5ff7d3aa0e3613e8efd/museups.com
fetch admin.museups.com $URI/5533828d371b618c7ee5/raw/162a1191793b4d3b046c18ee8457fb4780135328/admin.museups.com
fetch api.museups.com $URI/7c90628e878f5755cfbf/raw/f8195a4f3e5c8911a6549eb2f4c3d1311ac0bc34/api.museups.com
create_symlink museups.com
create_symlink admin.museups.com
create_symlink api.museups.com
printf "\nTesting nginx configurations"
printf "\n----------------------------\n"
if (sudo nginx -t)
then
echo "Test passed."
else
echo "Nginx Config Fail"
echo "Please correct your nginx configurations"
fi
# go back to previous directory
cd ..
if [ "$(ls -A sites)" ];
then
echo "Something went wrong! Make sure you have sudo."
rm -rf sites
else
echo "Finishing up"
rmdir sites
echo "Finished."
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment