Skip to content

Commit ddc1abd

Browse files
authored
Merge pull request v2fly#142 from v2fly/develop
2 parents e3f9f19 + c40ab4a commit ddc1abd

File tree

1 file changed

+30
-16
lines changed

1 file changed

+30
-16
lines changed

install-release.sh

+30-16
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,6 @@ JSON_PATH=${JSON_PATH:-/usr/local/etc/v2ray}
2323
# Set this variable only if you are starting v2ray with multiple configuration files:
2424
# export JSONS_PATH='/usr/local/etc/v2ray'
2525

26-
red=$(tput setaf 1)
27-
green=$(tput setaf 2)
28-
reset=$(tput sgr0)
29-
3026
curl() {
3127
$(type -P curl) -L -q --retry 5 --retry-delay 10 --retry-max-time 60 "$@"
3228
}
@@ -107,18 +103,23 @@ identify_the_operating_system_and_architecture() {
107103
if [[ "$(type -P apt)" ]]; then
108104
PACKAGE_MANAGEMENT_INSTALL='apt install -y --no-install-recommends'
109105
PACKAGE_MANAGEMENT_REMOVE='apt purge -y --auto-remove'
106+
package_provide_tput='ncurses-bin'
110107
elif [[ "$(type -P dnf)" ]]; then
111108
PACKAGE_MANAGEMENT_INSTALL='dnf install -y'
112109
PACKAGE_MANAGEMENT_REMOVE='dnf remove -y'
110+
package_provide_tput='ncurses'
113111
elif [[ "$(type -P yum)" ]]; then
114112
PACKAGE_MANAGEMENT_INSTALL='yum install -y'
115113
PACKAGE_MANAGEMENT_REMOVE='yum remove -y'
114+
package_provide_tput='ncurses'
116115
elif [[ "$(type -P zypper)" ]]; then
117116
PACKAGE_MANAGEMENT_INSTALL='zypper install -y --no-recommends'
118117
PACKAGE_MANAGEMENT_REMOVE='zypper remove -yu'
118+
package_provide_tput='ncurses-utils'
119119
elif [[ "$(type -P pacman)" ]]; then
120120
PACKAGE_MANAGEMENT_INSTALL='pacman -Syu --noconfirm'
121121
PACKAGE_MANAGEMENT_REMOVE='pacman -Rsun --noconfirm'
122+
package_provide_tput='ncurses'
122123
else
123124
echo "error: The script does not support the package manager in this operating system."
124125
exit 1
@@ -179,12 +180,13 @@ judgment_parameters() {
179180
}
180181

181182
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."
186188
else
187-
echo "error: Installation of $COMPONENT failed, please check your network."
189+
echo "error: Installation of $package_name failed, please check your network."
188190
exit 1
189191
fi
190192
}
@@ -436,12 +438,13 @@ remove_v2ray() {
436438
if [[ -n "$(pidof v2ray)" ]]; then
437439
stop_v2ray
438440
fi
439-
NAME="$1"
440441
"rm" /usr/local/bin/v2ray
441442
"rm" /usr/local/bin/v2ctl
442443
"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'
445448
if [[ "$?" -ne '0' ]]; then
446449
echo 'error: Failed to remove V2Ray.'
447450
exit 1
@@ -451,11 +454,17 @@ remove_v2ray() {
451454
echo "removed: $DAT_PATH"
452455
echo 'removed: /etc/systemd/system/v2ray.service'
453456
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'
454459
echo 'Please execute the command: systemctl disable v2ray'
455460
echo "You may need to execute a command to remove dependent software: $PACKAGE_MANAGEMENT_REMOVE curl unzip"
456461
echo 'info: V2Ray has been removed.'
457462
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
459468
exit 0
460469
fi
461470
else
@@ -483,6 +492,11 @@ main() {
483492
identify_the_operating_system_and_architecture
484493
judgment_parameters "$@"
485494

495+
install_software "$package_provide_tput" 'tput'
496+
red=$(tput setaf 1)
497+
green=$(tput setaf 2)
498+
reset=$(tput sgr0)
499+
486500
# Parameter information
487501
[[ "$HELP" -eq '1' ]] && show_help
488502
[[ "$CHECK" -eq '1' ]] && check_update
@@ -497,11 +511,11 @@ main() {
497511
echo 'warn: Install V2Ray from a local file, but still need to make sure the network is available.'
498512
echo -n 'warn: Please make sure the file is valid because we cannot confirm it. (Press any key) ...'
499513
read
500-
install_software unzip
514+
install_software 'unzip' 'unzip'
501515
decompression "$LOCAL_FILE"
502516
else
503517
# Normal way
504-
install_software curl
518+
install_software 'curl' 'curl'
505519
get_version
506520
NUMBER="$?"
507521
if [[ "$NUMBER" -eq '0' ]] || [[ "$FORCE" -eq '1' ]] || [[ "$NUMBER" -eq 2 ]]; then
@@ -512,7 +526,7 @@ main() {
512526
echo "removed: $TMP_DIRECTORY"
513527
exit 0
514528
fi
515-
install_software unzip
529+
install_software 'unzip' 'unzip'
516530
decompression "$ZIP_FILE"
517531
elif [[ "$NUMBER" -eq '1' ]]; then
518532
echo "info: No new version. The current version of V2Ray is $CURRENT_VERSION ."

0 commit comments

Comments
 (0)