Compare commits

..

6 Commits

Author SHA1 Message Date
dd6f022c94 simplify docker debian readme 2026-01-12 11:13:13 +00:00
a8e1ae9224 simplify update docker readme 2026-01-12 11:12:48 +00:00
3052fa2806 swap url for wget 2025-09-20 10:39:41 +00:00
1819ab280e swap url for wget 2025-09-20 10:38:46 +00:00
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 205 additions and 0 deletions

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

@@ -0,0 +1,4 @@
```bash
wget -qO docker-debian.sh https://gitea.featherer.xyz/nono/Scripts/raw/branch/main/docker-debian/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"

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

@@ -0,0 +1,6 @@
# cd into the docker folder
```bash
wget -qO update-docker.sh https://gitea.featherer.xyz/nono/Scripts/raw/branch/main/update-docker/update-docker.sh
source update-docker.sh
```

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!"