From 4488a5c20b50e30bfc604842db4fe3a4e508e7c8 Mon Sep 17 00:00:00 2001 From: tzwjkl Date: Mon, 8 Jun 2020 03:38:51 +0800 Subject: [PATCH] Add root uid judgment before running --- install-dat-release.sh | 8 ++++++++ install-release.sh | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/install-dat-release.sh b/install-dat-release.sh index e85b278..523a692 100644 --- a/install-dat-release.sh +++ b/install-dat-release.sh @@ -17,6 +17,13 @@ V2RAY="/usr/local/lib/v2ray/" DOWNLOAD_LINK_GEOIP="https://github.com/v2ray/geoip/releases/latest/download/geoip.dat" DOWNLOAD_LINK_GEOSITE="https://github.com/v2ray/domain-list-community/releases/latest/download/dlc.dat" +check_if_running_as_root() { + if [ $UID != "0" ]; then + echo "error: You must run this script as root!" + exit 1 + fi +} + download_geoip() { curl -L -H 'Cache-Control: no-cache' -o "${V2RAY}geoip.dat.new" "$DOWNLOAD_LINK_GEOIP" if [ "$?" -ne '0' ]; then @@ -64,6 +71,7 @@ rename_new() { } main() { + check_if_running_as_root download_geoip download_geosite rename_new diff --git a/install-release.sh b/install-release.sh index b415eab..5a459f8 100644 --- a/install-release.sh +++ b/install-release.sh @@ -12,6 +12,13 @@ # If the script executes incorrectly, go to: # https://github.com/v2fly/fhs-install-v2ray/issues +check_if_running_as_root() { + if [ $UID != "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 @@ -459,6 +466,7 @@ show_help() { } main() { + check_if_running_as_root identify_the_operating_system_and_architecture judgment_parameters "$@"