#!/bin/bash
#Prestashop @ Debian 12

PATH=/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin
ln -sf bash /bin/sh

echo -e "\n--- disabling password authentication & ubuntu user"
sed 's/#\(PasswordAuthentication\) yes/\1 no/' -i /etc/ssh/sshd_config
systemctl restart sshd

echo -e "\n--- installing web server packages"
apt update && apt upgrade -y
apt install libapache2-mod-php php-mysql mariadb-server wget unzip
apt install php-zip php-xml php-curl php-gd php-intl php-mbstring
a2enmod ssl
a2enmod rewrite
systemctl restart apache2
rm /var/www/html/index.html


PRESTA_VER=8.1.1 #2023-09-06
PASSWORD="P@ssw0rd"


echo -e "\n--- Enabling default HTTPS site"
a2ensite default-ssl
systemctl restart apache2

echo -e "\n--- Creating Prestashop database"
mariadb << EOF
create database prestashop;
create user prestashop@localhost identified by '$PASSWORD';
grant all privileges on prestashop.* to prestashop@localhost;
flush privileges;
EOF

echo -e "\n--- Deploying Prestashop"
cd /root
wget https://github.com/PrestaShop/PrestaShop/releases/download/$PRESTA_VER/prestashop_$PRESTA_VER.zip
cd /var/www/html
rm index.{php,html}
unzip /root/prestashop_$PRESTA_VER.zip
chown -R www-data:www-data /var/www/html
cd -
