#!/bin/bash

NC='\033[0m'       # Окончание цвета

Black='\033[0;30m'        # Black
Red='\033[0;31m'          # Red
Green='\033[0;32m'        # Green
Yellow='\033[0;33m'       # Yellow
Blue='\033[0;34m'         # Blue
Purple='\033[0;35m'       # Purple
Cyan='\033[0;36m'         # Cyan
White='\033[0;37m'        # White


echo -e "${Cyan}Создаем пользователя и домашнюю директорию${NC}"
mkdir -p /var/www/web/sites
adduser --gecos GESOS web
usermod -aG sudo web
usermod -d /var/www/web web
chown -R web:web /var/www/web
# su web <<EOF
cd ~
echo -e "${Cyan}Продолжаем от пользователя${NC}"
echo -e "${Green}Устанавливаем пакеты и настраиваем конфигруацию${NC}"
echo -e "${Cyan}Установка php и его завиимостей${NC}"
sudo apt update
sudo apt install curl -y
sudo apt install php8.1 php8.1-fpm php8.1-mysql php8.1-curl php8.1-mbstring php8.1-xml php8.1-bcmath php8.1-intl php8.1-gd ffmpeg php8.1-imagick php8.1-zip -y
sudo sed -i 's/www-data/web/g' /etc/php/8.1/fpm/pool.d/www.conf
sudo sed -i 's/upload_max_filesize = 2M/upload_max_filesize = 25M/g' /etc/php/8.1/fpm/php.ini
sudo sed -i 's/post_max_size = 2M/post_max_size = 25M' /etc/php/8.1/fpm/php.ini
sudo service php8.1-fpm restart && sudo service php8.1-fpm enable
cd ~
curl -sS https://getcomposer.org/installer -o composer-setup.php
sudo php composer-setup.php --install-dir=/usr/local/bin --filename=composer
sudo apt install composer -y
sudo apt install mariadb-server -y
sudo systemctl start mysql && sudo systemctl enable mysql
sudo systemctl restart mysql
echo -e "${Cyan}Установка nginx${NC}"
sudo apt install nginx -y
sudo sed -i 's/user www-data/user web/g' /etc/nginx/nginx.conf
echo -e "${Cyan}Останавливаем apache2 и запускаем nginx${NC}"
sudo systemctl stop apache2 && sudo systemctl disable apache2
sudo systemctl start nginx && sudo systemctl enable nginx
echo -e "${Cyan}Установка git${NC}"
sudo apt install git -y
echo -e "${Cyan}Установка nodeJS${NC}"
curl -fsSL https://deb.nodesource.com/setup_16.x | sudo -E bash -
sudo apt install -y nodejs
echo -e "${Cyan}Установка yarn${NC}"
sudo npm install --global yarn -y
sudo rm -rf /etc/nginx/sites-enabled/
sudo ln -s /etc/nginx/sites-available /etc/nginx/sites-enabled
echo -e "${Cyan}Установка certbot${NC}"
sudo apt install certbot python3-certbot-nginx -y

echo -e "${White}DONE${NC}"
echo -e "${Blue}DONE${NC}"
echo -e "${Red}DONE${NC}"
EOF
su web