| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- #!/bin/bash
- # This Bash script to install the latest release of geoip.dat and geosite.dat:
- # https://github.com/v2fly/geoip
- # https://github.com/v2fly/domain-list-community
- # Depends on cURL, please solve it yourself
- # You may plan to execute this Bash script regularly:
- # install -m 755 install-dat-release.sh /usr/local/bin/install-dat-release
- # 0 0 * * * /usr/local/bin/install-dat-release > /dev/null 2>&1
- # You can modify it to /usr/local/lib/xray
- XRAY="/usr/local/share/xray"
- DOWNLOAD_LINK_GEOIP="https://github.com/v2fly/geoip/releases/latest/download/geoip.dat"
- DOWNLOAD_LINK_GEOSITE="https://github.com/v2fly/domain-list-community/releases/latest/download/dlc.dat"
- file_ip='geoip.dat'
- file_dlc='dlc.dat'
- file_site='geosite.dat'
- dir_tmp="$(mktemp -d)"
- curl() {
- $(type -P curl) -L -q --retry 5 --retry-delay 10 --retry-max-time 60 "$@"
- }
- check_if_running_as_root() {
- # If you want to run as another user, please modify $UID to be owned by this user
- if [[ "$UID" -ne '0' ]]; then
- echo "error: You must run this script as root!"
- exit 1
- fi
- }
- download_files() {
- if ! curl -R -H 'Cache-Control: no-cache' -o "${dir_tmp}/${2}" "${1}"; then
- echo 'error: Download failed! Please check your network or try again.'
- exit 1
- fi
- if ! curl -R -H 'Cache-Control: no-cache' -o "${dir_tmp}/${2}.sha256sum" "${1}.sha256sum"; then
- echo 'error: Download failed! Please check your network or try again.'
- exit 1
- fi
- }
- check_sum() {
- (
- cd "${dir_tmp}" || exit
- for i in "${dir_tmp}"/*.sha256sum; do
- if ! sha256sum -c "${i}"; then
- echo 'error: Check failed! Please check your network or try again.'
- exit 1
- fi
- done
- )
- }
- install_file() {
- install -m 644 "${dir_tmp}"/${file_dlc} "${XRAY}"/${file_site}
- install -m 644 "${dir_tmp}"/${file_ip} "${XRAY}"/${file_ip}
- rm -r "${dir_tmp}"
- }
- main() {
- check_if_running_as_root
- download_files $DOWNLOAD_LINK_GEOIP $file_ip
- download_files $DOWNLOAD_LINK_GEOSITE $file_dlc
- check_sum
- install_file
- }
- main "$@"
|