Guest User

Untitled

a guest
Dec 13th, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.55 KB | None | 0 0
  1. #!/bin/bash
  2. vhroot='/etc/apache2/sites-available/'
  3. NEW_DOMAINS="/home/domain.txt"
  4.  
  5. cat ${NEW_DOMAINS} |
  6.  
  7. while read domain user email
  8. do
  9.  
  10. echo "<VirtualHost *:80>
  11. ServerName "$domain"
  12. ServerAlias www."$domain"
  13. ServerAdmin "$email"
  14. DocumentRoot /home/"$user"/domains/"$domain"/public_html
  15. </VirtualHost>" > $vhroot/$domain
  16.  
  17. #mkdir /home/$user/domains/domain
  18. #mkdir /home/$user/domains/$domain/public_html
  19. #chown -R $user.$user /home/$user/domains/$domain
  20.  
  21. echo "111.21.111.111 $domain" >> host.txt
  22. #a2ensite $hostname
  23. done
  24.  
  25. echo "" > /home/domain.txt
  26.  
  27. # /etc/init.d/apache2 reload
  28.  
  29. #!/bin/bash
  30. vhroot='/etc/apache2/sites-available/'
  31. NEW_DOMAINS="/home/domain.txt"
  32. has_new_domains=false #No new domains by default = do not reload the apache config.
  33.  
  34. cat ${NEW_DOMAINS} |
  35.  
  36. while read domain user email
  37. do
  38. has_new_domains=true #true = at least one new domain = reload apache config
  39. echo "<VirtualHost *:80>
  40. ServerName "$domain"
  41. ServerAlias www."$domain"
  42. ServerAdmin "$email"
  43. DocumentRoot /home/"$user"/domains/"$domain"/public_html
  44. </VirtualHost>" > $vhroot/$domain
  45.  
  46. #mkdir /home/$user/domains/domain
  47. #mkdir /home/$user/domains/$domain/public_html
  48. #chown -R $user.$user /home/$user/domains/$domain
  49.  
  50. echo "111.21.111.111 $domain" >> host.txt
  51. #a2ensite $hostname
  52. done
  53.  
  54. echo "" > /home/domain.txt
  55.  
  56. if $has_new_domains ; then #only reload the apache config if there is at least one new domain
  57. /etc/init.d/apache2 reload
  58. fi
  59.  
  60. #!/bin/bash
  61. vhroot='/etc/apache2/sites-available/'
  62. NEW_DOMAINS="adddomain.txt"
  63. has_new_domains=false #No new domains by default = do not reload the apache config.
  64.  
  65. cat ${NEW_DOMAINS} |
  66.  
  67. while read domain
  68. do
  69. if [ ! -z "$domain" ];
  70. then
  71. has_new_domains=true #true = at least one new domain = reload apache config
  72. echo "<VirtualHost *:80>
  73. ServerName "$domain"
  74. ServerAlias www."$domain"
  75. ServerAdmin postmaster@"$domain"
  76. DocumentRoot /var/www/html/websites/"$domain"
  77. </VirtualHost>" > $vhroot/"$domain".conf #.conf extension needed to make a2ensite work in apache -debian
  78. mkdir /var/www/html/websites/
  79. mkdir /var/www/html/websites/$domain
  80. chown -R root:www-data /var/www/html/websites
  81. chmod -R 755 /var/www/html/websites
  82.  
  83. #create index.html file
  84. echo "<!DOCTYPE html>
  85. <html>
  86. <head>
  87. <title>Welcome to nginx on Debian!</title>
  88. <style>
  89. body {
  90. width: 35em;
  91. margin: 0 auto;
  92. font-family: Tahoma, Verdana, Arial, sans-serif;
  93. }
  94. </style>
  95. </head>
  96. <body>
  97. <h1>Welcome to "$domain"</h1>
  98. <p>If you see this page, the Apache web server is successfully installed and working.</p>
  99.  
  100. <p>
  101. You can start building your website
  102. </p>
  103.  
  104. </body> </html>">/var/www/html/websites/$domain/index.html
  105. #echo "111.21.111.111 $domain" >> host.txt
  106. a2ensite "$domain".conf
  107. else echo 'No new domains'
  108. fi
  109. done
  110.  
  111. > adddomain.txt # with echo "" an empty line is still present in file
  112. DEL_DOMAINS="deldomain.txt"
  113. cat ${DEL_DOMAINS} |
  114.  
  115. while read deldomain
  116. do
  117. has_new_domains=true #true = at least one new domain = reload apache config
  118. #Make sure we don't delete all parent directory , in case variable is empty
  119. if [ ! -z "$deldomain" ]; then
  120. a2dissite "$deldomain".conf
  121. echo "dominio "$deldomain" eliminado"
  122. rm -r /var/www/html/websites/$deldomain
  123. rm $vhroot/"$deldomain".conf
  124. fi
  125. done
  126. > deldomain.txt
  127. if $has_new_domains ; then #only reload the apache config if there is at least one new domain
  128. /etc/init.d/apache2 reload
  129. fi
Add Comment
Please, Sign In to add comment