webinoly/plugins/stack
Cristhian Martínez Ochoa 22f9bfbfa1 php install with force
php installation now acepts force option for unattended scripts, to avoid nginx question.
2018-02-25 17:49:57 -07:00

507 lines
15 KiB
Bash

#!/bin/bash
# Server Stack Manager
# Syntax: stack <option> <arguments>
# Options: -html, -nginx, -php, -lemp, -mysql, -pma, -info, -purge-server-all, -web-tools, -php-ver
# Arguments: -purge, -notools, -noptim
source /opt/webinoly/lib/install
opt="$1"
arg="$2"
# Check if user entered arg before option and correct it.
if [[ $opt == "-purge" || $opt == "-notools" ]]; then
opt="$2"
arg="$1"
fi
# FORCE - Unattended Purge
clear_force_flag() {
[[ $(conf_read delall) == "true" ]] && conf_delete delall
}
if [[ $arg == "-purge=force" || $opt == "-purge-server-all=force" || $opt == "-php=force" ]]; then
conf_write delall true
[[ $arg == "-purge=force" ]] && arg="-purge"
[[ $opt == "-purge-server-all=force" ]] && opt="-purge-server-all"
[[ $opt == "-php=force" ]] && opt="-php"
force="1"
fi
if [[ $arg == "-noptim" && $opt == "-lemp" ]]; then
if ! [[ $(conf_read nginx) == "true" || $(conf_read php) == "true" || $(conf_read mysql) == "true" ]]; then
nginx_install
php_install
mysql_install
echo ""
echo "${gre} LEMP without optimization has been installed!!! ${end}"
echo ""
messagend_install dbpass
else
echo "${red}[ERROR] Some packages are already installed!${end}"
fi
# Delete some stack
elif [[ $arg == "-purge" && ( $opt == "-html" || $opt == "-nginx" ) ]]; then
if [[ $(conf_read nginx) != "true" ]]; then
echo "${red} Nginx is not installed, hence can not be deleted! ${end}"
clear_force_flag
exit 1
fi
echo ""
echo "${red} ¡ C A U T I O N ! You are about to remove NGINX from your server!"
echo ""
if [[ $(conf_read delall) != "true" ]]; then
echo " ${blu} Are you sure [y/N]? ${end}"
while read -r -n 1 -s answer; do
answer=${answer:-n}
if [[ $answer = [YyNn] ]]; then
break
fi
done
fi
if [[ $answer == [Yy] || $(conf_read delall) == "true" ]]; then
if [[ $(conf_read delall) == "true" && $force == 1 ]]; then
answer="Y"
else
echo ""
echo "${blu}Do you want to delete your sites data directory (/var/www) [Y/n]? ${end}"
while read -r -n 1 -s answer; do
answer=${answer:-y}
if [[ $answer = [YyNn] ]]; then
break
fi
done
fi
if [[ $answer == [Yy] ]]; then
if [[ $(conf_read mysql-tool) == "true" ]]; then
stack -pma -purge
fi
site -delete-all
sudo rm -rf /var/www/$(conf_read tools-port)
sudo rm -rf /var/www/html
fi
sudo service nginx stop
sudo apt-get -y purge nginx nginx-common
sudo apt-get -y purge letsencrypt python-boto duplicity duply
echo | sudo add-apt-repository --remove 'ppa:nginx/stable'
sudo apt-get -y autoremove
sudo rm $HOME/www
sudo rm $HOME/sites-available
linux_purge
if [[ $(conf_read php-tool) != "true" ]]; then
conf_write web-tool purged
fi
conf_write nginx purged
conf_write nginx-optim purged
conf_write nginx-tool purged
echo ""
echo "${gre} Nginx has been deleted successfully! ${end}"
echo ""
else
echo ""
echo " ${gre} Action aborted!!! ${end}"
echo ""
fi
echo ""
elif [[ $arg == "-purge" && $opt == "-php" ]]; then
if [[ $(conf_read php) != "true" ]]; then
echo "${red} PHP is not installed, hence can not be deleted! ${end}"
clear_force_flag
exit 1
fi
echo ""
echo "${red} ¡ C A U T I O N ! You are about to remove PHP from your server!"
echo " This action will also remove PhpMyAdmin if its installed because depends on PHP. ${end}"
echo ""
if [[ $(conf_read delall) != "true" ]]; then
echo " ${blu} Are you sure [y/N]? ${end}"
while read -r -n 1 -s answer; do
answer=${answer:-n}
if [[ $answer = [YyNn] ]]; then
break
fi
done
fi
if [[ $answer == [Yy] || $(conf_read delall) == "true" ]]; then
if [[ $(conf_read mysql-tool) == "true" ]]; then
stack -pma -purge
fi
sudo service php*-fpm stop
sudo apt-get -y purge php*-fpm php*-curl php*-gd php*-imap php*-mcrypt php*-readline php*-common php*-recode php*-mysql php*-cli php*-mbstring php*-bcmath php*-mysql php*-opcache php*-zip php*-xml php*-soap php-imagick graphviz php-pear php-xdebug php-msgpack
sudo apt-get -y purge php-memcached php-memcache memcached
sudo apt-get -y purge redis-server php-redis postfix
echo | sudo add-apt-repository --remove 'ppa:ondrej/php'
echo | sudo add-apt-repository --remove 'ppa:chris-lea/redis-server'
sudo apt-get -y autoremove
sudo rm -rf /etc/php
sudo rm /opt/webinoly/templates/source/*
conf_write php purged
conf_write php-optim purged
if [[ $(conf_read php-tool) == "true" ]]; then
rm -rf /var/www/$(conf_read tools-port)/htdocs/fpm
rm -rf /var/www/$(conf_read tools-port)/htdocs/php
conf_write php-tool purged
fi
if [[ $(conf_read nginx-tool) != "true" ]]; then
conf_write web-tool purged
fi
echo ""
echo "${gre} PHP has been deleted successfully! ${end}"
echo ""
else
echo ""
echo " ${gre} Action aborted!!! ${end}"
echo ""
fi
echo ""
elif [[ $arg == "-purge" && $opt == "-mysql" ]]; then
if [[ $(conf_read mysql) != "true" ]]; then
echo "${red} MySQL is not installed, hence can not be deleted! ${end}"
clear_force_flag
exit 1
fi
echo ""
echo "${red} ¡ C A U T I O N ! You are about to remove MySQL from your server! ${end}"
echo ""
if [[ $(conf_read delall) != "true" ]]; then
echo " ${blu} Are you sure [y/N]? ${end}"
while read -r -n 1 -s answer; do
answer=${answer:-n}
if [[ $answer = [YyNn] ]]; then
break
fi
done
fi
if [[ $answer == [Yy] || $(conf_read delall) == "true" ]]; then
if [[ $(conf_read mysql-tool) == "true" ]]; then
conf_write delautopma true
stack -pma -purge
conf_delete delautopma
fi
sudo service mysql stop
sudo apt-get -y purge mariadb-server mariadb-common mysql-common debconf-utils
sudo apt-get -y purge mariadb-client
sudo apt-get -y autoremove
os_name=$(check_osname)
sudo add-apt-repository --remove "deb [arch=amd64,i386,ppc64el] http://mirrors.syringanetworks.net/mariadb/repo/10.2/ubuntu ${os_name} main"
# Cases with MariaDB v10.2 support
case "$os_name" in
"trusty")
sudo apt-key del 0xcbcb082a1bb943db
;;
"xenial"|"zesty"|"artful")
sudo apt-key del 0xF1656F24C74CD1D8
;;
esac
sudo rm -rf /etc/mysql
sudo rm -rf /var/lib/mysql
conf_delete mysql-root
conf_delete mysql-admin
conf_write mysql-client purged
conf_write mysql purged
echo ""
echo "${gre} MySQL has been deleted successfully! ${end}"
echo ""
else
echo ""
echo " ${gre} Action aborted!!! ${end}"
echo ""
fi
echo ""
elif [[ $arg == "-purge" && $opt == "-pma" ]]; then
if [[ $(conf_read mysql-tool) != "true" ]]; then
echo "${red} PhpMyAdmin is not installed, hence can not be deleted! ${end}"
clear_force_flag
exit 1
fi
echo ""
echo "${red} ¡ C A U T I O N ! You are about to remove PhpMyAdmin from your server! ${end}"
echo ""
if [[ $(conf_read delall) != "true" && $(conf_read delautopma) != "true" ]]; then
echo " ${blu} Are you sure [y/N]? ${end} "
while read -r -n 1 -s answer; do
answer=${answer:-n}
if [[ $answer = [YyNn] ]]; then
break
fi
done
fi
if [[ $answer == [Yy] || $(conf_read delall) == "true" || $(conf_read delautopma) == "true" ]]; then
echo "phpmyadmin phpmyadmin/dbconfig-remove boolean true" | debconf-set-selections
echo "phpmyadmin phpmyadmin/purge boolean true" | debconf-set-selections
sudo apt-get -y purge phpmyadmin
sudo apt-get -y autoremove
sudo rm -rf /var/www/$(conf_read tools-port)/htdocs/pma
conf_write mysql-tool purged
echo ""
echo "${gre} PhpMyAdmin has been deleted successfully! ${end}"
echo ""
else
echo ""
echo " ${gre} Action aborted!!! ${end}"
echo ""
fi
echo ""
elif [[ $arg == "-purge" && $opt == "-web-tools" ]]; then
if [[ $(conf_read web-tool) != "true" ]]; then
echo "${red} Web Tools (Postfix, Redis, Memcached, Duplicity and Letsencrypt) are not installed, hence can not be deleted! ${end}"
clear_force_flag
exit 1
fi
echo ""
echo "${red} ¡ C A U T I O N ! You are about to remove all your Web Tools (Postfix, Redis, Memcached, Duplicity and Letsencrypt) from your server! ${end}"
echo ""
if [[ $(conf_read delall) != "true" ]]; then
echo " ${blu} Are you sure [y/N]? ${end} "
while read -r -n 1 -s answer; do
answer=${answer:-n}
if [[ $answer = [YyNn] ]]; then
break
fi
done
fi
if [[ $answer == [Yy] || $(conf_read delall) == "true" ]]; then
if [[ $(conf_read nginx-tool) == "true" ]]; then
sudo apt-get -y purge letsencrypt python-boto duplicity duply
fi
if [[ $(conf_read php-tool) == "true" ]]; then
sudo apt-get -y purge redis-server php-redis postfix php-memcached php-memcache memcached
fi
sudo apt-get -y autoremove
conf_write web-tool purged
echo ""
echo "${gre} Web Tools have been deleted successfully! ${end}"
echo ""
else
echo ""
echo " ${gre} Action aborted!!! ${end}"
echo ""
fi
echo ""
elif [[ $arg == "-purge" && $opt == "-lemp" ]]; then
echo ""
echo "${red}If you want to remove Webinoly Stack completely from your server use the '-purge-server-all' option or remove each package individually. ${end}"
echo ""
elif [[ $arg != "-purge" && $arg != "-notools" && -n "$arg" ]]; then
echo ""
echo "${red} $arg is not a valid argument! ${end}"
echo ""
# Install some stack
elif [[ $opt == "-html" || $opt == "-nginx" ]]; then
if [[ $(conf_read nginx) != "true" ]]; then
nginx_install
nginx_optim
if [[ $arg != "-notools" ]]; then
nginx_tool
fi
echo ""
echo "${gre} Nginx has been installed successfully! ${end}"
echo ""
else
echo "${red}Nginx is already installed!${end}"
if [[ $(conf_read nginx-optim) != "true" ]]; then
nginx_optim
echo "${gre}"
echo "NGINX has been optimized by Webinoly!"
echo "${end}"
fi
if [[ $(conf_read nginx-tool) != "true" && $arg != "-notools" ]]; then
nginx_tool
echo "${gre}"
echo "NGINX Tools has been re-installed!"
echo "${end}"
fi
fi
elif [[ $opt == "-php" ]]; then
if [[ $(conf_read php) != "true" ]]; then
if [[ $(conf_read nginx) != "true" && $(conf_read delall) != "true" ]]; then
echo ""
echo "${blu}Nginx is not installed, do you want to install it too [Y/n]?${end} "
while read -r -n 1 -s answer; do
answer=${answer:-y}
if [[ $answer = [YyNn] ]]; then
break
fi
done
if [[ $answer != [Nn] ]]; then
stack -nginx $arg
fi
fi
php_install
php_optim
if [[ $arg != "-notools" ]]; then
php_tool
fi
echo ""
echo "${gre} PHP has been installed successfully! ${end}"
echo ""
else
echo "${red}PHP is already installed!${end}"
if [[ $(conf_read php-optim) != "true" ]]; then
php_optim
echo "${gre}"
echo "PHP has been optimized by Webinoly!"
echo "${end}"
fi
if [[ $(conf_read php-tool) != "true" && $arg != "-notools" ]]; then
php_tool
echo "${gre}"
echo "PHP Tools has been re-installed!"
echo "${end}"
fi
fi
elif [[ $opt == "-mysql" ]]; then
if [[ $(conf_read mysql) != "true" ]]; then
mysql_install
if [[ $arg != "-notools" ]]; then
stack -pma
fi
echo ""
echo "${gre} MySQL (MariaDB) has been installed successfully! ${end}"
echo ""
messagend_install dbpass
else
echo "${red}MySQL is already installed!${end}"
if [[ $(conf_read mysql-tool) != "true" && $arg != "-notools" ]]; then
stack -pma
echo "${gre}"
echo "MySQL Tools has been re-installed!"
echo "${end}"
fi
fi
elif [[ $opt == "-pma" ]]; then
if [[ $(conf_read mysql) != "true" || $(conf_read php) != "true" || $(conf_read nginx) != "true" || $(conf_read nginx-tool) != "true" ]]; then
echo "${red} You need to have MySQL, PHP and NGINX installed before you can install PhpMyAdmin! ${end}"
clear_force_flag
exit 1
fi
if [[ $(conf_read mysql-tool) != "true" ]]; then
mysql_tool
echo ""
echo "${gre} PhpMyAdmin has been installed successfully! ${end}"
echo ""
else
echo "${red}PhpMyAdmin is already installed!${end}"
fi
elif [[ $opt == "-lemp" ]]; then
stack -nginx $arg
stack -php $arg
stack -mysql $arg
echo ""
echo "${gre} Nginx, PHP, MySQL (MariaDB) and other useful tools have been installed successfully! ${end}"
echo ""
elif [[ $opt == "-php-ver="* ]]; then
phpver=$(echo "${opt}" | cut -d'=' -f 2 -s)
if [[ -n $phpver && ($phpver == "7.2" || $phpver == "7.1" || $phpver == "7.0" || $phpver == "5.6") ]]; then
echo "${blu} New PHP version: '$phpver' ${end}"
if [[ $(conf_read php) == "true" && $(conf_read php-ver) == $phpver ]]; then
echo "${red}PHP $phpver is currently installed!${end}"
elif [[ $(conf_read php) == "true" && $(conf_read mysql-tool) == "true" ]]; then
sudo stack -php -purge=force
conf_write php-ver $phpver
# force flag prevent to be questioned (Unattended) when nginx is not installed.
conf_write delall true
sudo stack -php
sudo stack -pma
elif [[ $(conf_read php) == "true" && $(conf_read mysql-tool) != "true" ]]; then
sudo stack -php -purge=force
conf_write php-ver $phpver
conf_write delall true
sudo stack -php
elif [[ $(conf_read php) != "true" && $(conf_read mysql-tool) != "true" ]]; then
conf_write php-ver $phpver
echo "${gre} PHP is not already installed but new version will be installed next time! ${end}"
fi
clear_force_flag
else
echo "${red} Please, enter a valid PHP version!${end}"
fi
# Info & Purge-Server-All
elif [[ $opt == "-info" ]]; then
system_info
elif [[ $opt == "-purge-server-all" ]]; then
echo ""
echo "${red} ¡ C A U T I O N ! You are about to remove Webinoly Stack completely from your server!"
echo " This action will remove Nginx, PHP, MySQL and all the other tools, all your sites will remain in the server but will be publicly unavailable after this action."
echo ""
echo " If you want to remove your sites data use the webinoly command: 'sudo webinoly -delete-all'"
echo ""
if [[ $(conf_read delall) != "true" && $force != 1 ]]; then
echo " ${blu} Are you sure [y/N]? ${end}"
while read -r -n 1 -s answer; do
answer=${answer:-n}
if [[ $answer = [YyNn] ]]; then
break
fi
done
else
answer="Y"
fi
if [[ $answer == [Yy] ]]; then
conf_write delall true
[[ $force == 1 ]] && stack -nginx -purge=force || stack -nginx -purge
[[ $force == 1 ]] && stack -mysql -purge=force || stack -mysql -purge
[[ $force == 1 ]] && stack -php -purge=force || stack -php -purge
clear_force_flag
echo "${gre}"
echo "****************************************************************************"
echo "*** Webinoly Stack have been completely removed from your server ***"
echo "**** We are sad because you decided to remove Webinoly!! ****"
echo "****************************************************************************"
echo "${end}"
else
echo ""
echo " ${gre} Action aborted!!! ${end}"
echo ""
fi
else
echo "${red} $opt is not a valid option! ${end}"
fi
# Clear FORCE flag in config file
if [[ $force == 1 ]]; then
clear_force_flag
force="0"
fi