Advertisement
Mayur_k

Untitled

Feb 25th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.61 KB | None | 0 0
  1. if [[ $EUID -ne 0 ]]; then
  2. echo "This script must be run as root"
  3. exit 1
  4. fi
  5. LOG=script.log
  6. ERROR=script.err
  7. export DEBIAN_FRONTEND=noninteractive
  8.  
  9. mysql_secure_installation () {
  10. echo -e "Removing Insecure Details From MySQL"
  11. mysql -u$adminuser -p$adminpass -e "DELETE FROM mysql.user WHERE User='';"
  12. mysql -u$adminuser -p$adminpass -e "DELETE FROM mysql.user WHERE User='root' AND Host NOT IN ('localhost', '127.0.0.1', '::1');"
  13. mysql -u$adminuser -p$adminpass -e "DROP DATABASE IF EXISTS test;"
  14. mysql -u$adminuser -p$adminpass -e "DELETE FROM mysql.db WHERE Db='test' OR Db='test\\_%';"
  15. mysql -u$adminuser -p$adminpass -e "FLUSH PRIVILEGES;"
  16. }
  17.  
  18.  
  19. mysql_setup () {
  20. echo -e "${BLUE}Setting up mysql-server...${NC}"
  21. echo -e "${CAYAN}"
  22. ct=0
  23. while [ $ct -eq 0 ]
  24. do
  25. read -p "Enter User for MYSQL Admin: " adminuser
  26. echo
  27. read -sp "Enter the password for MYSQL Admin: " adminpass
  28. echo
  29. read -sp "Re-enter the password for MYSQL Admin: " re_adminpass
  30. echo
  31.  
  32. if [ $adminpass == $re_adminpass ];
  33. then
  34. echo -e "${GREEN}Password will be set for MySQL Admin.${NC}"
  35. echo "mysql-server mysql-server/root_password password $adminpass" | sudo debconf-set-selections
  36. echo "mysql-server mysql-server/root_password_again password $adminpass" | sudo debconf-set-selections
  37. ct=1
  38. else
  39. echo -e "${RED}Password did not match... Try again${NC}"
  40. fi
  41. done
  42. echo -e "${NC}"
  43. }
  44.  
  45.  
  46. site_setup () {
  47. echo -e "Cleaning old files and Setting up new files..."
  48. rm /etc/nginx/sites-available/$domain
  49. cp /etc/nginx/sites-available/default /etc/nginx/sites-available/$domain
  50. sed -i "s/site/$domain/g" /etc/nginx/sites-available/$domain
  51. service nginx restart
  52. rm -f /etc/nginx/sites-enabled/$domain
  53. ln -s /etc/nginx/sites-available/$domain /etc/nginx/sites-enabled/
  54.  
  55. mkdir -p /var/www/$domain/html
  56. cp -a /tmp/wordpress/. /var/www/$domain/html
  57. chown -R $USER:www-data /var/www/$domain/html
  58. find /var/www/$domain/html -type d -exec chmod g+s {} \;
  59. chmod g+w /var/www/$domain/html/wp-content
  60. chmod -R g+w /var/www/$domain/html/wp-content/themes
  61. chmod -R g+w /var/www/$domain/html/wp-content/plugins
  62. curl https://api.wordpress.org/secret-key/1.1/salt/ -o salt.txt
  63. sed -i '49,56d;57r salt.txt' /var/www/$domain/html/wp-config.php
  64.  
  65. sed -i "s/database_name_here/$dbname/" /var/www/$domain/html/wp-config.php
  66. sed -i "s/username_here/$wpuser/" /var/www/$domain/html/wp-config.php
  67. sed -i "s/password_here/$wppass/" /var/www/$domain/html/wp-config.php
  68.  
  69. service nginx restart
  70. service php7.0-fpm restart
  71. }
  72.  
  73.  
  74. domain_database_setup () {
  75. dt=0
  76. while [ $dt -eq 0 ]
  77. do
  78. echo -e "${CAYAN}"
  79. read -p "Enter domain name: www." domain
  80. echo
  81. echo -e "Your Domain name is www.$domain "
  82. echo "127.0.0.1 $domain www.$domain" >> /etc/hosts
  83. echo -e "${NC}"
  84. dt=1
  85. done
  86. dbname="$domain"_db
  87. ct=0
  88. echo
  89. echo -e "${CAYAN}"
  90. read -p "Enter the user name for $dbname database: " wpuser
  91. while [ $ct -eq 0 ]
  92. do
  93. echo -e "${CAYAN}"
  94. read -sp "Enter the password for $dbname database: " wppass
  95. echo
  96. read -sp "Re-enter the password for $dbname database: " re_wppass
  97. echo -e "${NC}"
  98. echo
  99. echo
  100. if [ $wppass == $re_wppass ];
  101. then
  102. echo -e "${GREEN}Password set for wordpress database.${NC}"
  103. mysql -u$adminuser -p$adminpass -e "CREATE DATABASE IF NOT EXISTS \`$dbname\`;"
  104. mysql -u$adminuser -p$adminpass -e "GRANT ALL PRIVILEGES ON \`$dbname\`.* TO '$wpuser'@"localhost" IDENTIFIED BY '$wppass';"
  105. mysql -u$adminuser -p$adminpass -e "FLUSH PRIVILEGES;"
  106. ct=1
  107. else
  108. echo -e "${RED}Password did not match... Try again${NC}"
  109.  
  110. fi
  111. done
  112. echo -e "${NC}"
  113.  
  114. }
  115.  
  116. apt update
  117. RED='\033[0;31m' GREEN='\033[0;32m' NC='\033[0m' CAYAN='\033[0;36m'
  118. BLUE='\033[0;34m' HBLK='\033[1;94m' YELLOW='\033[1;93m'
  119.  
  120.  
  121. echo -e "------------------------------------"
  122. echo -e "${BLUE}Checking if Nginx is installed${NC}"
  123. dpkg -l | grep nginx
  124. if [ "$?" -eq 0 ];
  125. then
  126. echo
  127. echo -e "${GREEN}NGINX is already Installed...${NC}";
  128. service nginx start
  129. echo -e "------------------------------------"
  130. else
  131. echo -e "------------------------------------"
  132. echo -e "${BLUE}Installing NGINX...${NC}"
  133. apt install nginx -y >>$LOG 2>>$ERROR
  134. service nginx start
  135. echo -e "${GREEN}Nginx is Installed.${NC}";
  136. echo -e "------------------------------------"
  137. fi
  138.  
  139. echo -e "${BLUE}Checking if Mysql is installed${NC}"
  140. dpkg -l | grep mysql-server
  141. if [ "$?" -eq 0 ];
  142. then
  143. echo
  144. echo -e "${GREEN}MySQL-Server is already Installed...${NC}";
  145. service mysql start
  146. echo -e "${CAYAN}"
  147. read -p "Enter the user name of MYSQL Admin: " adminuser
  148. read -sp "Enter the pasword of MYSQL Admin: " adminpass
  149. echo -e "${NC}"
  150. mysql_secure_installation
  151. else
  152. mysql_setup
  153. echo -e "------------------------------------"
  154. echo -e "${BLUE}Installing mysql-server... ${NC}"
  155. apt install mysql-server -y >>$LOG 2>>$ERROR
  156. service mysql start
  157. mysql_secure_installation
  158. echo -e "${GREEN}Mysql Setup is complete. ${NC}"
  159. echo -e "------------------------------------"
  160. fi
  161.  
  162. domain_database_setup # function
  163.  
  164. for i in curl php7.0-fpm php7.0-mysql mysql-client php-curl php-gd php-mbstring php-mcrypt php-xml php-xmlrpc;
  165. do
  166. echo -e "------------------------------------"
  167. echo -e "${GREEN}Checking if $i is installed${NC}";
  168. dpkg -l | grep $i
  169. if [ "$?" -eq 0 ];
  170. then
  171. echo -e "${GREEN}$i is Installed${NC}"
  172. echo -e "-----------------------------------"
  173. else
  174. echo -e "-----------------------------------"
  175. echo -e "${RED}$i is not Installed.${NC}"
  176. echo -e "${BLUE}Installing $i ...${NC}"
  177. apt install $i -y >>$LOG 2>>$ERROR
  178. echo -e "${GREEN}$i Package is installed..${NC} "
  179. echo -e "----------------------------------"
  180. fi
  181. done
  182. service php7.0-fpm start
  183. cat <<eof > /etc/nginx/sites-available/default
  184. server {
  185.  
  186. listen 80;
  187. listen [::]:80;
  188.  
  189. root /var/www/site/html;
  190. index index.php index.html index.htm index.nginx-debian.html;
  191.  
  192. server_name site www.site;
  193.  
  194. location / {
  195. try_files \$uri \$uri/ /index.php$is_args$args;
  196.  
  197. }
  198.  
  199. location ~ \.php$ {
  200. include snippets/fastcgi-php.conf;
  201. fastcgi_pass unix:/run/php/php7.0-fpm.sock;
  202. }
  203.  
  204. location ~ /\.ht {
  205. deny all;
  206. }
  207.  
  208. }
  209. eof
  210. service nginx reload
  211.  
  212. sed -i 's/^;\?cgi\.fix\_pathinfo=.*$/cgi.fix_pathinfo=0/' /etc/php/7.0/fpm/php.ini
  213. service php7.0-fpm restart
  214.  
  215. echo
  216. echo -e "${HBLK}Downloading wordpress...${NC}"
  217.  
  218. cd /tmp
  219. curl -O https://wordpress.org/latest.tar.gz
  220. tar xzvf latest.tar.gz
  221.  
  222. cp /tmp/wordpress/wp-config-sample.php /tmp/wordpress/wp-config.php
  223. site_setup
  224.  
  225. echo -e "Visit the site at ${YELLOW} www.$domain/wp-admin/install.php ${NC}"
  226. ct=0
  227. while [ $ct -eq 0 ]
  228. do
  229. echo -e "${GREEN}Do you want to create another site ? ${NC} (Yes = y | N = n)";
  230. read choice;
  231. if [ $choice == 'y' ] || [ $choice == 'yes' ]
  232. then
  233. domain_database_setup
  234. site_setup
  235. ct=0
  236. else
  237. echo -e "Setup is complete.. ";
  238. echo -e "Visit the site at ${YELLOW} www.$domain/wp-admin/install.php ${NC}"
  239. ct=1
  240. fi
  241. done
  242. #echo -e "WordPress Database name:${YELLOW} $dbname ${NC}"
  243. #echo -e "WordPress Database user:${YELLOW} $wpuser ${NC}"
  244. #echo -e "WordPress Database password:${YELLOW} $wppass ${NC}"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement