61 lines
2.0 KiB
Bash
61 lines
2.0 KiB
Bash
#!/bin/bash
|
|
|
|
APT_OPTIONS="-o Acquire::https::mirrors.martin98.com::Verify-Peer=false -o Acquire::https::mirrors.martin98.com::Verify-Host=false"
|
|
|
|
type=$(cat /etc/*release | grep ^ID= | cut -d= -f2)
|
|
release=$(cat /etc/*release | grep VERSION_CODENAME | cut -d= -f2)
|
|
components=$([ "${type}" = "debian" ] && echo "main contrib non-free non-free-firmware" || ([ "${type}" = "ubuntu" ] && echo "main restricted universe multiverse"))
|
|
|
|
# DEB822 格式
|
|
# docker.martin98.com/library/ubuntu:latest
|
|
# docker.martin98.com/library/debian:latest
|
|
if [ -f /etc/apt/sources.list.d/${type}.sources ]; then
|
|
cat > /etc/apt/sources.list.d/${type}.sources <<EOF
|
|
$(for suite in ${release} ${release}-updates ${release}-backports; do
|
|
echo "Types: deb"
|
|
echo "URIs: https://mirrors.martin98.com/repository/${type}-tsinghua-${suite}/"
|
|
echo "Suites: $suite"
|
|
echo "Components: ${components}"
|
|
echo "Signed-By: /usr/share/keyrings/${type}-archive-keyring.gpg"
|
|
echo
|
|
done)
|
|
EOF
|
|
# 传统格式
|
|
# docker.martin98.com/library/ubuntu:22.04
|
|
elif [ -f /etc/apt/sources.list ]; then
|
|
cat > /etc/apt/sources.list <<EOF
|
|
$(for suite in ${release} ${release}-updates ${release}-backports; do
|
|
echo "deb https://mirrors.martin98.com/repository/${type}-tsinghua-${suite}/ ${suite} ${components}"
|
|
done)
|
|
EOF
|
|
else
|
|
echo "没有找到合适的源"
|
|
exit 1
|
|
fi
|
|
|
|
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
|
|
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
|
|
|
|
if pidof systemd >/dev/null 2>&1; then
|
|
systemctl restart chrony && systemctl enable chrony
|
|
else
|
|
echo "systemctl 不存在,跳过 chrony 的重启"
|
|
fi
|
|
|
|
# fix vim 粘贴
|
|
if ! grep -q "set pastetoggle=" ~/.vimrc; then
|
|
echo "set pastetoggle=" >> ~/.vimrc
|
|
fi |