fix: Update require password

This commit is contained in:
shenmo 2024-10-29 17:09:05 +08:00
parent ed3db29806
commit b060000028
2 changed files with 30 additions and 29 deletions
tool
store-helper
update-upgrade

@ -2,7 +2,11 @@
# We use sudo twice to avoid ACE bug here # We use sudo twice to avoid ACE bug here
# https://gitee.com/amber-ce/amber-ce-bookworm/commit/43e1a1599ede474b37e41aa10c53fd8afc4d35a1 # https://gitee.com/amber-ce/amber-ce-bookworm/commit/43e1a1599ede474b37e41aa10c53fd8afc4d35a1
function zenity() { #!/bin/bash
# We use sudo twice to avoid ACE bug here
# https://gitee.com/amber-ce/amber-ce-bookworm/commit/43e1a1599ede474b37e41aa10c53fd8afc4d35a1
function zenity_prompt() {
if [[ -e /usr/bin/garma ]]; then if [[ -e /usr/bin/garma ]]; then
garma "$@" garma "$@"
else else
@ -10,36 +14,33 @@ function zenity() {
fi fi
} }
# 检查sudo是否需要密码 # 检查sudo是否需要密码
if sudo sudo -n true 2>/dev/null; then if sudo -n true 2>/dev/null; then
echo "sudo 无需密码,继续执行" echo "sudo 无需密码,继续执行"
else else
# 循环输入密码直到成功或用户取消
# 循环输入密码直到成功或用户取消 while true; do
while true; do # 使用zenity弹出密码输入框
# 使用zenity弹出密码输入框 PASSWORD=$(zenity_prompt --password --title="需要sudo权限")
PASSWORD=$(zenity --password --title="需要sudo权限" )
# 检查用户是否取消输入
# 检查用户是否取消输入 if [ -z "$PASSWORD" ]; then
if [ -z "$PASSWORD" ]; then zenity_prompt --error --text="操作已取消"
zenity --error --text="操作已取消" exit 1
exit 1 fi
fi
# 尝试使用输入的密码执行sudo命令
# 尝试使用输入的密码执行sudo命令 echo "$PASSWORD" | sudo -S -v 2>/dev/null
echo "$PASSWORD" | sudo sudo -S true 2>/dev/null
# 检查sudo是否成功
# 检查sudo是否成功 if [ $? -eq 0 ]; then
if [ $? -eq 0 ]; then echo "密码正确,继续执行"
echo "密码正确,继续执行" break
break else
else zenity_prompt --error --text="密码错误,请重新输入"
zenity --error --text="密码错误,请重新输入" fi
fi done
done
fi fi
# 使用sudo命令执行目标程序
echo "$PASSWORD" | sudo sudo -S "$@" echo "$PASSWORD" | sudo sudo -S "$@"

@ -1,6 +1,6 @@
#!/bin/bash #!/bin/bash
if [ "$(id -u)" != "0" ] ; then if [ "$(id -u)" != "0" ] ; then
if [[ IS_ACE_ENV="1" ]];then if [ "$IS_ACE_ENV" = "1" ];then
/opt/durapps/spark-store/bin/store-helper/pass-auth.sh "$0" "$@" /opt/durapps/spark-store/bin/store-helper/pass-auth.sh "$0" "$@"
else else
pkexec "$0" "$@" pkexec "$0" "$@"