Add root uid judgment before running

pull/5/head
tzwjkl 2020-06-08 03:38:51 +08:00
parent a0a1c5af20
commit 4488a5c20b
2 changed files with 16 additions and 0 deletions

View File

@ -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

View File

@ -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 "$@"