Merge pull request #89 from wickedyoda/macos-update

Macos update
This commit is contained in:
WickedYoda authored and GitHub committed 2026-08-05 13:20:24 -05:00
commit 1e25e36ce6
195 files changed
+152301

No files matched your search

+56
View File
@@ -0,0 +1,56 @@
#!/bin/bash
set -euo pipefail
echo "=================================================="
echo " WickedYoda System Update & Docker Cleanup"
echo " Started: $(date)"
echo "=================================================="
#
# Step 1 - Update local setup scripts from GitHub
#
echo
echo "==> Updating setup scripts from GitHub..."
curl -fsSL https://raw.githubusercontent.com/wickedyoda/public-setupfiles/refs/heads/main/update-from_repo.sh | sudo bash
#
# Step 2 - Run the update script
#
echo
echo "==> Running system update..."
sudo ./public-setupfiles/updates_scripts/updates.sh
#
# Step 3 - Remove unused Docker images
#
echo
echo "==> Pruning unused Docker images..."
docker image prune -af
#
# Step 4 - Remove unused Docker networks
#
echo
echo "==> Pruning unused Docker networks..."
docker network prune -f
#
# Step 5 - Remove stopped containers
#
echo
echo "==> Pruning stopped Docker containers..."
docker container prune -f
#
# Step 6 - Remove unused build cache
#
echo
echo "==> Pruning Docker build cache..."
docker builder prune -af
echo
echo "=================================================="
echo " Update and cleanup completed successfully!"
echo " Finished: $(date)"
echo "=================================================="
+213
View File
@@ -0,0 +1,213 @@
#!/usr/bin/env bash
set -euo pipefail
# Docker installer for Debian 12 (bookworm) and Debian 13 (trixie).
# Installs Docker Engine, CLI, containerd, Buildx, and Docker Compose plugin.
# Optionally configures unattended upgrades for Docker packages.
SCRIPT_NAME="$(basename "$0")"
AUTO_UPDATES=true
log() {
printf "[%s] %s\n" "$(date +"%Y-%m-%d %H:%M:%S")" "$*"
}
die() {
printf "Error: %s\n" "$*" >&2
exit 1
}
usage() {
cat <<EOF
Usage: sudo ./${SCRIPT_NAME} [options]
Options:
--no-auto-updates Do not configure unattended-upgrades for Docker packages
--auto-updates Configure unattended-upgrades for Docker packages (default)
-h, --help Show this help text
Examples:
sudo ./${SCRIPT_NAME}
sudo ./${SCRIPT_NAME} --no-auto-updates
EOF
}
parse_args() {
while [[ $# -gt 0 ]]; do
case "$1" in
--no-auto-updates)
AUTO_UPDATES=false
;;
--auto-updates)
AUTO_UPDATES=true
;;
-h|--help)
usage
exit 0
;;
*)
die "Unknown option: $1"
;;
esac
shift
done
}
require_root() {
if [[ "${EUID}" -ne 0 ]]; then
die "Please run as root: sudo ./${SCRIPT_NAME}"
fi
}
check_os() {
[[ -r /etc/os-release ]] || die "Cannot read /etc/os-release"
# shellcheck disable=SC1091
source /etc/os-release
[[ "${ID:-}" == "debian" ]] || die "This script supports Debian only. Detected: ${ID:-unknown}"
case "${VERSION_CODENAME:-}" in
bookworm|trixie)
;;
*)
die "Unsupported Debian codename: ${VERSION_CODENAME:-unknown}. Supported: bookworm (12), trixie (13)."
;;
esac
log "Detected Debian ${VERSION_ID:-unknown} (${VERSION_CODENAME})"
}
install_prereqs() {
log "Installing prerequisite packages..."
apt-get update
DEBIAN_FRONTEND=noninteractive apt-get install -y \
ca-certificates \
curl \
gnupg \
lsb-release \
apt-transport-https
}
setup_docker_repo() {
local keyring_dir="/etc/apt/keyrings"
local keyring_file="${keyring_dir}/docker.asc"
local repo_file="/etc/apt/sources.list.d/docker.list"
local main_sources_file="/etc/apt/sources.list"
local repo_line
local arch
arch="$(dpkg --print-architecture)"
repo_line="deb [arch=${arch} signed-by=${keyring_file}] https://download.docker.com/linux/debian ${VERSION_CODENAME} stable"
log "Configuring Docker APT repository..."
install -m 0755 -d "${keyring_dir}"
curl -fsSL https://download.docker.com/linux/debian/gpg -o "${keyring_file}"
chmod a+r "${keyring_file}"
cat > "${repo_file}" <<EOF
${repo_line}
EOF
# Ensure the Docker repo line is present in the main sources.list as requested.
touch "${main_sources_file}"
if grep -Fq "https://download.docker.com/linux/debian ${VERSION_CODENAME} stable" "${main_sources_file}"; then
log "Docker repository already present in ${main_sources_file}."
else
log "Adding Docker repository to ${main_sources_file}..."
printf "\n# Docker repository\n%s\n" "${repo_line}" >> "${main_sources_file}"
fi
}
install_docker() {
log "Installing Docker Engine and plugins..."
apt-get update
DEBIAN_FRONTEND=noninteractive apt-get install -y \
docker-ce \
docker-ce-cli \
containerd.io \
docker-buildx-plugin \
docker-compose-plugin
}
enable_services() {
log "Enabling and starting Docker services..."
systemctl enable --now docker
systemctl enable --now containerd
}
configure_user_group() {
local target_user="${SUDO_USER:-}"
if ! getent group docker >/dev/null; then
groupadd docker
fi
if [[ -n "${target_user}" && "${target_user}" != "root" ]]; then
if id -nG "${target_user}" | tr ' ' '\n' | grep -qx docker; then
log "User '${target_user}' is already in docker group."
else
log "Adding user '${target_user}' to docker group..."
usermod -aG docker "${target_user}"
log "User '${target_user}' must log out and back in for group changes to apply."
fi
else
log "No non-root sudo user detected. Skipping docker group assignment."
fi
}
configure_unattended_upgrades() {
log "Configuring unattended-upgrades for Docker packages..."
DEBIAN_FRONTEND=noninteractive apt-get install -y unattended-upgrades
local auto_file="/etc/apt/apt.conf.d/20auto-upgrades"
local docker_upgrade_file="/etc/apt/apt.conf.d/52docker-unattended-upgrades"
cat > "${auto_file}" <<'EOF'
APT::Periodic::Update-Package-Lists "1";
APT::Periodic::Unattended-Upgrade "1";
EOF
cat > "${docker_upgrade_file}" <<'EOF'
Unattended-Upgrade::Origins-Pattern {
"origin=Docker";
};
Unattended-Upgrade::Package-Blacklist {
};
EOF
systemctl enable --now unattended-upgrades
}
print_versions() {
log "Installed versions:"
docker --version || true
docker compose version || true
containerd --version || true
}
main() {
parse_args "$@"
require_root
check_os
install_prereqs
setup_docker_repo
install_docker
enable_services
configure_user_group
if [[ "${AUTO_UPDATES}" == "true" ]]; then
configure_unattended_upgrades
else
log "Skipping unattended-upgrades configuration."
fi
print_versions
log "Docker installation complete."
log "Test with: docker run --rm hello-world"
}
main "$@"
@@ -0,0 +1,199 @@
#!/usr/bin/env bash
set -euo pipefail
# setup-docker-remote-api.sh
# Enables Docker remote API on tcp://0.0.0.0:2375 using a systemd override.
# Optional: lock port 2375 down to a single source IP.
#
# Usage:
# sudo bash setup-docker-remote-api.sh
# sudo bash setup-docker-remote-api.sh --allow-ip 10.0.84.50
#
# Notes:
# - This exposes the Docker API over unencrypted TCP.
# - Anyone who can reach port 2375 can effectively control Docker on the host.
# - Strongly recommended: use --allow-ip with your Uptime Kuma server IP.
ALLOW_IP=""
OVERRIDE_DIR="/etc/systemd/system/docker.service.d"
OVERRIDE_FILE="${OVERRIDE_DIR}/override.conf"
BACKUP_SUFFIX="$(date +%Y%m%d-%H%M%S)"
usage() {
cat <<EOF
Usage:
sudo bash $0 [--allow-ip IP]
Options:
--allow-ip IP Allow only this source IP to access TCP 2375 using iptables.
-h, --help Show this help.
Examples:
sudo bash $0
sudo bash $0 --allow-ip 10.0.84.50
EOF
}
log() {
echo "[INFO] $*"
}
warn() {
echo "[WARN] $*" >&2
}
err() {
echo "[ERROR] $*" >&2
}
require_root() {
if [[ "${EUID}" -ne 0 ]]; then
err "Run this script as root or with sudo."
exit 1
fi
}
parse_args() {
while [[ $# -gt 0 ]]; do
case "$1" in
--allow-ip)
shift
[[ $# -gt 0 ]] || { err "Missing value for --allow-ip"; exit 1; }
ALLOW_IP="$1"
;;
-h|--help)
usage
exit 0
;;
*)
err "Unknown argument: $1"
usage
exit 1
;;
esac
shift
done
}
check_prereqs() {
command -v systemctl >/dev/null 2>&1 || { err "systemctl not found."; exit 1; }
command -v docker >/dev/null 2>&1 || { err "docker not found."; exit 1; }
command -v ss >/dev/null 2>&1 || { err "ss not found."; exit 1; }
command -v curl >/dev/null 2>&1 || { err "curl not found."; exit 1; }
if ! systemctl list-unit-files | grep -q '^docker.service'; then
err "docker.service not found."
exit 1
fi
}
backup_existing_override() {
mkdir -p "${OVERRIDE_DIR}"
if [[ -f "${OVERRIDE_FILE}" ]]; then
cp -a "${OVERRIDE_FILE}" "${OVERRIDE_FILE}.bak.${BACKUP_SUFFIX}"
log "Backed up existing override to ${OVERRIDE_FILE}.bak.${BACKUP_SUFFIX}"
fi
}
write_override() {
cat > "${OVERRIDE_FILE}" <<'EOF'
[Service]
ExecStart=
ExecStart=/usr/bin/dockerd -H fd:// -H tcp://0.0.0.0:2375 --containerd=/run/containerd/containerd.sock
EOF
log "Wrote Docker systemd override: ${OVERRIDE_FILE}"
}
reload_and_restart() {
log "Reloading systemd..."
systemctl daemon-reload
log "Restarting Docker..."
systemctl restart docker
log "Checking Docker service status..."
systemctl --no-pager --full status docker.service || true
}
verify_listener() {
log "Verifying Docker is listening on TCP 2375..."
if ss -lntp | grep -q ':2375'; then
ss -lntp | grep ':2375' || true
log "Docker is listening on port 2375."
else
err "Docker is not listening on port 2375."
exit 1
fi
}
verify_local_api() {
log "Verifying local Docker API response..."
if curl -fsS http://127.0.0.1:2375/version >/dev/null; then
curl -fsS http://127.0.0.1:2375/version
echo
log "Local Docker API test succeeded."
else
err "Local Docker API test failed."
exit 1
fi
}
configure_firewall() {
if [[ -z "${ALLOW_IP}" ]]; then
warn "No --allow-ip provided. Port 2375 will remain reachable by anything that can route to this host."
return
fi
command -v iptables >/dev/null 2>&1 || {
warn "iptables not found. Skipping firewall rules."
return
}
log "Applying iptables rules to allow only ${ALLOW_IP} to TCP 2375..."
# Avoid duplicate rules
iptables -C INPUT -p tcp -s "${ALLOW_IP}" --dport 2375 -j ACCEPT 2>/dev/null || \
iptables -A INPUT -p tcp -s "${ALLOW_IP}" --dport 2375 -j ACCEPT
iptables -C INPUT -p tcp --dport 2375 -j DROP 2>/dev/null || \
iptables -A INPUT -p tcp --dport 2375 -j DROP
log "iptables rules applied."
warn "Make sure your firewall rules are saved persistently on this host."
}
show_summary() {
echo
echo "Done."
echo
echo "Docker remote API should now be available at:"
echo " tcp://$(hostname -I | awk '{print $1}'):2375"
echo
echo "Use this in Uptime Kuma:"
echo " tcp://HOST_IP:2375"
echo
if [[ -n "${ALLOW_IP}" ]]; then
echo "Access restricted to source IP:"
echo " ${ALLOW_IP}"
else
echo "No IP restriction was applied."
fi
echo
}
main() {
require_root
parse_args "$@"
check_prereqs
backup_existing_override
write_override
reload_and_restart
verify_listener
verify_local_api
configure_firewall
show_summary
}
main "$@"