跳转到内容

Ubuntu/quick-setup.sh:修订间差异

来自UbuntuStudioCN
删除的内容 添加的内容
创建页面,内容为“#!/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. Canno…”
(没有差异)

2025年6月24日 (二) 15:09的版本

  1. !/bin/bash

echo "--- Initial Setup Script ---"

  1. 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

  1. 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."

  1. 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."

  1. 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

  1. 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
  2. Types: deb-src
  3. URIs: https://mirrors.tuna.tsinghua.edu.cn/ubuntu
  4. Suites: ${OS_VERSION} ${OS_VERSION}-updates ${OS_VERSION}-backports
  5. Components: main restricted universe multiverse
  6. Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg
  1. 以下安全更新软件源包含了官方源与镜像站配置,如有需要可自行修改注释切换

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

  1. Types: deb-src
  2. URIs: https://mirrors.tuna.tsinghua.edu.cn/ubuntu
  3. Suites: ${OS_VERSION}-security
  4. Components: main restricted universe multiverse
  5. Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg
  1. 预发布软件源,不建议启用
  1. Types: deb
  2. URIs: https://mirrors.tuna.tsinghua.edu.cn/ubuntu
  3. Suites: ${OS_VERSION}-proposed
  4. Components: main restricted universe multiverse
  5. Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg
  1. # Types: deb-src
  2. # URIs: https://mirrors.tuna.tsinghua.edu.cn/ubuntu
  3. # Suites: ${OS_VERSION}-proposed
  4. # Components: main restricted universe multiverse
  5. # 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. ---"