#!/bin/bash

cd /opt && git clone https://github.com/constantinekg/pcpo
cd /opt/pcpo/

sudo dpkg-reconfigure tzdata

sudo apt update && sudo apt upgrade -y

sudo apt install php7.4-cli php7.4-common php7.4-bcmath php7.4-bz2 php7.4-curl php7.4-dev php7.4-enchant php7.4-fpm php7.4-gd php7.4-gmp php7.4-intl php7.4-json php7.4-mbstring php7.4-mysql php7.4-pgsql php7.4-phpdbg php7.4-pspell php7.4-readline php7.4-soap php7.4-sqlite3 php7.4-tidy php7.4-xml php7.4-xmlrpc php7.4-xsl php7.4-zip php-memcache php-imagick nginx mysql-server python3-pip p7zip-full nmap git -y

sudo pip3 install wmi_client_wrapper wrapper barcodenumber wmi-client-wrapper-py3 mysql-connector python-telegram-bot

7z x web.tar.7z && tar -xvf web.tar && rm web.tar* -f

sudo chown www-data:www-data /opt/pcpo/web -R


sudo cp /opt/pcpo/bin/wmic /usr/bin/
sudo chmod +x /usr/bin/wmic

chmod +x scanner/multithread.py scanner/rerun.sh

sudo mysql_tzinfo_to_sql /usr/share/zoneinfo|mysql -u root mysql
echo "default_authentication_plugin=mysql_native_password" >> /etc/mysql/mysql.conf.d/mysqld.cnf
systemctl restart mysql.service
sudo mysql -e "CREATE DATABASE pcpo CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci;"
sudo mysql -e "CREATE USER 'pcpodbuser'@'localhost' IDENTIFIED WITH mysql_native_password BY 'JLKasr43m534653mlkfsd^';"
sudo mysql pcpo < db/pcpo.sql
sudo mysql -e "GRANT ALL ON pcpo.* TO 'pcpodbuser'@'localhost';"
sudo mysql -e "GRANT SELECT ON pcpo.* TO 'pcpodbuser'@'localhost';"
sudo mysql -e "FLUSH PRIVILEGES;"

sudo cp  /etc/nginx/sites-available/default  /etc/nginx/sites-available/default.bak
sudo rm /etc/nginx/sites-available/default /etc/nginx/sites-enabled/default
sudo cp /opt/pcpo/conf/pcpo.conf /etc/nginx/sites-available/pcpo.conf && sudo ln -s /etc/nginx/sites-available/pcpo.conf /etc/nginx/sites-enabled/pcpo.conf
sudo systemctl restart nginx


