Change to function

pull/1/head
Dct Mei 2020-04-17 00:09:54 +08:00
parent 45f823dd06
commit 65fc443163
No known key found for this signature in database
GPG Key ID: 50BF8B712DCAD7EA
1 changed files with 166 additions and 161 deletions

View File

@ -12,180 +12,182 @@
# If the script executes incorrectly, go to: # If the script executes incorrectly, go to:
# https://github.com/v2fly/fhs-install-v2ray/issues # https://github.com/v2fly/fhs-install-v2ray/issues
# Identify the operating system and architecture identify_the_operating_system_and_architecture() {
if [[ "$(uname)" == 'Linux' ]]; then if [[ "$(uname)" == 'Linux' ]]; then
case "$(uname -m)" in case "$(uname -m)" in
'i386' | 'i686') 'i386' | 'i686')
MACHINE='32' MACHINE='32'
;; ;;
'amd64' | 'x86_64') 'amd64' | 'x86_64')
MACHINE='64' MACHINE='64'
;; ;;
'armv6l' | 'armv7') 'armv6l' | 'armv7')
MACHINE='arm' MACHINE='arm'
;; ;;
'armv8' | 'aarch64') 'armv8' | 'aarch64')
MACHINE='arm64' MACHINE='arm64'
;; ;;
'mips') 'mips')
MACHINE='mips' MACHINE='mips'
;; ;;
'mips64') 'mips64')
MACHINE='mips64' MACHINE='mips64'
;; ;;
'mips64le') 'mips64le')
MACHINE='mips64le' MACHINE='mips64le'
;; ;;
'mipsle') 'mipsle')
MACHINE='mipsle' MACHINE='mipsle'
;; ;;
's390x') 's390x')
MACHINE='s390x' MACHINE='s390x'
;; ;;
'ppc64') 'ppc64')
MACHINE='ppc64' MACHINE='ppc64'
;; ;;
'ppc64le') 'ppc64le')
MACHINE='ppc64le' MACHINE='ppc64le'
;; ;;
*) *)
echo "error: The architecture is not supported." echo "error: The architecture is not supported."
exit 1
;;
esac
if [[ ! -f '/etc/os-release' ]]; then
echo "error: Don't use outdated Linux distributions."
exit 1
fi
if [[ -z "$(ls -l /sbin/init | grep systemd)" ]]; then
echo "error: Only Linux distributions using systemd are supported."
exit 1
fi
if [[ "$(command -v apt)" ]]; then
PACKAGE_MANAGEMENT_INSTALL='apt install'
PACKAGE_MANAGEMENT_REMOVE='apt remove'
elif [[ "$(command -v yum)" ]]; then
PACKAGE_MANAGEMENT_INSTALL='yum install'
PACKAGE_MANAGEMENT_REMOVE='yum remove'
if [[ "$(command -v dnf)" ]]; then
PACKAGE_MANAGEMENT_INSTALL='dnf install'
PACKAGE_MANAGEMENT_REMOVE='dnf remove'
fi
elif [[ "$(command -v zypper)" ]]; then
PACKAGE_MANAGEMENT_INSTALL='zypper install'
PACKAGE_MANAGEMENT_REMOVE='zypper remove'
else
echo "error: The script does not support the package manager in this operating system."
exit 1 exit 1
;;
esac
if [[ ! -f '/etc/os-release' ]]; then
echo "error: Don't use outdated Linux distributions."
exit 1
fi
if [[ -z "$(ls -l /sbin/init | grep systemd)" ]]; then
echo "error: Only Linux distributions using systemd are supported."
exit 1
fi
if [[ "$(command -v apt)" ]]; then
PACKAGE_MANAGEMENT_INSTALL='apt install'
PACKAGE_MANAGEMENT_REMOVE='apt remove'
elif [[ "$(command -v yum)" ]]; then
PACKAGE_MANAGEMENT_INSTALL='yum install'
PACKAGE_MANAGEMENT_REMOVE='yum remove'
if [[ "$(command -v dnf)" ]]; then
PACKAGE_MANAGEMENT_INSTALL='dnf install'
PACKAGE_MANAGEMENT_REMOVE='dnf remove'
fi fi
elif [[ "$(command -v zypper)" ]]; then
PACKAGE_MANAGEMENT_INSTALL='zypper install'
PACKAGE_MANAGEMENT_REMOVE='zypper remove'
else else
echo "error: The script does not support the package manager in this operating system." echo "error: This operating system is not supported."
exit 1 exit 1
fi fi
else }
echo "error: This operating system is not supported."
exit 1
fi
# Judgment parameters judgment_parameters() {
if [[ "$#" -gt '0' ]]; then if [[ "$#" -gt '0' ]]; then
case "$1" in case "$1" in
'--remove') '--remove')
if [[ "$#" -gt '1' ]]; then if [[ "$#" -gt '1' ]]; then
echo 'error: Please enter the correct parameters.' echo 'error: Please enter the correct parameters.'
exit 1
fi
REMOVE='1'
;;
'--version')
if [[ "$#" -gt '2' ]] || [[ -z "$2" ]]; then
echo 'error: Please specify the correct version.'
exit 1
fi
VERSION="$2"
;;
'-c' | '--check')
if [[ "$#" -gt '1' ]]; then
echo 'error: Please enter the correct parameters.'
exit 1
fi
CHECK='1'
;;
'-f' | '--force')
if [[ "$#" -gt '1' ]]; then
echo 'error: Please enter the correct parameters.'
exit 1
fi
FORCE='1'
;;
'-h' | '--help')
if [[ "$#" -gt '1' ]]; then
echo 'error: Please enter the correct parameters.'
exit 1
fi
HELP='1'
;;
'-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'
;;
'-p' | '--proxy')
case "$2" in
'http://'*)
;;
'https://'*)
;;
'socks4://'*)
;;
'socks4a://'*)
;;
'socks5://'*)
;;
'socks5h://'*)
;;
*)
echo 'error: Please specify the correct proxy server address.'
exit 1 exit 1
;; fi
esac REMOVE='1'
PROXY="-x $2" ;;
# Parameters available through a proxy server '--version')
if [[ "$#" -gt '2' ]]; then if [[ "$#" -gt '2' ]] || [[ -z "$2" ]]; then
case "$3" in echo 'error: Please specify the correct version.'
'--version') exit 1
if [[ "$#" -gt '4' ]] || [[ -z "$4" ]]; then fi
echo 'error: Please specify the correct version.' VERSION="$2"
exit 1 ;;
fi '-c' | '--check')
VERSION="$2" if [[ "$#" -gt '1' ]]; then
echo 'error: Please enter the correct parameters.'
exit 1
fi
CHECK='1'
;;
'-f' | '--force')
if [[ "$#" -gt '1' ]]; then
echo 'error: Please enter the correct parameters.'
exit 1
fi
FORCE='1'
;;
'-h' | '--help')
if [[ "$#" -gt '1' ]]; then
echo 'error: Please enter the correct parameters.'
exit 1
fi
HELP='1'
;;
'-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'
;;
'-p' | '--proxy')
case "$2" in
'http://'*)
;; ;;
'-c' | '--check') 'https://'*)
if [[ "$#" -gt '3' ]]; then
echo 'error: Please enter the correct parameters.'
exit 1
fi
CHECK='1'
;; ;;
'-f' | '--force') 'socks4://'*)
if [[ "$#" -gt '3' ]]; then ;;
echo 'error: Please enter the correct parameters.' 'socks4a://'*)
exit 1 ;;
fi 'socks5://'*)
FORCE='1' ;;
'socks5h://'*)
;; ;;
*) *)
echo "$0: unknown option -- -" echo 'error: Please specify the correct proxy server address.'
exit 1 exit 1
;; ;;
esac esac
fi PROXY="-x $2"
;; # Parameters available through a proxy server
*) if [[ "$#" -gt '2' ]]; then
echo "$0: unknown option -- -" case "$3" in
exit 1 '--version')
;; if [[ "$#" -gt '4' ]] || [[ -z "$4" ]]; then
esac echo 'error: Please specify the correct version.'
fi 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
;;
*)
echo "$0: unknown option -- -"
exit 1
;;
esac
fi
}
install_software() { install_software() {
COMPONENT="$1" COMPONENT="$1"
@ -457,6 +459,9 @@ show_help() {
} }
main() { main() {
identify_the_operating_system_and_architecture
judgment_parameters "$@"
# Parameter information # Parameter information
[[ "$HELP" -eq '1' ]] && show_help [[ "$HELP" -eq '1' ]] && show_help
[[ "$CHECK" -eq '1' ]] && check_update [[ "$CHECK" -eq '1' ]] && check_update
@ -538,4 +543,4 @@ main() {
fi fi
} }
main main "$@"