Compare commits

...

2 Commits

Author SHA1 Message Date
Noah vdv
8802e0b6b1 add docker debian script 2025-09-20 12:32:36 +02:00
Noah vdv
da04f340f1 add update docker script 2025-09-20 12:31:48 +02:00
4 changed files with 260 additions and 0 deletions

21
docker-debian/README.md Normal file
View File

@@ -0,0 +1,21 @@
# 🐳 Docker Setup Script for Debian
This script automates the installation of Docker and optionally helps you set up a working directory and a `compose.yaml` as well as a `.env` file.
---
## 🚀 How to Use
run the following script
```bash
wget -qO docker-debian.sh https://gitea.featherer.xyz/nono/docker-debian/raw/branch/main/docker-debian.sh
source docker-debian.sh
```
Or when run locally (using your own ip address)
```bash
wget -qO docker-debian.sh http://10.1.0.102:3000/nono/docker-debian/raw/branch/main/docker-debian.sh
source docker-debian.sh
```

View File

@@ -0,0 +1,162 @@
#!/bin/bash
clear
# If the user appends the y flag
AUTO_YES=false
for arg in "$@"; do
if [ "$arg" = "-y" ]; then
AUTO_YES=true
fi
done
# Color and formatting variables
RESET="\033[0m"
BOLD="\033[1m"
GREEN="\033[32m"
YELLOW="\033[33m"
CYAN="\033[36m"
RED="\033[31m"
# Print functions
info() { echo -e "\n${BOLD}${CYAN}>>> $1${RESET}\n"; }
warn() { echo -e "\n${BOLD}${YELLOW}>>> $1${RESET}\n"; }
error() { echo -e "\n${BOLD}${RED}>>> ERROR: $1${RESET}\n"; }
# Check if script is sourced
(return 0 2>/dev/null)
if [ $? -ne 0 ]; then
error "Please run this script with: source docker-debian.sh"
echo "Otherwise, directory changes won't persist."
exit 1
fi
# Set SUDO prefix
if [ "$EUID" -ne 0 ]; then
SUDO="sudo"
else
SUDO=""
fi
# Prompt function
prompt() {
local message=$1
if [ "$AUTO_YES" = true ]; then
echo -e "${BOLD}${CYAN}>>> $message [Y/n]: ${RESET}y"
return 0
fi
while true; do
read -rp "$(echo -e "${BOLD}${CYAN}>>> $message [Y/n]: ${RESET}")" yn
case $yn in
[Yy]* | "" ) return 0 ;;
[Nn]* ) return 1 ;;
* ) warn "Please answer yes or no." ;;
esac
done
}
### ======= Collect Choices First =======
prompt "Do you want to update and upgrade the system?" && DO_UPDATE=true
prompt "Do you want to install Docker?" && DO_DOCKER=true
prompt "Do you want to create a folder named after the hostname?" && USE_HOSTNAME=true
if [ -z "$USE_HOSTNAME" ]; then
prompt "Do you want to create a folder with a custom name?" && USE_CUSTOM=true
if [ "$USE_CUSTOM" = true ]; then
read -rp "$(echo -e "${BOLD}${CYAN}>>> Enter custom folder name: ${RESET}")" CUSTOM_DIR
[ -z "$CUSTOM_DIR" ] && warn "No folder name entered. Skipping folder creation." && SKIP_FOLDER=true
else
SKIP_FOLDER=true
fi
fi
if [ -z "$SKIP_FOLDER" ]; then
prompt "Do you want to create a compose.yaml file now?" && CREATE_COMPOSE=true
prompt "Do you want to create a .env file now?" && CREATE_ENV=true
fi
### ======= Review Selections =======
info "Review your selections before continuing:"
[ "$DO_UPDATE" = true ] && echo "✔ Update and upgrade the system"
[ "$DO_DOCKER" = true ] && echo "✔ Install Docker"
if [ -z "$SKIP_FOLDER" ]; then
echo "✔ Create folder: $([ "$USE_HOSTNAME" = true ] && echo "$(hostname)" || echo "$CUSTOM_DIR")"
[ "$CREATE_COMPOSE" = true ] && echo "✔ Create compose.yaml file"
[ "$CREATE_ENV" = true ] && echo "✔ Create .env file"
else
echo "✖ No folder will be created"
fi
echo
prompt "Proceed with these actions?" || { info "Operation cancelled."; return; }
clear
### ======= Execute Actions =======
if [ "$DO_UPDATE" = true ]; then
info "Updating and upgrading..."
$SUDO apt update && $SUDO apt upgrade -y
else
info "Skipping system update and upgrade."
fi
clear
if [ "$DO_DOCKER" = true ]; then
info "Installing Docker..."
$SUDO apt update
$SUDO apt install -y ca-certificates curl
$SUDO install -m 0755 -d /etc/apt/keyrings
$SUDO curl -fsSL https://download.docker.com/linux/debian/gpg -o /etc/apt/keyrings/docker.asc
$SUDO chmod a+r /etc/apt/keyrings/docker.asc
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/debian \
$(. /etc/os-release && echo \"$VERSION_CODENAME\") 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 docker-compose-plugin
info "Docker installation complete."
else
info "Skipping Docker installation."
fi
clear
if [ -z "$SKIP_FOLDER" ]; then
if [ "$USE_HOSTNAME" = true ]; then
FOLDER_NAME=$(hostname)
else
FOLDER_NAME="$CUSTOM_DIR"
fi
mkdir -p "$FOLDER_NAME"
cd "$FOLDER_NAME" || exit
info "Now inside folder: $FOLDER_NAME"
if [ "$CREATE_COMPOSE" = true ]; then
touch compose.yaml
info "compose.yaml created."
fi
if [ "$CREATE_ENV" = true ]; then
touch .env
info ".env file created."
fi
else
info "No folder created or entered."
fi
clear
info "Script completed."
rm -f ~/docker-debian.sh && echo -e "\n${BOLD}${GREEN}>>> Script file 'docker-debian.sh' in your home directory has been deleted.${RESET}\n"

44
update-docker/README.md Normal file
View File

@@ -0,0 +1,44 @@
# 🛠️ Maintenance Script for Docker Containers
Automates updating your Docker containers on Debian-based systems by pulling the latest images, restarting services, and cleaning up unused resources.
---
## 🚀 Installation, Setup & Running
Download the maintenance script to your Docker project directory:
```bash
# cd into the docker folder
wget -qO update-docker.sh https://gitea.featherer.xyz/nono/update-docker/raw/branch/main/update-docker.sh
source update-docker.sh
```
Or, when run locally (replace the ip address to your own)
```bash
# cd into the docker folder
wget -qO update-docker.sh http://10.1.0.102:3000/nono/update-docker/raw/branch/main/update-docker.sh
source update-docker.sh
```
---
## 🔄 What It Does
1. **Updates system packages**
Runs `apt update` and `apt upgrade -y` to ensure your host is up to date.
2. **Refreshes Docker services**
Executes `docker-compose pull`, `docker-compose down`, and `docker-compose up -d` to fetch new images and restart containers.
3. **Cleans up unused resources**
Calls `docker system prune -a -f` to remove dangling images, stopped containers, and unused networks.
4. **Verifies running containers**
Lists active containers with `docker ps` so you can confirm everything is up and running.
---
## 📝 Prerequisites
- **Debian-based OS** (e.g., Debian, Ubuntu)
- **Docker** & **Docker Compose** installed
- A user with **sudo** privileges or in the **docker** group

View File

@@ -0,0 +1,33 @@
#!/bin/bash
echo "Starting system update and Docker maintenance..."
# Update and upgrade APT packages
echo "Running apt update & upgrade..."
apt update
apt upgrade -y
# Pull latest images, stop containers, and recreate in detached mode
echo "Pulling latest Docker images..."
docker compose pull
echo "Stopping and removing existing containers..."
docker compose down
echo "Starting containers in detached mode..."
docker compose up -d
# Prune unused Docker objects
echo "Pruning unused Docker objects..."
docker system prune -a -f
# Show running containers
echo "Current running Docker containers:"
docker ps
echo "Maintenance complete."
echo "Removing the file"
rm -f ./update-docker.sh
echo "Done!"