From 2bc6fb6497467b430343ad56c5344909c663986b Mon Sep 17 00:00:00 2001 From: topuser <1549469775@qq.com> Date: Thu, 2 Apr 2026 11:48:20 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20'ubuntu/init.sh'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ubuntu/init.sh | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 ubuntu/init.sh diff --git a/ubuntu/init.sh b/ubuntu/init.sh new file mode 100644 index 0000000..5c9e86d --- /dev/null +++ b/ubuntu/init.sh @@ -0,0 +1,74 @@ +#!/bin/bash +set -euo pipefail + +# ====================== 配置项 ====================== +# 已改为 FiraCode Nerd Font +NERD_FONTS=("FiraCode") +# 字体安装目录 +FONT_DIR="$HOME/.local/share/fonts" +# ==================================================== + +echo "=============================================" +echo " Ubuntu 一键开发环境配置脚本开始执行 " +echo "=============================================" + +# 1. 安装依赖(curl、unzip、fontconfig) +echo -e "\n[1/3] 安装系统依赖..." +sudo apt update && sudo apt install -y curl unzip fontconfig + +# 2. 安装 Nerd 字体 +echo -e "\n[2/3] 安装 FiraCode Nerd Font..." +mkdir -p "$FONT_DIR" + +for font in "${NERD_FONTS[@]}"; do + echo "正在下载 ${font} Nerd Font..." + FONT_ZIP="${font}.zip" + curl -fsSL "https://github.com/ryanoasis/nerd-fonts/releases/latest/download/${FONT_ZIP}" -o "$FONT_ZIP" + + echo "解压字体到 ${FONT_DIR}..." + unzip -q -o "$FONT_ZIP" -d "$FONT_DIR" + + echo "清理临时文件..." + rm -f "$FONT_ZIP" +done + +# 刷新字体缓存 +fc-cache -fv "$FONT_DIR" +echo -e "✅ FiraCode Nerd Font 安装完成!" + +# 3. 安装 Starship 终端美化工具 +echo -e "\n[3/3] 安装 Starship 终端美化..." +curl -fsSL https://starship.rs/install.sh | sh -s -- -y + +# 配置 Starship 到 shell 配置文件(自动适配 bash/zsh) +if [ -n "$BASH_VERSION" ]; then + SHELL_CONFIG="$HOME/.bashrc" +elif [ -n "$ZSH_VERSION" ]; then + SHELL_CONFIG="$HOME/.zshrc" +else + SHELL_CONFIG="$HOME/.bashrc" +fi + +# 写入starship初始化配置 +if ! grep -q "starship init" "$SHELL_CONFIG"; then + echo 'eval "$(starship init bash)"' >> "$SHELL_CONFIG" + echo -e "✅ Starship 已配置到 ${SHELL_CONFIG}" +fi + +# 4. 安装 Volta Node 版本管理器 +echo -e "\n[4/4] 安装 Volta 版本管理器..." +curl -fsSL https://get.volta.sh | bash + +# 配置 Volta 环境变量 +VOLTA_HOME="$HOME/.volta" +if ! grep -q "VOLTA_HOME" "$SHELL_CONFIG"; then + echo 'export VOLTA_HOME="$HOME/.volta"' >> "$SHELL_CONFIG" + echo 'export PATH="$VOLTA_HOME/bin:$PATH"' >> "$SHELL_CONFIG" + echo -e "✅ Volta 环境变量已配置到 ${SHELL_CONFIG}" +fi + +echo -e "\n=============================================" +echo " ✅ 所有工具安装配置完成! " +echo " 请执行以下命令立即生效,或重启终端:" +echo " source $SHELL_CONFIG" +echo "=============================================" \ No newline at end of file