Guest User

Untitled

a guest
Jun 5th, 2018
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.55 KB | None | 0 0
  1. #!/bin/bash
  2. # Create a NGINX file, index.php and mysql DB for $DOMAIN passed in first argument e.g
  3. # sudo bash create.sh domain.co.uk
  4. # needs /root/.my.conf set up with [client] root user and password to create DB
  5. # needs certbot installed to do certbot
  6.  
  7. DOMAIN=$1
  8. cp /etc/nginx/sites-available/basic /etc/nginx/sites-available/${DOMAIN}
  9. sed -i "s/:domain/${DOMAIN}/g" /etc/nginx/sites-available/${DOMAIN}
  10. ln -s /etc/nginx/sites-available/${DOMAIN} /etc/nginx/sites-enabled/${DOMAIN}
  11. printf "created /etc/nginx/sites-available/${DOMAIN}"
  12. mkdir -p /var/www/${DOMAIN}/public
  13. printf "public folder here /var/www/${DOMAIN}/public"
  14. printf "<?php echo 'Domain ${DOMAIN} waiting for your magic'; ?>" > /var/www/${DOMAIN}/public/index.php
  15. chown -R www-data:www-data /var/www/${DOMAIN}
  16.  
  17. PASSWDDB="$(openssl rand -base64 12)"
  18.  
  19. mysql --defaults-extra-file=/root/.my.conf -e "CREATE DATABASE ${DOMAIN//[^a-zA-Z_-]/_} /*\!40100 DEFAULT CHARACTER SET utf8 */;"
  20. mysql --defaults-extra-file=/root/.my.conf -e "CREATE USER ${DOMAIN//[^a-zA-Z_-]/_}@localhost IDENTIFIED BY '${PASSWDDB}';"
  21. mysql --defaults-extra-file=/root/.my.conf -e "GRANT ALL PRIVILEGES ON ${DOMAIN//[^a-zA-Z_-]/_}.* TO '${DOMAIN//[^a-zA-Z_-]/_}'@'localhost';"
  22. mysql --defaults-extra-file=/root/.my.conf -e "FLUSH PRIVILEGES;"
  23.  
  24. printf "Database: ${DOMAIN//[^a-zA-Z_-]/_}\nUsername:${DOMAIN//[^a-zA-Z_-]/_}\nPassword:${PASSWDDB}" > /var/www/${DOMAIN}/config
  25. printf "Database config here: /var/www/${DOMAIN}/config"
  26.  
  27. sudo systemctl reload nginx
  28. sudo systemctl restart nginx
  29.  
  30. certbot -n --redirect --nginx -d ${DOMAIN} -d www.${DOMAIN}
Add Comment
Please, Sign In to add comment