Last active
February 11, 2017 09:41
-
-
Save dmsmidt/1ba18245136a034daa80adf203f89565 to your computer and use it in GitHub Desktop.
Prepare a local Drupal install. Git checkout, nginx setup, create MySql database.
This file contains hidden or 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 | |
# This is a general-purpose function to ask Yes/No questions in Bash, either | |
# with or without a default answer. It keeps repeating the question until it | |
# gets a valid answer. | |
ask() { | |
# http://djm.me/ask | |
while true; do | |
if [ "${2:-}" = "Y" ]; then | |
prompt="Y/n" | |
default=Y | |
elif [ "${2:-}" = "N" ]; then | |
prompt="y/N" | |
default=N | |
else | |
prompt="y/n" | |
default= | |
fi | |
# Ask the question | |
read -p "$1 [$prompt] " REPLY </dev/tty | |
# Default? | |
if [ -z "$REPLY" ]; then | |
REPLY=$default | |
fi | |
# Check if the reply is valid | |
case "$REPLY" in | |
Y*|y*) return 0 ;; | |
N*|n*) return 1 ;; | |
esac | |
done | |
} | |
read -e -p "Enter the project system name: " NAME | |
if [[ -z "${NAME}" ]]; then | |
printf '%s\n' "No input entered." | |
exit 1 | |
fi | |
read -e -p "Site/Project dir: " -i "/srv/http/${NAME}" SITE_DIR | |
read -e -p "Docroot: " -i "${SITE_DIR}/docroot" SITE_DOCROOT | |
read -e -p "Site url: " -i "${NAME}.localhost" SITE_NAME | |
if ask "Clone site from Git?"; then | |
read -e -p "Enter the repo ssh address: " CLONE | |
git clone ${CLONE} ${SITE_DIR} | |
fi | |
if ask "Create database?"; then | |
read -e -p "Enter the database name: " -i "${NAME}" DB | |
echo "create database `${DB}`" | mysql -uroot -p | |
fi | |
PATH_AV="/etc/nginx/servers-available/${NAME}.conf" | |
PATH_EN="/etc/nginx/servers-enabled/${NAME}.conf" | |
echo "Create nginx site config." | |
[ -f "${PATH_AV}" ] && sudo rm "${PATH_AV}" | |
read -e -p "Drupal Major version [7,8]: " -i "8" DRUPAL_VERSION | |
echo -e "server {\n\ | |
server_name ${SITE_NAME} www.${SITE_NAME} ;\n\ | |
root ${SITE_DOCROOT};\n\ | |
include drupal${DRUPAL_VERSION}.conf;\n\ | |
}" | sudo tee "${PATH_AV}" > /dev/null | |
echo "Enable site." | |
[ -f "${PATH_EN}" ] && sudo rm "${PATH_EN}" | |
sudo ln -s "${PATH_AV}" "${PATH_EN}" | |
echo "Activate site." | |
sudo systemctl reload nginx | |
echo "[DONE]" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment