57 lines
1.6 KiB
Bash
Executable File
57 lines
1.6 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
docker_installer="$(dirname "$0")/../docker_installers/ubuntu_docker_installer.sh"
|
|
webtop_compose="$(dirname "$0")/docker-compose.yml"
|
|
|
|
# Ask for the username
|
|
read -p "Enter the username: " username
|
|
|
|
# Ask for the password
|
|
read -sp "Enter the password: " password
|
|
echo
|
|
|
|
# Ask if a swap file is needed
|
|
read -p "Do you want to add a swap file? (y/n): " add_swap
|
|
if [[ "$add_swap" == "y" ]]; then
|
|
read -p "Enter the size of the swap file (e.g., 1G, 512M): " swap_size
|
|
sudo fallocate -l "$swap_size" /swapfile
|
|
sudo chmod 600 /swapfile
|
|
sudo mkswap /swapfile
|
|
sudo swapon /swapfile
|
|
echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab
|
|
echo "Swap file of size $swap_size created."
|
|
fi
|
|
|
|
# Create the user with the given password
|
|
sudo useradd -m "$username" -p "$(openssl passwd -1 "$password")"
|
|
|
|
echo "User $username created."
|
|
|
|
# Add user to sudo group
|
|
sudo usermod -aG sudo "$username"
|
|
|
|
echo "User $username added to sudo group."
|
|
|
|
# Copy necessary files
|
|
sudo mkdir -p /home/"$username"/webtop
|
|
sudo cp "$webtop_compose" /home/"$username"/webtop
|
|
sudo chown -R "$username":"$username" /home/"$username"/webtop
|
|
|
|
# Create a secondary script
|
|
secondary_script=/home/"$username"/setup_webtop.sh
|
|
cat << EOF | sudo tee "$secondary_script"
|
|
#!/bin/bash
|
|
sudo chmod +x "$docker_installer"
|
|
sudo bash "$docker_installer"
|
|
cd /home/$username/webtop
|
|
sudo docker compose up -d
|
|
EOF
|
|
|
|
sudo chmod +x "$secondary_script"
|
|
sudo chown "$username":"$username" "$secondary_script"
|
|
|
|
# Execute the secondary script as the new user
|
|
sudo -u "$username" bash "$secondary_script"
|
|
|
|
echo "Webtop container running..."
|