mirror of
https://github.com/Dichgrem/dotfiles.git
synced 2025-12-17 05:22:00 -05:00
fix:update_setup.sh
This commit is contained in:
@@ -2,16 +2,33 @@
|
|||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
SCRIPT_NAME=$(basename "$0")
|
SCRIPT_NAME=$(basename "$0")
|
||||||
echo "\n=== Ubuntu Repos and Plugins Setup Script ===\n"
|
echo -e "\n=== Ubuntu Repos and Plugins Setup Script ===\n"
|
||||||
|
|
||||||
# Determine Ubuntu codename
|
# Detect Ubuntu codename
|
||||||
CODENAME=$(lsb_release -cs)
|
CODENAME=$(lsb_release -cs)
|
||||||
echo "Detected Ubuntu codename: $CODENAME"
|
echo "Detected Ubuntu codename: $CODENAME"
|
||||||
|
|
||||||
# Function to add PPA if not present
|
# Docker 官方支持的 Ubuntu 版本
|
||||||
|
DOCKER_SUPPORTED_CODENAMES=("focal" "jammy")
|
||||||
|
|
||||||
|
# 如果当前 codename 不在支持列表,回退到 jammy
|
||||||
|
if [[ ! " ${DOCKER_SUPPORTED_CODENAMES[*]} " =~ " ${CODENAME} " ]]; then
|
||||||
|
echo "Docker does not officially support '$CODENAME', falling back to 'jammy'"
|
||||||
|
CODENAME="jammy"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# ==== 清理旧 Docker 源和包 ====
|
||||||
|
echo "Cleaning old Docker sources and packages..."
|
||||||
|
sudo rm -f /etc/apt/sources.list.d/docker.list
|
||||||
|
sudo rm -f /usr/share/keyrings/docker-archive-keyring.gpg
|
||||||
|
sudo apt remove -y docker docker-engine docker.io containerd runc || true
|
||||||
|
|
||||||
|
# ==== 函数 ====
|
||||||
|
# 添加 PPA
|
||||||
add_ppa() {
|
add_ppa() {
|
||||||
local PPA="$1"
|
local PPA="$1"
|
||||||
if ! grep -Rq "${PPA#*:}" /etc/apt/sources.list.d; then
|
local PPA_NAME="${PPA#*:}"
|
||||||
|
if ! grep -Rq "$PPA_NAME" /etc/apt/sources.list.d 2>/dev/null; then
|
||||||
echo "Adding PPA: $PPA"
|
echo "Adding PPA: $PPA"
|
||||||
sudo add-apt-repository -y "$PPA"
|
sudo add-apt-repository -y "$PPA"
|
||||||
else
|
else
|
||||||
@@ -19,36 +36,35 @@ add_ppa() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# Function to add Docker repo
|
# 添加 Docker 源
|
||||||
add_docker_repo() {
|
add_docker_repo() {
|
||||||
local KEYRING="/usr/share/keyrings/docker-archive-keyring.gpg"
|
local KEYRING="/usr/share/keyrings/docker-archive-keyring.gpg"
|
||||||
if [ ! -f "$KEYRING" ]; then
|
if [ ! -f "$KEYRING" ]; then
|
||||||
echo "Adding Docker GPG key and repository"
|
echo "Adding Docker GPG key and repository"
|
||||||
curl -fsSL https://download.docker.com/linux/ubuntu/gpg |
|
curl -fsSL https://download.docker.com/linux/ubuntu/gpg |
|
||||||
sudo gpg --dearmor -o "$KEYRING"
|
sudo gpg --dearmor -o "$KEYRING"
|
||||||
echo "deb [arch=amd64 signed-by=$KEYRING] https://download.docker.com/linux/ubuntu $CODENAME stable" |
|
echo "deb [arch=$(dpkg --print-architecture) signed-by=$KEYRING] https://download.docker.com/linux/ubuntu $CODENAME stable" |
|
||||||
sudo tee /etc/apt/sources.list.d/docker.list >/dev/null
|
sudo tee /etc/apt/sources.list.d/docker.list >/dev/null
|
||||||
else
|
else
|
||||||
echo "Docker repository already configured"
|
echo "Docker repository already configured"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# Add PPAs
|
# ==== 添加 PPA ====
|
||||||
add_ppa ppa:fish-shell/release-3
|
add_ppa ppa:fish-shell/release-3
|
||||||
add_ppa ppa:neovim-ppa/unstable
|
add_ppa ppa:neovim-ppa/unstable
|
||||||
add_ppa ppa:zhangsongcui3371/fastfetch
|
add_ppa ppa:zhangsongcui3371/fastfetch
|
||||||
|
|
||||||
# Add Docker repo
|
# ==== 添加 Docker 源 ====
|
||||||
add_docker_repo
|
add_docker_repo
|
||||||
|
|
||||||
# Update package list
|
# ==== 更新软件列表 ====
|
||||||
echo "\nUpdating package lists..."
|
echo -e "\nUpdating package lists..."
|
||||||
sudo apt update
|
sudo apt update
|
||||||
|
|
||||||
# Core packages to install
|
# 核心软件包
|
||||||
CORE_PKGS=(docker-ce docker-ce-cli containerd.io fastfetch neovim fish tealdeer)
|
CORE_PKGS=(docker-ce docker-ce-cli containerd.io fastfetch neovim fish tealdeer)
|
||||||
|
|
||||||
# Install each package, skip if not found
|
|
||||||
for pkg in "${CORE_PKGS[@]}"; do
|
for pkg in "${CORE_PKGS[@]}"; do
|
||||||
if apt-cache show "$pkg" >/dev/null 2>&1; then
|
if apt-cache show "$pkg" >/dev/null 2>&1; then
|
||||||
echo "Installing $pkg..."
|
echo "Installing $pkg..."
|
||||||
@@ -58,20 +74,20 @@ for pkg in "${CORE_PKGS[@]}"; do
|
|||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
# Fisher and fish plugins
|
# ==== 安装 fisher 和 fish 插件 ====
|
||||||
echo "\nInstalling Fisher and fish plugins..."
|
echo -e "\nInstalling Fisher and fish plugins..."
|
||||||
fish -c 'curl -sL https://git.io/fisher | source && fisher install jorgebucaran/fisher'
|
fish -c 'curl -sL https://git.io/fisher | source && fisher install jorgebucaran/fisher'
|
||||||
fish -c 'fisher install bruno-ricard/fish-autopair Pure-Fish/pure'
|
fish -c 'fisher install bruno-ricard/fish-autopair Pure-Fish/pure'
|
||||||
|
|
||||||
# Atuin installation
|
# ==== 安装 Atuin ====
|
||||||
if ! command -v atuin >/dev/null 2>&1; then
|
if ! command -v atuin >/dev/null 2>&1; then
|
||||||
echo "\nInstalling Atuin"
|
echo -e "\nInstalling Atuin..."
|
||||||
curl -sS https://raw.githubusercontent.com/ellie/atuin/main/install.sh | bash
|
curl -sS https://raw.githubusercontent.com/ellie/atuin/main/install.sh | bash
|
||||||
else
|
else
|
||||||
echo "Atuin already installed"
|
echo "Atuin already installed"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Change default shell to fish
|
# ==== 改默认 shell 为 fish ====
|
||||||
if [ "$SHELL" != "$(which fish)" ]; then
|
if [ "$SHELL" != "$(which fish)" ]; then
|
||||||
echo "Changing default shell to fish"
|
echo "Changing default shell to fish"
|
||||||
chsh -s "$(which fish)"
|
chsh -s "$(which fish)"
|
||||||
@@ -79,4 +95,4 @@ else
|
|||||||
echo "Default shell is already fish"
|
echo "Default shell is already fish"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "\n=== Setup Complete! Restart your terminal to apply changes. ==="
|
echo -e "\n=== Setup Complete! Restart your terminal to apply changes. ==="
|
||||||
|
|||||||
Reference in New Issue
Block a user