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
sudo apt install -y vim curl wget pv python3 python3-dev build-essential git byobu
}
# Install some basic utilities create_new_user() {
sudo apt install -y vim curl wget pv python3 python3-dev build-essential git byobu echo "Please enter the desired username:"
read username
# 1. Create a new user and prompt for a username if id "$username" &>/dev/null; then
echo "Please enter the desired username:"
read username
# Check if user already exists
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 sudo usermod -aG sudo $username
fi
}
# 2. Give that user sudo privileges install_zsh() {
sudo usermod -aG sudo $username sudo apt install -y zsh
sudo chsh -s $(which zsh) $username
}
# 3. Install zsh and make it the default shell for the user install_docker() {
sudo apt install -y zsh sudo apt install -y apt-transport-https ca-certificates gnupg
sudo chsh -s $(which zsh) $username curl -fsSL https://download.docker.com/linux/debian/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker.gpg
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
sudo apt update && sudo apt install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin
sudo systemctl enable docker
sudo systemctl start docker
sudo docker run hello-world
}
# 4. Install Docker CE install_portainer() {
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
}
# a. Install prerequisites install_distrobox() {
sudo apt install -y apt-transport-https ca-certificates gnupg su - $username -c "curl -s https://raw.githubusercontent.com/89luca89/distrobox/main/install | sh"
}
# b. Add Docker's official GPG key install_syncthing() {
curl -fsSL https://download.docker.com/linux/debian/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker.gpg 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
}
# c. Add Docker's stable repository # Main script execution
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 install_basic_utilities
create_new_user
# d. Install Docker install_zsh
sudo apt update && sudo apt install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin install_docker
install_portainer
# e. Ensure Docker is active in systemd and run the hello-world container to verify the installation install_distrobox
sudo systemctl enable docker install_syncthing
sudo systemctl start docker
sudo docker run hello-world
# 5. Install Portainer
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
# 6. Install distrobox for the user
su - $username -c "curl -s https://raw.githubusercontent.com/89luca89/distrobox/main/install | sh"
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."