deployment-dcdn/install.sh

79 lines
1.8 KiB
Bash
Raw Normal View History

2024-02-23 14:28:42 +01:00
#!/bin/bash
echo "Deployment Debian + Caddy + Directus + Nuxt"
if [ "$EUID" -ne 0 ]; then
echo "Please run as root"
exit
fi
#
# USER
#
2024-02-23 15:14:36 +01:00
read -p "Create a user ? (y/n) " answer
if [[ "$answer" == "y" ]]; then
echo "Create user"
2024-02-23 14:28:42 +01:00
2024-02-23 15:14:36 +01:00
read -p "Enter username: " username
2024-02-23 14:28:42 +01:00
2024-02-23 15:14:36 +01:00
if id "$username" &>/dev/null; then
echo "User '$username' already exists."
exit 1
fi
2024-02-23 14:28:42 +01:00
2024-02-23 15:14:36 +01:00
echo "Generate and store the password somewhere safe"
read -s -p "Enter password: " password
echo
useradd -m "$username"
chsh -s /bin/bash $username
echo "$username:$password" | chpasswd
2024-02-23 14:28:42 +01:00
2024-02-23 15:14:36 +01:00
usermod -aG sudo $username
2024-02-23 14:28:42 +01:00
2024-02-23 15:14:36 +01:00
echo "User '$username' created with password successfully."
fi
2024-02-23 14:28:42 +01:00
#
# SSH
#
2024-02-23 15:14:36 +01:00
read -p "Setup SSH ? (y/n) " answer
if [[ "$answer" == "y" ]]; then
echo "Setup SSH"
touch /etc/ssh/sshd_config.d/custom.conf
echo "PermitRootLogin no" >> /etc/ssh/sshd_config.d/custom.conf
echo "PermitEmptyPasswords no" >> /etc/ssh/sshd_config.d/custom.conf
systemctl reload ssh
fi
#
# FIREWALL AND FAIL2BAN
#
2024-02-23 15:14:36 +01:00
read -p "Setup Firewall and Fail2Ban ? (y/n) " answer
if [[ "$answer" == "y" ]]; then
echo "Setup Firewall and Fail2Ban"
apt install -y ufw fail2ban
systemctl enable fail2ban
ufw allow ssh
ufw allow http
ufw allow https
fi
#
# TODO : ZABBIX AND URBACKUP
#
echo "TODO : Zabbix and Urbackup"
#
# CADDY
#
2024-02-23 15:14:36 +01:00
read -p "Install Caddy webserver ? (y/n) " answer
if [[ "$answer" == "y" ]]; then
echo "Install Caddy Webserver"
apt install -y debian-keyring debian-archive-keyring apt-transport-https curl
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' | gpg --dearmor -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' | tee /etc/apt/sources.list.d/caddy-stable.list
apt update
apt install -y caddy
fi