Files
ai-soulmate-local-deployment/scripts/bootstrap-ubuntu-22.04.sh
T

59 lines
2.1 KiB
Bash
Executable File

#!/usr/bin/env bash
set -Eeuo pipefail
if [[ "${EUID}" -eq 0 ]]; then
sudo_command=()
else
sudo_command=(sudo)
fi
if [[ ! -r /etc/os-release ]]; then
printf '/etc/os-release is unavailable.\n' >&2
exit 1
fi
source /etc/os-release
if [[ "${ID:-}" != "ubuntu" || "${VERSION_ID:-}" != "22.04" ]]; then
printf 'This script requires Ubuntu 22.04; found %s %s.\n' "${ID:-unknown}" "${VERSION_ID:-unknown}" >&2
exit 1
fi
timezone_name="${TIMEZONE_NAME:-Asia/Shanghai}"
deploy_user="${DEPLOY_USER:-${SUDO_USER:-}}"
"${sudo_command[@]}" timedatectl set-timezone "$timezone_name"
"${sudo_command[@]}" apt-get update
"${sudo_command[@]}" apt-get install -y ca-certificates curl gnupg git jq rsync tmux htop sysstat iotop nvme-cli smartmontools unzip
if [[ "${RUN_UPGRADE:-0}" == "1" ]]; then
"${sudo_command[@]}" apt-get upgrade -y
fi
"${sudo_command[@]}" install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg \
| "${sudo_command[@]}" gpg --dearmor --yes -o /etc/apt/keyrings/docker.gpg
"${sudo_command[@]}" chmod a+r /etc/apt/keyrings/docker.gpg
architecture="$(dpkg --print-architecture)"
codename="${VERSION_CODENAME}"
printf 'deb [arch=%s signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu %s stable\n' \
"$architecture" "$codename" \
| "${sudo_command[@]}" tee /etc/apt/sources.list.d/docker.list >/dev/null
"${sudo_command[@]}" apt-get update
"${sudo_command[@]}" apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
"${sudo_command[@]}" systemctl enable --now docker
if [[ -n "$deploy_user" && "$deploy_user" != "root" ]]; then
"${sudo_command[@]}" usermod -aG docker "$deploy_user"
printf 'Added %s to the docker group; start a new SSH session before using docker without sudo.\n' "$deploy_user"
fi
"${sudo_command[@]}" docker version
"${sudo_command[@]}" docker compose version
"${sudo_command[@]}" systemctl is-active docker
if [[ -e /var/run/reboot-required ]]; then
printf 'A reboot is required. Keep the current SSH session until key login and the reserved address are rechecked.\n'
fi