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:
# https://github.com/v2fly/fhs-install-v2ray/issues
# Identify the operating system and architecture
if [[ "$(uname)" == 'Linux' ]]; then
case "$(uname -m)" in
'i386' | 'i686')
MACHINE='32'
;;
'amd64' | 'x86_64')
MACHINE='64'
;;
'armv6l' | 'armv7')
MACHINE='arm'
;;
'armv8' | 'aarch64')
MACHINE='arm64'
;;
'mips')
MACHINE='mips'
;;
'mips64')
MACHINE='mips64'
;;
'mips64le')
MACHINE='mips64le'
;;
'mipsle')
MACHINE='mipsle'
;;
's390x')
MACHINE='s390x'
;;
'ppc64')
MACHINE='ppc64'
;;
'ppc64le')
MACHINE='ppc64le'
;;
*)
echo "error: The architecture is not supported."
identify_the_operating_system_and_architecture() {
if [[ "$(uname)" == 'Linux' ]]; then
case "$(uname -m)" in
'i386' | 'i686')
MACHINE='32'
;;
'amd64' | 'x86_64')
MACHINE='64'
;;
'armv6l' | 'armv7')
MACHINE='arm'
;;
'armv8' | 'aarch64')
MACHINE='arm64'
;;
'mips')
MACHINE='mips'
;;
'mips64')
MACHINE='mips64'
;;
'mips64le')
MACHINE='mips64le'
;;
'mipsle')
MACHINE='mipsle'
;;
's390x')
MACHINE='s390x'
;;
'ppc64')
MACHINE='ppc64'
;;
'ppc64le')
MACHINE='ppc64le'
;;
*)
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
;;
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."
echo "error: This operating system is not supported."
exit 1
fi
else
echo "error: This operating system is not supported."
exit 1
fi
}
# Judgment parameters
if [[ "$#" -gt '0' ]]; then
case "$1" in
'--remove')
if [[ "$#" -gt '1' ]]; then
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.'
judgment_parameters() {
if [[ "$#" -gt '0' ]]; then
case "$1" in
'--remove')
if [[ "$#" -gt '1' ]]; then
echo 'error: Please enter the correct parameters.'
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"
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://'*)
;;
'-c' | '--check')
if [[ "$#" -gt '3' ]]; then
echo 'error: Please enter the correct parameters.'
exit 1
fi
CHECK='1'
'https://'*)
;;
'-f' | '--force')
if [[ "$#" -gt '3' ]]; then
echo 'error: Please enter the correct parameters.'
exit 1
fi
FORCE='1'
'socks4://'*)
;;
'socks4a://'*)
;;
'socks5://'*)
;;
'socks5h://'*)
;;
*)
echo "$0: unknown option -- -"
echo 'error: Please specify the correct proxy server address.'
exit 1
;;
esac
fi
;;
*)
echo "$0: unknown option -- -"
exit 1
;;
esac
fi
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
;;
*)
echo "$0: unknown option -- -"
exit 1
;;
esac
fi
}
install_software() {
COMPONENT="$1"
@ -457,6 +459,9 @@ show_help() {
}
main() {
identify_the_operating_system_and_architecture
judgment_parameters "$@"
# Parameter information
[[ "$HELP" -eq '1' ]] && show_help
[[ "$CHECK" -eq '1' ]] && check_update
@ -538,4 +543,4 @@ main() {
fi
}
main
main "$@"