serverPostInstall/script.sh
2024-08-03 20:11:41 +02:00

74 lines
No EOL
1.8 KiB
Bash

#!/bin/bash
# Function to update Ubuntu/Debian
update_debian_based() {
echo "Updating $1..."
sudo apt-get update && sudo apt-get upgrade -y
sudo apt install -y sudo curl gnupg rsync
echo "Upgrade completed!"
}
# Function to update Fedora
update_fedora() {
echo "Updating Fedora..."
sudo dnf update -y
sudo dnf install -y sudo curl gnupg rsync
echo "Upgrade completed!"
}
# Function to update CentOS
update_centos() {
echo "Updating CentOS..."
sudo yum update -y
sudo yum install -y sudo curl gnupg rsync
echo "Upgrade completed!"
}
# Detecting the distribution based on /etc/os-release
if [ -f /etc/os-release ]; then
. /etc/os-release
DISTRO=$ID
else
echo "Cannot detect the OS. /etc/os-release not found."
exit 1
fi
# Updating the system based on detected distribution
case "$DISTRO" in
ubuntu)
update_debian_based "Ubuntu"
;;
debian)
update_debian_based "Debian"
;;
fedora)
update_fedora
;;
centos)
update_centos
;;
*)
echo "Unsupported distribution: $DISTRO"
exit 1
esac
# Ask if user wants to add a new user
read -p "Do you want to add a new user? (y/n): " add_new_user
if [ "$add_new_user" == "y" ]; then
read -p "Enter the username for the new user: " username
read -s -p "Enter the password for the new user: " password
echo
adduser --disabled-password --gecos "" $username
echo "$username:$password" | chpasswd
else
echo "No new user will be created."
fi
# Ask if user wants to install Docker
read -p "Do you want to install Docker? (y/n): " install_docker
if [ "$install_docker" == "y" ]; then
curl -sSL https://get.docker.com | sh
echo "Docker has been installed. Adding newly created user to Docker group..."
usermod -aG docker $username
newgrp docker
fi