fix1: fix function judgment_parameters (#104)
Co-authored-by: IceCodeNew <32576256+IceCodeNew@users.noreply.github.com>pull/114/head
parent
d41ead065b
commit
f607e17837
|
@ -13,10 +13,10 @@
|
||||||
# https://github.com/v2fly/fhs-install-v2ray/issues
|
# https://github.com/v2fly/fhs-install-v2ray/issues
|
||||||
|
|
||||||
# If you modify the following variables, you also need to modify the unit file yourself:
|
# If you modify the following variables, you also need to modify the unit file yourself:
|
||||||
# You can modify it to /usr/local/lib/v2ray/
|
# You can modify it to /usr/local/lib/v2ray
|
||||||
DAT_PATH='/usr/local/share/v2ray/'
|
DAT_PATH='/usr/local/share/v2ray'
|
||||||
# You can modify it to /etc/v2ray/
|
# You can modify it to /etc/v2ray
|
||||||
JSON_PATH='/usr/local/etc/v2ray/'
|
JSON_PATH='/usr/local/etc/v2ray'
|
||||||
|
|
||||||
check_if_running_as_root() {
|
check_if_running_as_root() {
|
||||||
# If you want to run as another user, please modify $UID to be owned by this user
|
# If you want to run as another user, please modify $UID to be owned by this user
|
||||||
|
@ -41,7 +41,7 @@ identify_the_operating_system_and_architecture() {
|
||||||
'armv6l')
|
'armv6l')
|
||||||
MACHINE='arm32-v6'
|
MACHINE='arm32-v6'
|
||||||
;;
|
;;
|
||||||
'armv7' | 'armv7l' )
|
'armv7' | 'armv7l')
|
||||||
MACHINE='arm32-v7a'
|
MACHINE='arm32-v7a'
|
||||||
;;
|
;;
|
||||||
'armv8' | 'aarch64')
|
'armv8' | 'aarch64')
|
||||||
|
@ -107,8 +107,9 @@ identify_the_operating_system_and_architecture() {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
## Demo function for processing parameters
|
||||||
judgment_parameters() {
|
judgment_parameters() {
|
||||||
if [[ "$#" -gt '0' ]]; then
|
while [[ "$#" -gt '0' ]]; do
|
||||||
case "$1" in
|
case "$1" in
|
||||||
'--remove')
|
'--remove')
|
||||||
if [[ "$#" -gt '1' ]]; then
|
if [[ "$#" -gt '1' ]]; then
|
||||||
|
@ -118,98 +119,41 @@ judgment_parameters() {
|
||||||
REMOVE='1'
|
REMOVE='1'
|
||||||
;;
|
;;
|
||||||
'--version')
|
'--version')
|
||||||
if [[ "$#" -gt '2' ]] || [[ -z "$2" ]]; then
|
VERSION="${2:?error: Please specify the correct version.}"
|
||||||
echo 'error: Please specify the correct version.'
|
break
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
VERSION="$2"
|
|
||||||
;;
|
;;
|
||||||
'-c' | '--check')
|
'-c' | '--check')
|
||||||
if [[ "$#" -gt '1' ]]; then
|
|
||||||
echo 'error: Please enter the correct parameters.'
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
CHECK='1'
|
CHECK='1'
|
||||||
|
break
|
||||||
;;
|
;;
|
||||||
'-f' | '--force')
|
'-f' | '--force')
|
||||||
if [[ "$#" -gt '1' ]]; then
|
|
||||||
echo 'error: Please enter the correct parameters.'
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
FORCE='1'
|
FORCE='1'
|
||||||
;;
|
break
|
||||||
|
;;
|
||||||
'-h' | '--help')
|
'-h' | '--help')
|
||||||
if [[ "$#" -gt '1' ]]; then
|
|
||||||
echo 'error: Please enter the correct parameters.'
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
HELP='1'
|
HELP='1'
|
||||||
|
break
|
||||||
;;
|
;;
|
||||||
'-l' | '--local')
|
'-l' | '--local')
|
||||||
if [[ "$#" -gt '2' ]] || [[ -z "$2" ]]; then
|
|
||||||
echo 'error: Please specify the correct local file.'
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
LOCAL_FILE="$2"
|
|
||||||
LOCAL_INSTALL='1'
|
LOCAL_INSTALL='1'
|
||||||
|
LOCAL_FILE="${2:?error: Please specify the correct local file.}"
|
||||||
|
break
|
||||||
;;
|
;;
|
||||||
'-p' | '--proxy')
|
'-p' | '--proxy')
|
||||||
case "$2" in
|
if echo "${2:?undefine var}" | grep -qEo '^(https?|socks4a?|socks5h?):\/\/'; then
|
||||||
'http://'*)
|
echo 'error: Please specify the correct proxy server address.'
|
||||||
;;
|
exit 1
|
||||||
'https://'*)
|
|
||||||
;;
|
|
||||||
'socks4://'*)
|
|
||||||
;;
|
|
||||||
'socks4a://'*)
|
|
||||||
;;
|
|
||||||
'socks5://'*)
|
|
||||||
;;
|
|
||||||
'socks5h://'*)
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
echo 'error: Please specify the correct proxy server address.'
|
|
||||||
exit 1
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
PROXY="-x$2"
|
|
||||||
# Parameters available through a proxy server
|
|
||||||
if [[ "$#" -gt '2' ]]; then
|
|
||||||
case "$3" in
|
|
||||||
'--version')
|
|
||||||
if [[ "$#" -gt '4' ]] || [[ -z "$4" ]]; then
|
|
||||||
echo 'error: Please specify the correct version.'
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
VERSION="$2"
|
|
||||||
;;
|
|
||||||
'-c' | '--check')
|
|
||||||
if [[ "$#" -gt '3' ]]; then
|
|
||||||
echo 'error: Please enter the correct parameters.'
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
CHECK='1'
|
|
||||||
;;
|
|
||||||
'-f' | '--force')
|
|
||||||
if [[ "$#" -gt '3' ]]; then
|
|
||||||
echo 'error: Please enter the correct parameters.'
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
FORCE='1'
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
echo "$0: unknown option -- -"
|
|
||||||
exit 1
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
fi
|
fi
|
||||||
|
PROXY="-x$2"
|
||||||
|
shift
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
echo "$0: unknown option -- -"
|
echo "$0: unknown option -- -"
|
||||||
exit 1
|
exit 1
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
fi
|
shift
|
||||||
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
install_software() {
|
install_software() {
|
||||||
|
@ -339,7 +283,7 @@ install_file() {
|
||||||
if [[ "$NAME" == 'v2ray' ]] || [[ "$NAME" == 'v2ctl' ]]; then
|
if [[ "$NAME" == 'v2ray' ]] || [[ "$NAME" == 'v2ctl' ]]; then
|
||||||
install -m 755 "${TMP_DIRECTORY}/$NAME" "/usr/local/bin/$NAME"
|
install -m 755 "${TMP_DIRECTORY}/$NAME" "/usr/local/bin/$NAME"
|
||||||
elif [[ "$NAME" == 'geoip.dat' ]] || [[ "$NAME" == 'geosite.dat' ]]; then
|
elif [[ "$NAME" == 'geoip.dat' ]] || [[ "$NAME" == 'geosite.dat' ]]; then
|
||||||
install -m 644 "${TMP_DIRECTORY}/$NAME" "${DAT_PATH}$NAME"
|
install -m 644 "${TMP_DIRECTORY}/$NAME" "${DAT_PATH}/$NAME"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -349,7 +293,7 @@ install_v2ray() {
|
||||||
install_file v2ctl
|
install_file v2ctl
|
||||||
install -d "$DAT_PATH"
|
install -d "$DAT_PATH"
|
||||||
# If the file exists, geoip.dat and geosite.dat will not be installed or updated
|
# If the file exists, geoip.dat and geosite.dat will not be installed or updated
|
||||||
if [[ ! -f "${DAT_PATH}.undat" ]]; then
|
if [[ ! -f "${DAT_PATH}/.undat" ]]; then
|
||||||
install_file geoip.dat
|
install_file geoip.dat
|
||||||
install_file geosite.dat
|
install_file geosite.dat
|
||||||
fi
|
fi
|
||||||
|
@ -357,7 +301,7 @@ install_v2ray() {
|
||||||
# Install V2Ray configuration file to $JSON_PATH
|
# Install V2Ray configuration file to $JSON_PATH
|
||||||
if [[ ! -d "$JSON_PATH" ]]; then
|
if [[ ! -d "$JSON_PATH" ]]; then
|
||||||
install -d "$JSON_PATH"
|
install -d "$JSON_PATH"
|
||||||
echo "{}" > "${JSON_PATH}config.json"
|
echo "{}" > "${JSON_PATH}/config.json"
|
||||||
CONFIG_NEW='1'
|
CONFIG_NEW='1'
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -523,9 +467,9 @@ main() {
|
||||||
echo 'installed: /usr/local/bin/v2ray'
|
echo 'installed: /usr/local/bin/v2ray'
|
||||||
echo 'installed: /usr/local/bin/v2ctl'
|
echo 'installed: /usr/local/bin/v2ctl'
|
||||||
# If the file exists, the content output of installing or updating geoip.dat and geosite.dat will not be displayed
|
# If the file exists, the content output of installing or updating geoip.dat and geosite.dat will not be displayed
|
||||||
if [[ ! -f "${DAT_PATH}.undat" ]]; then
|
if [[ ! -f "${DAT_PATH}/.undat" ]]; then
|
||||||
echo "installed: ${DAT_PATH}geoip.dat"
|
echo "installed: ${DAT_PATH}/geoip.dat"
|
||||||
echo "installed: ${DAT_PATH}geosite.dat"
|
echo "installed: ${DAT_PATH}/geosite.dat"
|
||||||
fi
|
fi
|
||||||
if [[ "$CONFIG_NEW" -eq '1' ]]; then
|
if [[ "$CONFIG_NEW" -eq '1' ]]; then
|
||||||
echo "installed: ${JSON_PATH}config.json"
|
echo "installed: ${JSON_PATH}config.json"
|
||||||
|
|
Loading…
Reference in New Issue