From c94f3346632b038fe65176dcb9c61994e436c203 Mon Sep 17 00:00:00 2001 From: bin456789 Date: Thu, 4 Dec 2025 19:43:52 +0800 Subject: [PATCH] =?UTF-8?q?core:=20=E7=94=A8=20sh=20=E8=BF=90=E8=A1=8C?= =?UTF-8?q?=E6=97=B6=E8=87=AA=E5=8A=A8=E5=88=87=E6=8D=A2=E6=88=90=20bash?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- reinstall.sh | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/reinstall.sh b/reinstall.sh index 3edb7e1..7ea47a9 100644 --- a/reinstall.sh +++ b/reinstall.sh @@ -22,6 +22,22 @@ export LC_ALL=C # 不要漏了最后的 $PATH,否则会找不到 windows 系统程序例如 diskpart export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:$PATH +# 如果不是 bash 的话,继续执行会有语法错误,因此在这里判断是否 bash +if [ -z "$BASH" ]; then + if [ -f /etc/alpine-release ]; then + if ! apk add bash; then + echo "Error while install bash." >&2 + exit 1 + fi + fi + if command -v bash >/dev/null; then + exec bash "$0" "$@" + else + echo "Please run this script with bash." >&2 + exit 1 + fi +fi + # 记录日志,过滤含有 password 的行 exec > >(tee >(grep -iv password >>/reinstall.log)) 2>&1 THIS_SCRIPT=$(readlink -f "$0") @@ -35,11 +51,6 @@ trap_err() { sed -n "$line_no"p "$THIS_SCRIPT" } -if ! { [ -n "$BASH" ] && [ -n "$BASH_VERSION" ]; }; then - echo "Please run this script with bash." >&2 - exit 1 -fi - usage_and_exit() { if is_in_windows; then reinstall_____='.\reinstall.bat'