92 lines
No EOL
2 KiB
Bash
92 lines
No EOL
2 KiB
Bash
#!/bin/bash
|
|
|
|
# Function to update Ubuntu/Debian
|
|
update_debian_based() {
|
|
echo "Updating $1..."
|
|
sudo apt-get update && sudo apt-get upgrade -y
|
|
echo "Upgrade completed!"
|
|
}
|
|
|
|
# Function to update Fedora
|
|
update_fedora() {
|
|
echo "Updating Fedora..."
|
|
sudo dnf update -y
|
|
echo "Upgrade completed!"
|
|
}
|
|
|
|
# Function to update CentOS
|
|
update_centos() {
|
|
echo "Updating CentOS..."
|
|
sudo yum update -y
|
|
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
|
|
|
|
# Function to create a new user
|
|
create_new_user() {
|
|
echo "Enter the username for the new user: "
|
|
read USERNAME
|
|
|
|
# Check if the username already exists
|
|
if id "$USERNAME" &>/dev/null; then
|
|
echo "User $USERNAME already exists!"
|
|
create_new_user
|
|
else
|
|
echo "Enter the password for the new user: "
|
|
read -s PASSWORD
|
|
|
|
# Create the user and set the password
|
|
sudo useradd -m "$USERNAME"
|
|
echo "$USERNAME:$PASSWORD" | sudo chpasswd
|
|
echo "User $USERNAME created successfully!"
|
|
fi
|
|
}
|
|
|
|
# Asking if the user wants to create a new user
|
|
echo "Do you want to create a new user? (y/n): "
|
|
read CREATE_USER
|
|
|
|
if [ "$CREATE_USER" = "y" ]; then
|
|
create_new_user
|
|
else
|
|
echo "No new user will be created."
|
|
fi
|
|
|
|
# Asking if the user wants to install Docker
|
|
echo "Do you want to install Docker & Docker Compose? (y/n): "
|
|
read INSTALL_DOCKER
|
|
|
|
if [ "$INSTALL_DOCKER" = "y" ]; then
|
|
curl -sSL https://get.docker.com | sh
|
|
sudo usermod -aG docker $(whoami)
|
|
newgrp docker
|
|
else
|
|
echo "Docker won't be installed."
|
|
fi |