Guest User

Untitled

a guest
Jan 12th, 2017
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 6.49 KB | None | 0 0
  1. #!/bin/bash
  2. #For Centos 7
  3. #chmod +x script
  4. #./script
  5. #Testat si verificat pe CentOS 7.3.1611
  6. if [ "$(id -u)" != "0" ];
  7.     then
  8.         printf "Sorry, sudo required.\n"
  9.         exit
  10. fi
  11. public_ip=`curl -s http://icanhazip.com`
  12. private_ip=`ip addr | grep 'state UP' -A2 | tail -n1 | awk '{print $2}' | cut -f1  -d'/'`
  13.  
  14. height=15
  15. width=40
  16. choice_height=4
  17. backtitle="LAMP+WORDPRESS INSTALL"
  18. title="LAMP+WORDPRESS INSTALL"
  19. menu="Choose one of the following options:"
  20.  
  21. OPTIONS=(1 "Install&configure LAMP"
  22.     2 "Set HOSTS"
  23.     3 "Set VirtualHosts"
  24.     4 "Install&configure Wordpress")
  25.    
  26.  
  27. choice=$(dialog --clear \
  28.                 --backtitle "$backtitle" \
  29.                 --title "$title" \
  30.                 --menu "$menu" \
  31.                 $height $width $choice_height \
  32.                 "${OPTIONS[@]}" \
  33.                 2>&1 >/dev/tty)
  34.  
  35. clear
  36. case $choice in
  37.         1)
  38.         clear
  39.         yes | yum install httpd
  40.         systemctl enable httpd
  41.         systemctl start httpd
  42.  
  43.         yes | yum install mariadb-server mariadb
  44.         systemctl start mariadb
  45.         systemctl enable mariadb
  46.  
  47.         printf "Set root password if you have one and enter yes all time\n"
  48.         mysql_secure_installation
  49.  
  50.         yes | yum install php php-mysql php-fpm
  51.         systemctl restart httpd
  52.         if cat /etc/redhat-release | grep -q "CentOS Linux release 7." && rpm -q firewalld > /dev/null;
  53.             then
  54.                 printf "Adding port 80:"
  55.                 firewall-cmd --permanent --zone=public --add-service=http
  56.                 printf "\nAdding port 443:"
  57.                 firewall-cmd --permanent --zone=public --add-service=https
  58.                 printf "\nReloading firewalld:"
  59.                 firewall-cmd --reload
  60.                 printf "\n"
  61.         fi
  62.  
  63.         touch /var/www/html/info.php
  64.         printf "<?php echo "succes"; ?>" > /var/www/html/info.php
  65.         printf "Checking /var/www/html/info.php\n"
  66.         tmp_ip=$public_ip
  67.         tmp_ip+="/"
  68.         tmp_ip+="info.php"
  69.         site=$(curl -s $tmp_ip)
  70.  
  71.         if [[ $site = "succes" ]] > /dev/null;
  72.             then
  73.                 printf "php has been verified&instaled!\n" 
  74.         else
  75.             printf "error verifying php ( $site)\n"
  76.         fi
  77.         rm /var/www/html/info.php
  78.             ;;
  79.         2)
  80.         clear
  81.         printf "Set custom hosts?(y/n)\n"
  82.         read -e hostss
  83.         if [ "$hostss" == y ] ;
  84.             then
  85.                 printf "[custom host]enter ip: "
  86.                 read -e ip
  87.                 printf "[custom host]enter host: "
  88.                 read -e host
  89.                 printf "$ip $host" >> /etc/hosts
  90.                 printf "$ip $host added on /etc/hosts\n"
  91.         fi
  92.  
  93.             ;;
  94.         3)
  95.         clear
  96.         printf "Set virtual host domain?(y/n)"
  97.         read -e virtual
  98.  
  99.         if [ "$virtual" == y ] ;
  100.         then
  101.             printf "Enter the name of virtual domain: "
  102.             read -e domain 
  103.             mkdir -p /var/www/$domain/public_html
  104.             chown -R $USER:$USER /var/www/$domain/public_html
  105.             chmod -R 755 /var/www
  106.             printf "<html>
  107.                 <head>
  108.                         <title>Welcome to $domain!</title>
  109.                 </head>
  110.                 <body>
  111.                         <h1>Success! The $domain virtual host is working!</h1>
  112.                     <h1>Public ip: $public_ip</h1>
  113.                     <h1>Private ip: $private_ip</h1>
  114.                 </body>
  115.                 </html>" > /var/www/$domain/public_html/index.html
  116.  
  117.             mkdir -p /etc/httpd/sites-available
  118.             mkdir -p /etc/httpd/sites-enabled
  119.    
  120.             if ! grep -q "IncludeOptional sites-enabled/*.conf" /etc/httpd/conf/httpd.conf;
  121.                 then
  122.                     printf "IncludeOptional sites-enabled/*.conf" >> /etc/httpd/conf/httpd.conf
  123.             fi
  124.    
  125.             printf "<VirtualHost *:80>
  126.                     ServerName www.$domain
  127.                     ServerAlias $domain
  128.                     DocumentRoot /var/www/$domain/public_html
  129.                     ErrorLog /var/www/$domain/error.log
  130.                     CustomLog /var/www/$domain/requests.log combined
  131.                 </VirtualHost>" > /etc/httpd/sites-available/$domain.conf
  132.             sudo ln -s /etc/httpd/sites-available/$domain.conf /etc/httpd/sites-enabled/$domain.conf
  133.             printf "$private_ip $domain\n" >> /etc/hosts
  134.             printf "Done $domain\n"
  135.         fi
  136.             ;;
  137.         4)
  138.         clear
  139.         printf "WordPress Install Script\n"                        
  140.         printf "Create database, user, password for wordpress? (y/n)\n"
  141.         read -e sql
  142.  
  143.         if [ "$sql" == y ] ;
  144.             then
  145.                 printf "Creating database:\n"
  146.                 printf "ENTER ROOT PASSWORD: "
  147.                 read -s root_password                  
  148.                 printf "\nDatabase Name: "
  149.                 read -e db_name
  150.                 printf "\nDatabase User: "
  151.                 read -e db_user
  152.                 printf "\nDatabase Password: "
  153.                 read -s db_pass
  154.                 mysql -u root -p$root_password -e "
  155.                     CREATE DATABASE $db_name;
  156.                     CREATE USER '$db_user'@'localhost' IDENTIFIED BY '$db_pass';
  157.                     GRANT ALL PRIVILEGES ON $db_name.* TO '$db_user'@'localhost';
  158.                     FLUSH PRIVILEGES; "
  159.  
  160.                 printf "MySQL info:\n"
  161.                 printf "DataBase Name: $db_name\n"
  162.                 printf "Username: $db_user\n"
  163.                 printf "Password: $db_pass\n"
  164.         fi
  165.         printf "Enter Wordpress Database:\n"
  166.         printf "Database Name: "
  167.         read -e dbname
  168.                    
  169.         printf "Database User: "
  170.         read -e dbuser
  171.  
  172.         printf "Database Password: "
  173.         read -s dbpass
  174.                            
  175.         curl -O https://wordpress.org/latest.tar.gz    
  176.         tar -zxvf latest.tar.gz
  177.         mv wordpress wps
  178.         cp -rf wps /var/www/html
  179.  
  180.         cp /var/www/html/wps/wp-config-sample.php /var/www/html/wps/wp-config.php
  181.         perl -pi -e "s/database_name_here/$dbname/g" /var/www/html/wps/wp-config.php
  182.         perl -pi -e "s/username_here/$dbuser/g" /var/www/html/wps/wp-config.php
  183.         perl -pi -e "s/password_here/$dbpass/g" /var/www/html/wps/wp-config.php
  184.  
  185.         perl -i -pe'
  186.         BEGIN   {
  187.                     @chars = ("a" .. "z", "A" .. "Z", 0 .. 9);
  188.                     push @chars, split //, "!@#$%^&*()-_ []{}<>~\`+=,.;:/?|";
  189.                     sub salt { join "", map $chars[ rand @chars ], 1 .. 64 }
  190.             }  
  191.             s/put your unique phrase here/salt()/ge
  192.         ' /var/www/html/wps/wp-config.php
  193.         mkdir /var/www/html/wps/wp-content/uploads
  194.         chmod 775 /var/www/html/wps/wp-content/uploads
  195.  
  196.         rm latest.tar.gz
  197.         rm -Rf wps
  198.         printf "Wordpress Installation is complete.\n"
  199.  
  200.         if [ ! -f /usr/local/bin/wp ];
  201.             then
  202.             printf "Downloading & Installing WP-CLI\n"
  203.             curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
  204.             chmod +x wp-cli.phar
  205.             sudo mv wp-cli.phar /usr/local/bin/wp
  206.             printf "Done\n"
  207.         fi
  208.         printf "Site Title: "
  209.         read -e site_title
  210.         printf "Site Username: "
  211.         read -e site_username
  212.         printf "Site Email: "
  213.         read -e site_email
  214.         site_password=$(openssl rand -base64 12)
  215.         pushd $PWD
  216.         cd /var/www/html/wps
  217.         /usr/local/bin/wp --allow-root core install --url=$public_ip/wps --title=$site_title --admin_user=$site_username --admin_email=$site_email  --admin_password=$site_password
  218.         printf "Complete: \nSite title: $site_title \nUsername: $site_username \nEmail: $site_email \nPasswd: $site_password \n To see ur website visit: ${public_ip}/wps"
  219.         rm -f /usr/local/bin/wp
  220.             ;;
  221. esac
Add Comment
Please, Sign In to add comment