Guest User

Untitled

a guest
Dec 15th, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.19 KB | None | 0 0
  1. #! /bin/bash
  2. #
  3. # =======================
  4. # Linode vhost script
  5. # =======================
  6.  
  7. function make_vhost
  8. {
  9. cat <<- _EOF_
  10. <VirtualHost *:80>
  11. ServerAdmin linus@unwi.se
  12. ServerName $dname
  13. ServerAlias *.$dname
  14. DocumentRoot /srv/www/$dname/public_html/
  15. ErrorLog /srv/www/$dname/logs/error.log
  16. CustomLog /srv/www/$dname/logs/access.log combined
  17.  
  18. <Directory /srv/www/$dname/public_html/>
  19. Options FollowSymLinks
  20. AllowOverride All
  21. Order allow,deny
  22. allow from all
  23. </Directory>
  24. </VirtualHost>
  25. _EOF_
  26. }
  27.  
  28. # =======================
  29. # header
  30. # =======================
  31. clear
  32. echo "*** Virtual host setup ***"
  33.  
  34. # =======================
  35. # set domain name variable
  36. # =======================
  37. echo " "
  38. echo -n "Enter domain name: "
  39. read dname
  40. echo " "
  41. echo "Setting up files for $dname"
  42.  
  43. # =======================
  44. # create needed directories
  45. # =======================
  46. echo " "
  47. mkdir -vp /srv/www/$dname
  48. mkdir -vp /srv/www/$dname/public_html
  49. mkdir -vp /srv/www/$dname/logs
  50. echo " "
  51. touch /srv/www/$dname/logs/access.log
  52. echo "created /srv/www/$dname/logs/access.log"
  53. touch /srv/www/$dname/logs/error.log
  54. echo "created /srv/www/$dname/logs/error.log"
  55.  
  56. # =======================
  57. # build vhost config file
  58. # =======================
  59. echo " "
  60. make_vhost > /etc/apache2/sites-available/$dname
  61. echo "created /etc/apache2/sites-available/$dname"
  62. cd /srv/www/$dname/public_html
  63.  
  64. # =======================
  65. # add git repo
  66. # =======================
  67. echo " "
  68. while true; do
  69. read -p "Initialize empty Git repository? $" yn
  70. case $yn in
  71. [Yy]* ) git init; touch README; git add .; git commit -m "Initial commit."; git checkout -b live; break;;
  72. [Nn]* ) break;;
  73. * ) echo "Please answer yes or no.";;
  74. esac
  75. done
  76.  
  77. # =======================
  78. # enable site
  79. # =======================
  80. echo " "
  81. while true; do
  82. read -p "Enable site? $" yn
  83. case $yn in
  84. [Yy]* ) a2ensite $dname; service apache2 reload; break;;
  85. [Nn]* ) break;;
  86. * ) echo "Please answer yes or no.";;
  87. esac
  88. done
  89.  
  90. # =======================
  91. # exit
  92. # =======================
  93. echo " "
  94. echo "*** Finished setting up files for $dname."
  95. exit
Add Comment
Please, Sign In to add comment