Adding syncthing and refactored to functions.

This commit is contained in:
Michael March 2023-09-24 14:59:44 +00:00
parent 3d0ab236a7
commit 5a77802816

View file

@ -1,53 +1,61 @@
#!/bin/bash #!/bin/bash
# Update and upgrade existing packages install_basic_utilities() {
sudo apt update && sudo apt upgrade -y sudo apt update && sudo apt upgrade -y
# Install some basic utilities
sudo apt install -y vim curl wget pv python3 python3-dev build-essential git byobu sudo apt install -y vim curl wget pv python3 python3-dev build-essential git byobu
}
# 1. Create a new user and prompt for a username create_new_user() {
echo "Please enter the desired username:" echo "Please enter the desired username:"
read username read username
# Check if user already exists
if id "$username" &>/dev/null; then if id "$username" &>/dev/null; then
echo "User $username already exists!" echo "User $username already exists!"
else else
sudo adduser $username sudo adduser $username
fi
# 2. Give that user sudo privileges
sudo usermod -aG sudo $username sudo usermod -aG sudo $username
fi
}
# 3. Install zsh and make it the default shell for the user install_zsh() {
sudo apt install -y zsh sudo apt install -y zsh
sudo chsh -s $(which zsh) $username sudo chsh -s $(which zsh) $username
}
# 4. Install Docker CE install_docker() {
# a. Install prerequisites
sudo apt install -y apt-transport-https ca-certificates gnupg sudo apt install -y apt-transport-https ca-certificates gnupg
# b. Add Docker's official GPG key
curl -fsSL https://download.docker.com/linux/debian/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker.gpg curl -fsSL https://download.docker.com/linux/debian/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker.gpg
# c. Add Docker's stable repository
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker.gpg] https://download.docker.com/linux/debian $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker.gpg] https://download.docker.com/linux/debian $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
# d. Install Docker
sudo apt update && sudo apt install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin sudo apt update && sudo apt install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin
# e. Ensure Docker is active in systemd and run the hello-world container to verify the installation
sudo systemctl enable docker sudo systemctl enable docker
sudo systemctl start docker sudo systemctl start docker
sudo docker run hello-world sudo docker run hello-world
}
# 5. Install Portainer install_portainer() {
sudo docker volume create portainer_data sudo docker volume create portainer_data
sudo docker run -d -p 9000:9000 --name=portainer --restart=always -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data portainer/portainer-ce sudo docker run -d -p 9000:9000 --name=portainer --restart=always -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data portainer/portainer-ce
}
# 6. Install distrobox for the user install_distrobox() {
su - $username -c "curl -s https://raw.githubusercontent.com/89luca89/distrobox/main/install | sh" su - $username -c "curl -s https://raw.githubusercontent.com/89luca89/distrobox/main/install | sh"
}
install_syncthing() {
sudo curl -o /usr/share/keyrings/syncthing-archive-keyring.gpg https://syncthing.net/release-key.gpg
echo "deb [signed-by=/usr/share/keyrings/syncthing-archive-keyring.gpg] https://apt.syncthing.net/ syncthing stable" | sudo tee /etc/apt/sources.list.d/syncthing.list
sudo apt-get update
sudo apt-get install -y syncthing
sudo systemctl enable syncthing@$username.service
sudo systemctl start syncthing@$username.service
}
# Main script execution
install_basic_utilities
create_new_user
install_zsh
install_docker
install_portainer
install_distrobox
install_syncthing
echo "All tasks completed! You can now access Portainer at http://your-server-ip:9000." echo "All tasks completed! You can now access Portainer at http://your-server-ip:9000."