From 1be785699207be4f16a96d4d2758ad981a064f71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=98=9F=E5=85=89-k?= <36470587+kxgx@users.noreply.github.com> Date: Sun, 12 Jan 2025 04:06:31 +0000 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20install.sh?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/install.sh | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/bin/install.sh b/bin/install.sh index 716e5e5..7ed79be 100644 --- a/bin/install.sh +++ b/bin/install.sh @@ -44,16 +44,18 @@ if [ "$CURRENT_LANG" != "$DEFAULT_LANG" ]; then export LANG=$DEFAULT_LANG export LC_ALL=$DEFAULT_LANG - # 检查 locale.gen 中是否已存在 DEFAULT_LANG - if ! grep -q "$DEFAULT_LANG UTF-8" /etc/locale.gen; then - # 如果不存在,则添加到 locale.gen - echo "$DEFAULT_LANG UTF-8" | sudo tee -a /etc/locale.gen - # 确保 locale.gen 被正确更新 - if [ $? -ne 0 ]; then - echo "无法更新 locale.gen 文件" >&2 - exit 1 - fi +# 检查 locale.gen 中是否已存在 DEFAULT_LANG +if ! grep -qxE "^\s*$DEFAULT_LANG UTF-8\s*$" /etc/locale.gen; then + # 如果不存在,则添加到 locale.gen + echo "$DEFAULT_LANG UTF-8" | sudo tee -a /etc/locale.gen + # 确保 locale.gen 被正确更新 + if [ $? -ne 0 ]; then + echo "无法更新 locale.gen 文件" >&2 + exit 1 fi +else + echo "语言环境 $DEFAULT_LANG 已在 locale.gen 中设置,跳过添加。" +fi # 生成 locale if ! sudo locale-gen; then