@@ -23,10 +23,6 @@ JSON_PATH=${JSON_PATH:-/usr/local/etc/v2ray}
23
23
# Set this variable only if you are starting v2ray with multiple configuration files:
24
24
# export JSONS_PATH='/usr/local/etc/v2ray'
25
25
26
- red=$( tput setaf 1)
27
- green=$( tput setaf 2)
28
- reset=$( tput sgr0)
29
-
30
26
curl () {
31
27
$( type -P curl) -L -q --retry 5 --retry-delay 10 --retry-max-time 60 " $@ "
32
28
}
@@ -107,18 +103,23 @@ identify_the_operating_system_and_architecture() {
107
103
if [[ " $( type -P apt) " ]]; then
108
104
PACKAGE_MANAGEMENT_INSTALL=' apt install -y --no-install-recommends'
109
105
PACKAGE_MANAGEMENT_REMOVE=' apt purge -y --auto-remove'
106
+ package_provide_tput=' ncurses-bin'
110
107
elif [[ " $( type -P dnf) " ]]; then
111
108
PACKAGE_MANAGEMENT_INSTALL=' dnf install -y'
112
109
PACKAGE_MANAGEMENT_REMOVE=' dnf remove -y'
110
+ package_provide_tput=' ncurses'
113
111
elif [[ " $( type -P yum) " ]]; then
114
112
PACKAGE_MANAGEMENT_INSTALL=' yum install -y'
115
113
PACKAGE_MANAGEMENT_REMOVE=' yum remove -y'
114
+ package_provide_tput=' ncurses'
116
115
elif [[ " $( type -P zypper) " ]]; then
117
116
PACKAGE_MANAGEMENT_INSTALL=' zypper install -y --no-recommends'
118
117
PACKAGE_MANAGEMENT_REMOVE=' zypper remove -yu'
118
+ package_provide_tput=' ncurses-utils'
119
119
elif [[ " $( type -P pacman) " ]]; then
120
120
PACKAGE_MANAGEMENT_INSTALL=' pacman -Syu --noconfirm'
121
121
PACKAGE_MANAGEMENT_REMOVE=' pacman -Rsun --noconfirm'
122
+ package_provide_tput=' ncurses'
122
123
else
123
124
echo " error: The script does not support the package manager in this operating system."
124
125
exit 1
@@ -179,12 +180,13 @@ judgment_parameters() {
179
180
}
180
181
181
182
install_software () {
182
- COMPONENT=" $1 "
183
- type -P " $COMPONENT " > /dev/null 2>&1 && return
184
- if ${PACKAGE_MANAGEMENT_INSTALL} " $COMPONENT " ; then
185
- echo " info: $COMPONENT is installed."
183
+ package_name=" $1 "
184
+ file_to_detect=" $2 "
185
+ type -P " $file_to_detect " > /dev/null 2>&1 && return
186
+ if ${PACKAGE_MANAGEMENT_INSTALL} " $package_name " ; then
187
+ echo " info: $package_name is installed."
186
188
else
187
- echo " error: Installation of $COMPONENT failed, please check your network."
189
+ echo " error: Installation of $package_name failed, please check your network."
188
190
exit 1
189
191
fi
190
192
}
@@ -436,12 +438,13 @@ remove_v2ray() {
436
438
if [[ -n " $( pidof v2ray) " ]]; then
437
439
stop_v2ray
438
440
fi
439
- NAME=" $1 "
440
441
" rm" /usr/local/bin/v2ray
441
442
" rm" /usr/local/bin/v2ctl
442
443
" rm" -r " $DAT_PATH "
443
- " rm" /etc/systemd/system/v2ray.service
444
- " rm" /etc/systemd/system/v2ray@.service
444
+ " rm" ' /etc/systemd/system/v2ray.service'
445
+ " rm" ' /etc/systemd/system/v2ray@.service'
446
+ " rm" -r ' /etc/systemd/system/v2ray.service.d'
447
+ " rm" -r ' /etc/systemd/system/v2ray@.service.d'
445
448
if [[ " $? " -ne ' 0' ]]; then
446
449
echo ' error: Failed to remove V2Ray.'
447
450
exit 1
@@ -451,11 +454,17 @@ remove_v2ray() {
451
454
echo " removed: $DAT_PATH "
452
455
echo ' removed: /etc/systemd/system/v2ray.service'
453
456
echo ' removed: /etc/systemd/system/v2ray@.service'
457
+ echo ' removed: /etc/systemd/system/v2ray.service.d'
458
+ echo ' removed: /etc/systemd/system/v2ray@.service.d'
454
459
echo ' Please execute the command: systemctl disable v2ray'
455
460
echo " You may need to execute a command to remove dependent software: $PACKAGE_MANAGEMENT_REMOVE curl unzip"
456
461
echo ' info: V2Ray has been removed.'
457
462
echo ' info: If necessary, manually delete the configuration and log files.'
458
- echo " info: e.g., $JSON_PATH and /var/log/v2ray/ ..."
463
+ if [[ -n " $JSONS_PATH " ]]; then
464
+ echo " info: e.g., $JSONS_PATH and /var/log/v2ray/ ..."
465
+ else
466
+ echo " info: e.g., $JSON_PATH and /var/log/v2ray/ ..."
467
+ fi
459
468
exit 0
460
469
fi
461
470
else
@@ -483,6 +492,11 @@ main() {
483
492
identify_the_operating_system_and_architecture
484
493
judgment_parameters " $@ "
485
494
495
+ install_software " $package_provide_tput " ' tput'
496
+ red=$( tput setaf 1)
497
+ green=$( tput setaf 2)
498
+ reset=$( tput sgr0)
499
+
486
500
# Parameter information
487
501
[[ " $HELP " -eq ' 1' ]] && show_help
488
502
[[ " $CHECK " -eq ' 1' ]] && check_update
@@ -497,11 +511,11 @@ main() {
497
511
echo ' warn: Install V2Ray from a local file, but still need to make sure the network is available.'
498
512
echo -n ' warn: Please make sure the file is valid because we cannot confirm it. (Press any key) ...'
499
513
read
500
- install_software unzip
514
+ install_software ' unzip' ' unzip '
501
515
decompression " $LOCAL_FILE "
502
516
else
503
517
# Normal way
504
- install_software curl
518
+ install_software ' curl' ' curl '
505
519
get_version
506
520
NUMBER=" $? "
507
521
if [[ " $NUMBER " -eq ' 0' ]] || [[ " $FORCE " -eq ' 1' ]] || [[ " $NUMBER " -eq 2 ]]; then
@@ -512,7 +526,7 @@ main() {
512
526
echo " removed: $TMP_DIRECTORY "
513
527
exit 0
514
528
fi
515
- install_software unzip
529
+ install_software ' unzip' ' unzip '
516
530
decompression " $ZIP_FILE "
517
531
elif [[ " $NUMBER " -eq ' 1' ]]; then
518
532
echo " info: No new version. The current version of V2Ray is $CURRENT_VERSION ."
0 commit comments