feat: init project
This commit is contained in:
commit
870a0c58d1
3 files changed
+168
No files matched your search
@@ -0,0 +1,111 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
# ==========================================================
|
||||||
|
# install-docker.sh
|
||||||
|
# Install latest Docker Engine + Docker Compose plugin on
|
||||||
|
# Ubuntu (20.04 / 22.04 / 24.04). Follows the official
|
||||||
|
# Docker install guide at:
|
||||||
|
# https://docs.docker.com/engine/install/ubuntu/
|
||||||
|
#
|
||||||
|
# Run:
|
||||||
|
# sudo bash scripts/install-docker.sh
|
||||||
|
# ==========================================================
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
# -- Color helpers
|
||||||
|
info() { printf "\033[34m[INFO]\033[0m %s\n" "$*"; }
|
||||||
|
ok() { printf "\033[32m[OK]\033[0m %s\n" "$*"; }
|
||||||
|
warn() { printf "\033[33m[WARN]\033[0m %s\n" "$*"; }
|
||||||
|
err() { printf "\033[31m[ERROR]\033[0m %s\n" "$*"; }
|
||||||
|
|
||||||
|
# -- Must run as root
|
||||||
|
if [[ $EUID -ne 0 ]]; then
|
||||||
|
err "This script must be run as root (use sudo)."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# -- Must be Ubuntu
|
||||||
|
if ! grep -qi 'ubuntu' /etc/os-release 2>/dev/null; then
|
||||||
|
err "This script only supports Ubuntu. Detected:"
|
||||||
|
cat /etc/os-release 2>/dev/null || echo "(unknown)"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# ==========================================================
|
||||||
|
# 1. Uninstall old, potentially-conflicting packages
|
||||||
|
# ==========================================================
|
||||||
|
info "Removing old Docker packages (it's fine if none were installed)…"
|
||||||
|
for pkg in docker.io docker-doc docker-compose docker-compose-v2 \
|
||||||
|
podman-docker containerd runc; do
|
||||||
|
if dpkg -s "$pkg" &>/dev/null; then
|
||||||
|
apt-get remove -y "$pkg"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
ok "Old packages removed."
|
||||||
|
|
||||||
|
# ==========================================================
|
||||||
|
# 2. Install prerequisites
|
||||||
|
# ==========================================================
|
||||||
|
info "Installing prerequisites…"
|
||||||
|
apt-get update -qq
|
||||||
|
apt-get install -y -qq ca-certificates curl
|
||||||
|
ok "Prerequisites installed."
|
||||||
|
|
||||||
|
# ==========================================================
|
||||||
|
# 3. Add Docker's official GPG key
|
||||||
|
# ==========================================================
|
||||||
|
info "Adding Docker GPG key…"
|
||||||
|
install -m 0755 -d /etc/apt/keyrings
|
||||||
|
curl -fsSL https://download.docker.com/linux/ubuntu/gpg \
|
||||||
|
-o /etc/apt/keyrings/docker.asc
|
||||||
|
chmod a+r /etc/apt/keyrings/docker.asc
|
||||||
|
ok "GPG key added."
|
||||||
|
|
||||||
|
# ==========================================================
|
||||||
|
# 4. Add Docker apt repository
|
||||||
|
# ==========================================================
|
||||||
|
info "Adding Docker apt repository…"
|
||||||
|
# Derive codename from /etc/os-release (e.g. noble, jammy, focal)
|
||||||
|
. /etc/os-release
|
||||||
|
echo \
|
||||||
|
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] \
|
||||||
|
https://download.docker.com/linux/ubuntu ${VERSION_CODENAME} stable" \
|
||||||
|
| tee /etc/apt/sources.list.d/docker.list > /dev/null
|
||||||
|
apt-get update -qq
|
||||||
|
ok "Docker repository added."
|
||||||
|
|
||||||
|
# ==========================================================
|
||||||
|
# 5. Install Docker Engine + CLI + containerd + Compose plugin
|
||||||
|
# ==========================================================
|
||||||
|
info "Installing Docker Engine, CLI, containerd, and Compose plugin…"
|
||||||
|
apt-get install -y -qq docker-ce docker-ce-cli containerd.io \
|
||||||
|
docker-buildx-plugin docker-compose-plugin
|
||||||
|
ok "Docker packages installed."
|
||||||
|
|
||||||
|
# ==========================================================
|
||||||
|
# 6. Optional: add current non-root user to docker group
|
||||||
|
# ==========================================================
|
||||||
|
if [[ -n "${SUDO_USER:-}" ]]; then
|
||||||
|
info "Adding user '$SUDO_USER' to the docker group…"
|
||||||
|
usermod -aG docker "$SUDO_USER"
|
||||||
|
ok "User '$SUDO_USER' added to docker group."
|
||||||
|
warn "Log out and back in (or run 'newgrp docker') for group change to take effect."
|
||||||
|
fi
|
||||||
|
|
||||||
|
# ==========================================================
|
||||||
|
# 7. Verify installation
|
||||||
|
# ==========================================================
|
||||||
|
info "Verifying installation…"
|
||||||
|
docker --version
|
||||||
|
docker compose version
|
||||||
|
|
||||||
|
# Start & enable Docker daemon
|
||||||
|
systemctl enable docker --now 2>/dev/null || true
|
||||||
|
|
||||||
|
# Quick smoke test
|
||||||
|
if docker run --rm hello-world &>/dev/null; then
|
||||||
|
ok "Docker is working — hello-world ran successfully."
|
||||||
|
else
|
||||||
|
warn "hello-world check skipped (no network or daemon not ready)."
|
||||||
|
fi
|
||||||
|
|
||||||
|
ok "Installation complete!"
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
MIRRORS=(
|
||||||
|
"https://docker.1ms.run"
|
||||||
|
"https://docker.xuanyuan.me"
|
||||||
|
"https://docker.m.daocloud.io"
|
||||||
|
"https://dockerproxy.com"
|
||||||
|
"https://docker.nju.edu.cn"
|
||||||
|
)
|
||||||
|
|
||||||
|
DAEMON_JSON="/etc/docker/daemon.json"
|
||||||
|
|
||||||
|
if [ "$EUID" -ne 0 ]; then
|
||||||
|
echo "Please run as root (sudo)." >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Backup existing config
|
||||||
|
if [ -f "$DAEMON_JSON" ]; then
|
||||||
|
cp "$DAEMON_JSON" "${DAEMON_JSON}.bak.$(date +%s)"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Build mirrors JSON array
|
||||||
|
MIRRORS_JSON=$(printf '%s\n' "${MIRRORS[@]}" | jq -R . | jq -s .)
|
||||||
|
|
||||||
|
# Merge with existing config if present
|
||||||
|
if [ -f "$DAEMON_JSON" ]; then
|
||||||
|
jq --argjson mirrors "$MIRRORS_JSON" '. + {"registry-mirrors": $mirrors}' "$DAEMON_JSON" > "${DAEMON_JSON}.new"
|
||||||
|
else
|
||||||
|
jq -n --argjson mirrors "$MIRRORS_JSON" '{"registry-mirrors": $mirrors}' > "${DAEMON_JSON}.new"
|
||||||
|
fi
|
||||||
|
|
||||||
|
mv "${DAEMON_JSON}.new" "$DAEMON_JSON"
|
||||||
|
echo "Wrote $DAEMON_JSON"
|
||||||
|
|
||||||
|
systemctl daemon-reload
|
||||||
|
systemctl restart docker
|
||||||
|
|
||||||
|
echo "Docker mirrors configured. Verify: docker info | grep -A5 Mirrors"
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
VIMRC="${HOME}/.vimrc"
|
||||||
|
|
||||||
|
cat >> "$VIMRC" <<'EOF'
|
||||||
|
|
||||||
|
" 2-space indent
|
||||||
|
set tabstop=2
|
||||||
|
set shiftwidth=2
|
||||||
|
set softtabstop=2
|
||||||
|
set expandtab
|
||||||
|
set autoindent
|
||||||
|
filetype plugin indent on
|
||||||
|
EOF
|
||||||
|
|
||||||
|
echo "Appended 2-space indent settings to $VIMRC"
|
||||||
Reference in new issue
Block a user