clear
echo -e "\x3cs\033[0m"

#atualizar sistema
sudo ufw disable
apt-get update
cd /var
apt-get install zip -y
echo America/Sao_Paulo > /etc/timezone && rm /etc/localtime && ln -snf /usr/share/zoneinfo/America/Sao_Paulo /etc/localtime > /dev/null 2>&1

#instalar java8 

sudo mkdir -p /usr/lib/jvm
cd /usr/lib/jvm
wget http://montagemcsp.dyndns.org/ubuntu-24-26/jdk-8u212-linux-x64.tar.gz
cd /usr/lib/jvm 
tar -xvzf jdk-8u212-linux-x64.tar.gz
mv jdk1.8.0_212*/ jre-oracle
sudo mv jre-oracle/ /usr/lib
sudo update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jre-oracle/bin/java" 1
sudo update-alternatives --set java /usr/lib/jre-oracle/bin/java

#instalar csp

cd /usr/local
wget http://montagemcsp.dyndns.org/ubuntu-24-26/csp.zip
unzip csp.zip
cd /usr/local
chmod -R 777 csp

if [ ! -d "/etc/systemd/system/csp.service" ]; then
echo '[Unit]
Description=CSP
After=network.target
Requires=network.target

[Service]
Type=forking
ExecStart=/usr/local/csp/cardproxy.sh start
ExecStop=/usr/local/csp/cardproxy.sh stop
TimeoutStopSec=1
Restart=always
RestartSec=5
StartLimitInterval=0

[Install]
WantedBy=multi-user.target' >> /etc/systemd/system/csp.service

chmod 755 /etc/systemd/system/csp.service
chmod 755 -R /opt/csp
chmod 755 -R /cd /usr/local
systemctl enable csp.service
fi


#SOBRESCREVER ARQUIVO REMOTO RC.LOCAL

if [ ! -d "/etc/systemd/system/rc-local.service" ]; then
echo "[Unit]
 Description=/etc/rc.local Compatibility
 ConditionPathExists=/etc/rc.local

[Service]
 Type=forking
 ExecStart=/etc/rc.local start
 TimeoutSec=0
 StandardOutput=tty
 RemainAfterExit=yes
 SysVStartPriority=99

[Install]
 WantedBy=multi-user.target" >> /etc/systemd/system/rc-local.service
 
chmod +x /etc/systemd/system/rc-local.service > /dev/null 2>&1
chmod +x /etc/rc.local > /dev/null 2>&1
systemctl enable rc-local > /dev/null 2>&1
fi

rm /etc/rc.local
rm /etc/crontab
cd /etc/
wget http://montagemcsp.dyndns.org/ubuntu-24-26/rc.local
wget http://montagemcsp.dyndns.org/ubuntu-24-26/crontab
chmod +x rc.local
chmod +x crontab
service cron restart
#chmod -R 777 rc.local
#chmod -R 600 crontab
#update-rc.d checksrv.sh defaults

#reiniciar csp automatico

cd /home/
wget http://montagemcsp.dyndns.org/ubuntu-24-26/reboot.sh
chmod +x reboot.sh
chmod -R 777 reboot.sh
#update-rc.d checksrv.sh defaults

echo "root soft nofile 65536" >> /etc/security/limits.conf
echo "root hard nofile 65536" >> /etc/security/limits.conf

#remover arquivo da pasta root

rm /root/csp-24-26.sh
reboot

