From cfcc137d01e599d823716ab0748e48637b916134 Mon Sep 17 00:00:00 2001 From: IceCodeNew <32576256+IceCodeNew@users.noreply.github.com> Date: Thu, 26 Nov 2020 00:04:37 +0800 Subject: [PATCH] Revert "Revert "Add root uid judgment before running"" This reverts commit 0941d675572a5a6e4b9d8f98fe971efed04c38a1. --- install-dat-release.sh | 9 +++++++++ install-release.sh | 9 +++++++++ 2 files changed, 18 insertions(+) diff --git a/install-dat-release.sh b/install-dat-release.sh index 981b206..cf5093a 100644 --- a/install-dat-release.sh +++ b/install-dat-release.sh @@ -26,6 +26,14 @@ curl() { $(type -P curl) -L -q --retry 5 --retry-delay 10 --retry-max-time 60 "$@" } +check_if_running_as_root() { + # If you want to run as another user, please modify $UID to be owned by this user + if [[ "$UID" -ne '0' ]]; then + echo "error: You must run this script as root!" + exit 1 + fi +} + download_files() { if ! curl -R -H 'Cache-Control: no-cache' -o "${dir_tmp}/${2}" "${1}"; then echo 'error: Download failed! Please check your network or try again.' @@ -56,6 +64,7 @@ install_file() { } main() { + check_if_running_as_root download_files $DOWNLOAD_LINK_GEOIP $file_ip download_files $DOWNLOAD_LINK_GEOSITE $file_dlc check_sum diff --git a/install-release.sh b/install-release.sh index 65fda26..54b1219 100644 --- a/install-release.sh +++ b/install-release.sh @@ -44,6 +44,14 @@ systemd_cat_config() { fi } +check_if_running_as_root() { + # If you want to run as another user, please modify $UID to be owned by this user + if [[ "$UID" -ne '0' ]]; then + echo "error: You must run this script as root!" + exit 1 + fi +} + identify_the_operating_system_and_architecture() { if [[ "$(uname)" == 'Linux' ]]; then case "$(uname -m)" in @@ -491,6 +499,7 @@ show_help() { } main() { + check_if_running_as_root identify_the_operating_system_and_architecture judgment_parameters "$@"