mirror of
https://github.com/cedar2025/hysteria.git
synced 2025-09-01 06:01:47 +00:00
fix(script): auto sudo when run from stdin
This commit is contained in:
@@ -91,7 +91,7 @@ curl() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
mktemp() {
|
mktemp() {
|
||||||
command mktemp "$@" "hyservinst.XXXXXXXXXX"
|
command mktemp "$@" "/tmp/hyservinst.XXXXXXXXXX"
|
||||||
}
|
}
|
||||||
|
|
||||||
tput() {
|
tput() {
|
||||||
@@ -287,6 +287,34 @@ is_user_exists() {
|
|||||||
id "$_user" > /dev/null 2>&1
|
id "$_user" > /dev/null 2>&1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rerun_with_sudo() {
|
||||||
|
if ! has_command sudo; then
|
||||||
|
return 13
|
||||||
|
fi
|
||||||
|
|
||||||
|
local _target_script
|
||||||
|
|
||||||
|
if has_prefix "$0" "/dev/fd/"; then
|
||||||
|
local _tmp_script="$(mktemp)"
|
||||||
|
chmod +x "$_tmp_script"
|
||||||
|
|
||||||
|
if has_command curl; then
|
||||||
|
curl -o "$_tmp_script" 'https://get.hy2.sh/'
|
||||||
|
elif has_command wget; then
|
||||||
|
wget -O "$_tmp_script" 'https://get.hy2.sh'
|
||||||
|
else
|
||||||
|
return 127
|
||||||
|
fi
|
||||||
|
|
||||||
|
_target_script="$_tmp_script"
|
||||||
|
else
|
||||||
|
_target_script="$0"
|
||||||
|
fi
|
||||||
|
|
||||||
|
note "Re-running this script with sudo, you can also specify FORCE_NO_ROOT=1 to force this script running with current user."
|
||||||
|
exec_sudo "$_target_script" "${SCRIPT_ARGS[@]}"
|
||||||
|
}
|
||||||
|
|
||||||
check_permission() {
|
check_permission() {
|
||||||
if [[ "$UID" -eq '0' ]]; then
|
if [[ "$UID" -eq '0' ]]; then
|
||||||
return
|
return
|
||||||
@@ -299,10 +327,7 @@ check_permission() {
|
|||||||
warning "FORCE_NO_ROOT=1 is specified, we will process without root and you may encounter the insufficient privilege error."
|
warning "FORCE_NO_ROOT=1 is specified, we will process without root and you may encounter the insufficient privilege error."
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
if has_command sudo; then
|
if ! rerun_with_sudo; then
|
||||||
note "Re-running this script with sudo, you can also specify FORCE_NO_ROOT=1 to force this script running with current user."
|
|
||||||
exec_sudo "$0" "${SCRIPT_ARGS[@]}"
|
|
||||||
else
|
|
||||||
error "Please run this script with root or specify FORCE_NO_ROOT=1 to force this script running with current user."
|
error "Please run this script with root or specify FORCE_NO_ROOT=1 to force this script running with current user."
|
||||||
exit 13
|
exit 13
|
||||||
fi
|
fi
|
||||||
|
Reference in New Issue
Block a user