From f81ce6916f9dc2b7296d1f43e668244ce947592e Mon Sep 17 00:00:00 2001 From: Jensfrank Date: Wed, 26 Jun 2024 15:29:50 +0800 Subject: [PATCH] Update nodeloc_vps_autotest.sh --- nodeloc_vps_autotest.sh | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/nodeloc_vps_autotest.sh b/nodeloc_vps_autotest.sh index 9cba3ea..0553b56 100644 --- a/nodeloc_vps_autotest.sh +++ b/nodeloc_vps_autotest.sh @@ -6,6 +6,16 @@ GREEN='\033[0;32m' YELLOW='\033[1;33m' NC='\033[0m' # No Color +# 检查 root 权限并获取 sudo 权限 +if [ "$(id -u)" != "0" ]; then + echo "此脚本需要 root 权限运行。" + if ! sudo -v; then + echo "无法获取 sudo 权限,退出脚本。" + exit 1 + fi + echo "已获取 sudo 权限。" +fi + #更新系统 update_system() { if command -v apt &>/dev/null; then