init/init-apt.sh
Martin 42261906a9
All checks were successful
Build Docker Image / Explore-Gitea-Actions (push) Successful in 11s
[*] 忽略重复
2025-01-22 17:42:05 +08:00

46 lines
1.9 KiB
Bash

#!/bin/bash
APT_OPTIONS="-o Acquire::https::mirrors.martin98.com::Verify-Peer=false -o Acquire::https::mirrors.martin98.com::Verify-Host=false"
lsb_dist=$(cat /etc/*release | grep ^ID= | cut -d= -f2) # ubuntu or debian?
release=$(cat /etc/*release | grep VERSION_CODENAME | cut -d= -f2) # ubuntu(jammy oracular) debian(bookworm)....
components=$([ "${lsb_dist=}" = "debian" ] && echo "main contrib non-free non-free-firmware" || ([ "${lsb_dist=}" = "ubuntu" ] && echo "main restricted universe multiverse"))
# 删除 DEB822 格式
if [ -f /etc/apt/sources.list.d/${lsb_dist}.sources ]; then
rm /etc/apt/sources.list.d/${lsb_dist}.sources
fi
# 配置镜像源
echo "deb https://mirrors.martin98.com/repository/$lsb_dist $release $components" > /etc/apt/sources.list
# docker
if [ ! -f /usr/share/keyrings/docker-archive-keyring.gpg ]; then
curl -fsSL https://mirrors.martin98.com/repository/docker-ce/linux/$lsb_dist/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
fi
echo "deb [signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://mirrors.martin98.com/repository/docker-ce/linux/$lsb_dist $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
# 关闭交互式弹窗
echo 'debconf debconf/frontend select Noninteractive' | debconf-set-selections
apt update $APT_OPTIONS && apt install $APT_OPTIONS -y ca-certificates curl && update-ca-certificates
apt update && apt upgrade -y
# NTP
# 启用阿里云 ntp
if pidof systemd >/dev/null 2>&1; then
apt install chrony -y
cat > /etc/chrony.conf <<EOF
server ntp4.aliyun.com minpoll 4 maxpoll 10 iburst
server ntp5.aliyun.com iburst
driftfile /var/lib/chrony/drift
allow 127.0.0.1
EOF
systemctl restart chrony && systemctl enable chrony
else
echo "systemctl 不存在,跳过 chrony 的重启"
fi
# fix vim 粘贴
if pidof vim >/dev/null 2>&1; then
if ! grep -q "set pastetoggle=" ~/.vimrc; then
echo "set pastetoggle=" >> ~/.vimrc
fi
fi