mirror of https://github.com/XTLS/Xray-install
Complete basic revision
parent
7fc7febe13
commit
7e8ad02265
|
@ -1,6 +1,10 @@
|
||||||
#!/bin/ash
|
#!/bin/ash
|
||||||
|
|
||||||
# Judge architecture
|
TMP_DIRECTORY="$(mktemp -d)/"
|
||||||
|
ZIP_FILE="${TMP_DIRECTORY}v2ray-linux-$BIT.zip"
|
||||||
|
DOWNLOAD_LINK="https://github.com/v2ray/v2ray-core/releases/latest/download/v2ray-linux-$BIT.zip"
|
||||||
|
|
||||||
|
identify_architecture() {
|
||||||
case "$(arch -s)" in
|
case "$(arch -s)" in
|
||||||
'i386' | 'i686')
|
'i386' | 'i686')
|
||||||
BIT='32'
|
BIT='32'
|
||||||
|
@ -13,19 +17,24 @@ case "$(arch -s)" in
|
||||||
exit 1
|
exit 1
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
|
install_software() {
|
||||||
|
if [[ -n "$(command -v curl)" ]]; then
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
if [[ -n "$(command -v unzip)" ]]; then
|
||||||
|
return
|
||||||
|
fi
|
||||||
if [ "$(command -v apk)" ]; then
|
if [ "$(command -v apk)" ]; then
|
||||||
apk update
|
|
||||||
apk add curl unzip
|
apk add curl unzip
|
||||||
else
|
else
|
||||||
echo "error: The script does not support the package manager in this operating system."
|
echo "error: The script does not support the package manager in this operating system."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
TMP_DIRECTORY="$(mktemp -d)/"
|
download_v2ray() {
|
||||||
ZIP_FILE="${TMP_DIRECTORY}v2ray-linux-$BIT.zip"
|
|
||||||
DOWNLOAD_LINK="https://github.com/v2ray/v2ray-core/releases/latest/download/v2ray-linux-$BIT.zip"
|
|
||||||
|
|
||||||
curl -L -H 'Cache-Control: no-cache' -o "$ZIP_FILE" "$DOWNLOAD_LINK" -#
|
curl -L -H 'Cache-Control: no-cache' -o "$ZIP_FILE" "$DOWNLOAD_LINK" -#
|
||||||
if [ "$?" -ne '0' ]; then
|
if [ "$?" -ne '0' ]; then
|
||||||
echo 'error: Download failed! Please check your network or try again.'
|
echo 'error: Download failed! Please check your network or try again.'
|
||||||
|
@ -36,8 +45,9 @@ if [ "$?" -ne '0' ]; then
|
||||||
echo 'error: Download failed! Please check your network or try again.'
|
echo 'error: Download failed! Please check your network or try again.'
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
# Verification of V2Ray archive
|
verification_v2ray() {
|
||||||
for LISTSUM in 'md5' 'sha1' 'sha256' 'sha512'; do
|
for LISTSUM in 'md5' 'sha1' 'sha256' 'sha512'; do
|
||||||
SUM="$(${LISTSUM}sum $ZIP_FILE | sed 's/ .*//')"
|
SUM="$(${LISTSUM}sum $ZIP_FILE | sed 's/ .*//')"
|
||||||
CHECKSUM="$(grep $(echo $LISTSUM | tr [:lower:] [:upper:]) $ZIP_FILE.dgst | sed 's/.* //')"
|
CHECKSUM="$(grep $(echo $LISTSUM | tr [:lower:] [:upper:]) $ZIP_FILE.dgst | sed 's/.* //')"
|
||||||
|
@ -46,19 +56,29 @@ for LISTSUM in 'md5' 'sha1' 'sha256' 'sha512'; do
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
decompression() {
|
||||||
unzip -q "$ZIP_FILE" -d "$TMP_DIRECTORY"
|
unzip -q "$ZIP_FILE" -d "$TMP_DIRECTORY"
|
||||||
|
}
|
||||||
|
|
||||||
|
is_it_running() {
|
||||||
V2RAY_RUNNING='0'
|
V2RAY_RUNNING='0'
|
||||||
if [ -n "$(pgrep v2ray)" ]; then
|
if [ -n "$(pgrep v2ray)" ]; then
|
||||||
rc-service v2ray stop
|
rc-service v2ray stop
|
||||||
V2RAY_RUNNING='1'
|
V2RAY_RUNNING='1'
|
||||||
fi
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
install_v2ray() {
|
||||||
install -m 755 "${TMP_DIRECTORY}v2ray" "/usr/local/bin/v2ray"
|
install -m 755 "${TMP_DIRECTORY}v2ray" "/usr/local/bin/v2ray"
|
||||||
install -m 755 "${TMP_DIRECTORY}v2ctl" "/usr/local/bin/v2ctl"
|
install -m 755 "${TMP_DIRECTORY}v2ctl" "/usr/local/bin/v2ctl"
|
||||||
install -d /usr/local/lib/v2ray/
|
install -d /usr/local/lib/v2ray/
|
||||||
install -m 755 "${TMP_DIRECTORY}geoip.dat" "/usr/local/lib/v2ray/geoip.dat"
|
install -m 755 "${TMP_DIRECTORY}geoip.dat" "/usr/local/lib/v2ray/geoip.dat"
|
||||||
install -m 755 "${TMP_DIRECTORY}geosite.dat" "/usr/local/lib/v2ray/geosite.dat"
|
install -m 755 "${TMP_DIRECTORY}geosite.dat" "/usr/local/lib/v2ray/geosite.dat"
|
||||||
|
}
|
||||||
|
|
||||||
|
install_confdir() {
|
||||||
CONFDIR='0'
|
CONFDIR='0'
|
||||||
if [ ! -d '/usr/local/etc/v2ray/' ]; then
|
if [ ! -d '/usr/local/etc/v2ray/' ]; then
|
||||||
install -d /usr/local/etc/v2ray/
|
install -d /usr/local/etc/v2ray/
|
||||||
|
@ -67,11 +87,19 @@ if [ ! -d '/usr/local/etc/v2ray/' ]; then
|
||||||
done
|
done
|
||||||
CONFDIR='1'
|
CONFDIR='1'
|
||||||
fi
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
install_log() {
|
||||||
LOG='0'
|
LOG='0'
|
||||||
if [ ! -d '/var/log/v2ray/' ]; then
|
if [ ! -d '/var/log/v2ray/' ]; then
|
||||||
install -d -o nobody -g nobody /var/log/v2ray/
|
install -d -o nobody -g nobody /var/log/v2ray/
|
||||||
|
install -m 600 -o nobody -g nobody /var/log/v2ray/access.log
|
||||||
|
install -m 600 -o nobody -g nobody /var/log/v2ray/error.log
|
||||||
LOG='1'
|
LOG='1'
|
||||||
fi
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
install_startup_service_file() {
|
||||||
OPENRC='0'
|
OPENRC='0'
|
||||||
if [ ! -f '/etc/init.d/v2ray' ]; then
|
if [ ! -f '/etc/init.d/v2ray' ]; then
|
||||||
mkdir "${TMP_DIRECTORY}init.d/"
|
mkdir "${TMP_DIRECTORY}init.d/"
|
||||||
|
@ -83,7 +111,9 @@ if [ ! -f '/etc/init.d/v2ray' ]; then
|
||||||
install -m 755 "${TMP_DIRECTORY}init.d/v2ray" /etc/init.d/v2ray
|
install -m 755 "${TMP_DIRECTORY}init.d/v2ray" /etc/init.d/v2ray
|
||||||
OPENRC='1'
|
OPENRC='1'
|
||||||
fi
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
information() {
|
||||||
echo 'installed: /usr/local/bin/v2ray'
|
echo 'installed: /usr/local/bin/v2ray'
|
||||||
echo 'installed: /usr/local/bin/v2ctl'
|
echo 'installed: /usr/local/bin/v2ctl'
|
||||||
echo 'installed: /usr/local/lib/v2ray/geoip.dat'
|
echo 'installed: /usr/local/lib/v2ray/geoip.dat'
|
||||||
|
@ -115,3 +145,21 @@ else
|
||||||
echo 'Please execute the command: rc-update add v2ray; rc-service v2ray start'
|
echo 'Please execute the command: rc-update add v2ray; rc-service v2ray start'
|
||||||
fi
|
fi
|
||||||
echo "info: V2Ray is installed."
|
echo "info: V2Ray is installed."
|
||||||
|
}
|
||||||
|
|
||||||
|
main() {
|
||||||
|
identify_architecture
|
||||||
|
install_software
|
||||||
|
install_software
|
||||||
|
download_v2ray
|
||||||
|
verification_v2ray
|
||||||
|
decompression
|
||||||
|
is_it_running
|
||||||
|
install_v2ray
|
||||||
|
install_confdir
|
||||||
|
install_log
|
||||||
|
install_startup_service_file
|
||||||
|
information
|
||||||
|
}
|
||||||
|
|
||||||
|
main
|
||||||
|
|
Loading…
Reference in New Issue