From 5a7780281626a4c7d4da847f5d6785b540da910b Mon Sep 17 00:00:00 2001 From: Michael March Date: Sun, 24 Sep 2023 14:59:44 +0000 Subject: [PATCH] Adding syncthing and refactored to functions. --- debian-bootstrap.sh | 92 ++++++++++++++++++++++++--------------------- 1 file changed, 50 insertions(+), 42 deletions(-) diff --git a/debian-bootstrap.sh b/debian-bootstrap.sh index 4503acb..4269536 100644 --- a/debian-bootstrap.sh +++ b/debian-bootstrap.sh @@ -1,53 +1,61 @@ #!/bin/bash -# Update and upgrade existing packages -sudo apt update && sudo apt upgrade -y +install_basic_utilities() { + 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 -sudo apt install -y vim curl wget pv python3 python3-dev build-essential git byobu +create_new_user() { + echo "Please enter the desired username:" + read username + if id "$username" &>/dev/null; then + echo "User $username already exists!" + else + sudo adduser $username + sudo usermod -aG sudo $username + fi +} -# 1. Create a new user and prompt for a username -echo "Please enter the desired username:" -read username +install_zsh() { + sudo apt install -y zsh + sudo chsh -s $(which zsh) $username +} -# Check if user already exists -if id "$username" &>/dev/null; then - echo "User $username already exists!" -else - sudo adduser $username -fi +install_docker() { + sudo apt install -y apt-transport-https ca-certificates gnupg + 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 +} -# 2. Give that user sudo privileges -sudo usermod -aG sudo $username +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 +} -# 3. Install zsh and make it the default shell for the user -sudo apt install -y zsh -sudo chsh -s $(which zsh) $username +install_distrobox() { + su - $username -c "curl -s https://raw.githubusercontent.com/89luca89/distrobox/main/install | sh" +} -# 4. Install Docker CE +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 +} -# a. Install prerequisites -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 - -# 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 - -# d. Install Docker -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 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" +# 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."