From eb0480dee547ae775de7ab60ca9950e884dd4c57 Mon Sep 17 00:00:00 2001 From: cutelua <33216131+cutelua@users.noreply.github.com> Date: Fri, 15 Mar 2019 15:22:15 +0800 Subject: [PATCH] add timezone dis --- install.sh | 41 ++++++++++++++++++++++++++++++++++++++--- src/sys-info.sh | 26 ++++++++++++++++++++++++++ v2ray.sh | 18 ++++++++++++++++-- 3 files changed, 80 insertions(+), 5 deletions(-) mode change 100644 => 100755 install.sh create mode 100644 src/sys-info.sh mode change 100644 => 100755 v2ray.sh diff --git a/install.sh b/install.sh old mode 100644 new mode 100755 index fa5ae20..4bb5aa2 --- a/install.sh +++ b/install.sh @@ -6,6 +6,11 @@ yellow='\e[93m' magenta='\e[95m' cyan='\e[96m' none='\e[0m' +_red() { echo -e ${red}$*${none}; } +_green() { echo -e ${green}$*${none}; } +_yellow() { echo -e ${yellow}$*${none}; } +_magenta() { echo -e ${magenta}$*${none}; } +_cyan() { echo -e ${cyan}$*${none}; } # Root [[ $(id -u) != 0 ]] && echo -e "\n 哎呀……请使用 ${red}root ${none}用户运行 ${yellow}~(^_^) ${none}\n" && exit 1 @@ -108,6 +113,33 @@ _load() { . "${_dir}$@" } + +_sys_timezone() { + IS_OPENVZ= + if hostnamectl status | grep -q openvz; then + IS_OPENVZ=1 + fi + + echo + timedatectl set-timezone Asia/Shanghai + timedatectl set-ntp true + echo "已将你的主机设置为Asia/Shanghai时区并通过systemd-timesyncd自动同步时间。" + echo + + if [[ $IS_OPENVZ ]]; then + echo + echo -e "你的主机环境为 ${yellow}Openvz${none} ,建议使用${yellow}v2ray mkcp${none}系列协议。" + echo -e "注意:${yellow}Openvz${none} 系统时间无法由虚拟机内程序控制同步。" + echo -e "如果主机时间跟实际相差${yellow}超过90秒${none},v2ray将无法正常通信,请发ticket联系vps主机商调整。" + fi +} + +_sys_time() { + echo -e "\n主机时间:${yellow}" + timedatectl status | sed -n '1p;4p' + echo -e "${none}" +} + v2ray_config() { # clear echo @@ -738,9 +770,7 @@ install_v2ray() { # $cmd install -y lrzsz git zip unzip curl wget qrencode libcap iptables-services $cmd install -y socat lrzsz git zip unzip curl wget qrencode libcap patch diffutils fi - ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime [ -d /etc/v2ray ] && rm -rf /etc/v2ray - date -s "$(curl -sI g.cn | grep Date | cut -d' ' -f3-6)Z" if [[ $local_install ]]; then if [[ ! -d $(pwd)/config ]]; then @@ -752,7 +782,7 @@ install_v2ray() { exit 1 fi mkdir -p /etc/v2ray/233boy/v2ray - cp -rf $(pwd)/* /etc/v2ray/233boy/v2ray + cp -rf $(pwd) /etc/v2ray/233boy/v2ray/ else pushd /tmp git clone --depth=1 https://github.com/233boy/v2ray -b "$_gitbranch" /etc/v2ray/233boy/v2ray @@ -923,6 +953,11 @@ _install() { exit 1 fi _disableselinux + _sys_timezone + _sys_time + echo + echo + pause v2ray_config blocked_hosts shadowsocks_config diff --git a/src/sys-info.sh b/src/sys-info.sh new file mode 100644 index 0000000..17cbf0c --- /dev/null +++ b/src/sys-info.sh @@ -0,0 +1,26 @@ +#!/bin/bash +_sys_timezone() { + IS_OPENVZ= + if hostnamectl status | grep -q openvz; then + IS_OPENVZ=1 + fi + + echo + timedatectl set-timezone Asia/Shanghai + timedatectl set-ntp true + echo "已将你的主机设置为Asia/Shanghai时区并通过systemd-timesyncd自动同步时间。" + echo + + if [[ $IS_OPENVZ ]]; then + echo + echo -e "你的主机环境为 ${yellow}Openvz${none} ,建议使用${yellow}v2ray mkcp${none}系列协议。" + echo -e "注意:${yellow}Openvz${none} 系统时间无法由虚拟机内程序控制同步。" + echo -e "如果主机时间跟实际相差${yellow}超过90秒${none},v2ray将无法正常通信,请发ticket联系vps主机商调整。" + fi +} + +_sys_time() { + echo -e "主机时间:${yellow}" + timedatectl status | sed -n '1p;4p' + echo -e "${none}" +} diff --git a/v2ray.sh b/v2ray.sh old mode 100644 new mode 100755 index 62a09b2..4447b5b --- a/v2ray.sh +++ b/v2ray.sh @@ -77,12 +77,18 @@ _site="ddog.xyz" if [[ $v2ray_ver != v* ]]; then v2ray_ver="v$v2ray_ver" fi + if [[ ! -f $_v2ray_sh ]]; then - mv -f /usr/local/bin/v2ray $_v2ray_sh - chmod +x $_v2ray_sh + [[ -f /usr/local/bin/v2ray ]] && rm -f /usr/local/bin/v2ray + ln -s /etc/v2ray/233boy/v2ray/v2ray.sh $_v2ray_sh echo -e "\n $yellow 警告: 请重新登录 SSH 以避免出现 v2ray 命令未找到的情况。$none \n" && exit 1 fi +if [[ ! -L $_v2ray_sh ]]; then + rm -f $_v2ray_sh + ln -s /etc/v2ray/233boy/v2ray/v2ray.sh $_v2ray_sh +fi + if [ $v2ray_pid ]; then v2ray_status="$green正在运行$none" else @@ -2906,6 +2912,11 @@ menu() { fi done echo + echo + echo -e "注意: 如果主机时间跟实际相差${yellow}超过90秒${none},v2ray将无法正常通信。" + _load sys-info.sh + _sys_time + echo echo -e "温馨提示...如果你不想执行选项...按$yellow Ctrl + C $none即可退出" echo read -p "$(echo -e "请选择菜单 [${magenta}1-${#_lists[*]}$none]:")" choose @@ -3049,7 +3060,10 @@ reload) view_v2ray_config_info ;; time) + _load sys-info.sh + _sys_timezone date -s "$(curl -sI g.cn | grep Date | cut -d' ' -f3-6)Z" + _sys_time ;; log) view_v2ray_log