Ubuntu/quick-setup.sh
- !/bin/bash
echo "--- Initial Setup Script ---"
- 1. Read OS_VERSION from /etc/os-release
if [ -f "/etc/os-release" ]; then
source /etc/os-release if [ -n "$UBUNTU_CODENAME" ]; then OS_VERSION="$UBUNTU_CODENAME" echo "Detected Ubuntu codename: $OS_VERSION" else echo "Error: UBUNTU_CODENAME not found in /etc/os-release. Cannot determine OS version." exit 1 fi
else
echo "Error: /etc/os-release not found. Cannot determine OS version." exit 1
fi
- 2. Create /etc/apt/apt.conf.d/99proxy
echo "Creating /etc/apt/apt.conf.d/99proxy with proxy settings..." sudo bash -c 'cat <<EOF > /etc/apt/apt.conf.d/99proxy // Acquire::http::proxy "http://proxy.company.com:80/"; // Acquire::https::proxy "https://proxy.company.com:80/"; EOF' echo "Proxy configuration created. Lines are commented out by default."
- 3. Backup existing sources.list and sources.list.d
echo "Backing up existing /etc/apt/sources.list and /etc/apt/sources.list.d/*..." if [ -f "/etc/apt/sources.list" ]; then
sudo mv /etc/apt/sources.list /etc/apt/sources.list.bak echo "Backed up /etc/apt/sources.list to /etc/apt/sources.list.bak"
fi
if [ -d "/etc/apt/sources.list.d" ]; then
for f in /etc/apt/sources.list.d/*; do if [ -f "$f" ]; then sudo mv "$f" "${f}.bak" echo "Backed up $f to ${f}.bak" fi done
fi echo "Existing APT source configurations backed up."
- 4. Create /etc/apt/sources.list.d/tuna.sources
echo "Creating /etc/apt/sources.list.d/tuna.sources with Tsinghua TUNA mirror for $OS_VERSION..." sudo bash -c "cat <<EOF > /etc/apt/sources.list.d/tuna.sources Types: deb URIs: https://mirrors.tuna.tsinghua.edu.cn/ubuntu Suites: ${OS_VERSION} ${OS_VERSION}-updates ${OS_VERSION}-backports Components: main restricted universe multiverse Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg
- 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
- Types: deb-src
- URIs: https://mirrors.tuna.tsinghua.edu.cn/ubuntu
- Suites: ${OS_VERSION} ${OS_VERSION}-updates ${OS_VERSION}-backports
- Components: main restricted universe multiverse
- Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg
- 以下安全更新软件源包含了官方源与镜像站配置,如有需要可自行修改注释切换
Types: deb URIs: https://mirrors.tuna.tsinghua.edu.cn/ubuntu Suites: ${OS_VERSION}-security Components: main restricted universe multiverse Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg
- Types: deb-src
- URIs: https://mirrors.tuna.tsinghua.edu.cn/ubuntu
- Suites: ${OS_VERSION}-security
- Components: main restricted universe multiverse
- Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg
- 预发布软件源,不建议启用
- Types: deb
- URIs: https://mirrors.tuna.tsinghua.edu.cn/ubuntu
- Suites: ${OS_VERSION}-proposed
- Components: main restricted universe multiverse
- Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg
- # Types: deb-src
- # URIs: https://mirrors.tuna.tsinghua.edu.cn/ubuntu
- # Suites: ${OS_VERSION}-proposed
- # Components: main restricted universe multiverse
- # Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg
EOF" echo "Tsinghua TUNA mirror configuration added to /etc/apt/sources.list.d/tuna.sources"
echo "--- Setup complete. It is recommended to run 'sudo apt update' now. ---"