From 91cbb23765768c3dc1f7c0ff493e1273d8691ea2 Mon Sep 17 00:00:00 2001 From: wulabing Date: Tue, 5 Dec 2017 17:20:02 +0800 Subject: [PATCH] V1.0 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit debian 8 系统支持 --- install.sh | 274 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 274 insertions(+) create mode 100644 install.sh diff --git a/install.sh b/install.sh new file mode 100644 index 0000000..0526c01 --- /dev/null +++ b/install.sh @@ -0,0 +1,274 @@ +#!/bin/bash + +#==================================================== +# System Request:Debian 7+/Ubuntu 14.04+/Centos 6+ +# Author: wulabing +# Dscription: V2ray ws+tls onekey +# Version: 1.0 +# Blog: https://www.wulabing.com +# Official document: www.v2ray.com +#==================================================== + +#fonts color +Green="\033[32m" +Red="\033[31m" +Yellow="\033[33m" +GreenBG="\033[42;37m" +RedBG="\033[41;37m" +Font="\033[0m" + +#notification information +Info="${Green}[信息]${Font}" +OK="${Green}[OK]${Font}" +Error="${Red}[错误]${Font}" +Notification="${Yellow}[注意]${Font}" + +v2ray_conf_dir="/etc/v2ray" +nginx_conf_dir="/etc/nginx/conf.d" +v2ray_conf="${v2ray_conf_dir}/config.json" +nginx_conf="${nginx_conf_dir}/v2ray.conf" +is_root(){ + if [ `id -u` -eq 0 ] + then echo -e "${OK} ${GreenBG} 当前用户是root用户,进入安装流程 ${Font} " + else + echo -e "${Error} ${RedBG} 当前用户不是root用户,请切换到root用户后重新执行脚本 ${Font}" + exit 1 + fi +} +time_modify(){ + apt-get install ntpdate -y + + if [[ $? -ne 0 ]];then + echo -e "${Error} ${RedBG} ntpdate 时间同步服务安装失败,请根据错误提示进行修复 ${Font}" + exit 2 + else + echo -e "${OK} ntpdate 时间同步服务安装成功" + fi + + service ntp stop + + echo -e "${Info} 正在进行时间同步" + ntpdate time.nist.gov + + if [[ $? -eq 0 ]];then + echo -e "${OK} ${GreenBG} 时间同步成功 ${Font}" + echo -e "${OK} ${GreenBG} 当前系统时间 `date -R`(请注意时区间时间换算,换算后时间误差应为三分钟以内)${Font}" + sleep 1 + else + echo -e "${Error} ${RedBG} 时间同步失败,请检查ntpdate服务是否正常工作 ${Font}" + fi +} +dependency_install(){ + apt-get update + apt-get install wget curl -y + apt-get install bc + if [[ $? -eq 0 ]];then + echo -e "${OK} ${GreenBG} bc 安装完成 ${Font}" + sleep 1 + else + echo -e "${Error} ${RedBG} bc 安装失败 ${Font}" + exit 1 + fi +} +modify_port_UUID(){ + let PORT=$RANDOM+10000 + UUID=$(cat /proc/sys/kernel/random/uuid) + sed -i "/\"port\"/c \ \"port\":${PORT}," ${v2ray_conf} + sed -i "/\"id\"/c \\\t \"id\":\"${UUID}\"," ${v2ray_conf} +} +modify_nginx(){ + sed -i "/server_name/c \\\tserver_name ${domain};" ${nginx_conf} + sed -i "/proxy_pass/c \\\tproxy_pass http://127.0.0.1:${PORT};" ${nginx_conf} +} +v2ray_install(){ + if [[ -d /root/v2ray ]];then + rm -rf /root/v2ray + fi + + mkdir -p /root/v2ray && cd /root/v2ray + wget https://install.direct/go.sh + + if [[ -f go.sh ]];then + source go.sh --force + if [[ $? -eq 0 ]];then + echo -e "${OK} ${GreenBG} V2ray 安装成功 ${Font}" + echo -e "${Green} Port: ${PORT} ${Font}" + echo -e "${Grenn} UUID: ${UUID} ${Font}" + else + echo -e "${Error} ${RedBG} V2ray 安装失败,请检查相关依赖是否正确安装 ${Font}" + exit 3 + fi + else + echo -e "${OK} ${GreenBG} V2ray 安装文件下载失败,请检查下载地址是否可用 ${Font}" + exit 4 + fi +} +nginx_install(){ + apt-get install nginx -y + if [[ -d /etc/nginx ]];then + echo -e "${OK} ${GreenBG} nginx 安装完成 ${Font}" + else + echo -e "${Error} ${RedBG} nginx 安装失败 ${Font}" + exit 5 + fi +} +ssl_install(){ + + apt-get install socat netcat -y + + if [[ $? -eq 0 ]];then + echo -e "${OK} ${GreenBG} SSL 证书生成脚本依赖安装成功 ${Font}" + else + echo -e "${Error} ${RedBG} SSL 证书生成脚本依赖安装失败 ${Font}" + exit 6 + fi + curl https://get.acme.sh | sh + + if [[ $? -eq 0 ]];then + echo -e "${OK} ${GreenBG} SSL 证书生成脚本安装成功 ${Font}" + else + echo -e "${Error} ${RedBG} SSL 证书生成脚本安装失败,请检查相关依赖是否正常安装 ${Font}" + exit 7 + fi + +} +domain_check(){ + stty erase '^H' && read -p "请输入你的域名信息(eg:www.wulabing.com):" domain + domain_ip=`ping ${domain} -c 1 | sed '1{s/[^(]*(//;s/).*//;q}'` + local_ip=`ifconfig eth0 | grep 'inet ' | sed s/^.*addr://g | sed s/Bcast.*$//g` + echo -e "域名dns解析IP:${domain_ip}" + echo -e "本机IP: ${local_ip}" + sleep 2 + if [[ $(echo ${local_ip}|tr '.' '+'|bc) -eq $(echo ${domain_ip}|tr '.' '+'|bc) ]];then + echo -e "${OK} ${GreenBG} 域名dns解析IP 与 本机IP 匹配 ${Font}" + else + echo -e "${Error} ${RedBG} 域名dns解析IP 与 本机IP 不匹配 安装终止 ${Font}" + exit 1 + fi +} +port_exist_check(){ + if [[ 0 -eq `netstat -tlpn | grep "$1"| wc -l` ]];then + echo -e "${OK} ${GreenBG} $1 端口未被占用 ${Font}" + else + echo -e "${Error} ${RedBG} $1 端口被占用,请检查占用进程 结束后重新运行脚本 ${Font}" + netstat -tlpn | grep "$1" + exit 1 + fi +} +acme(){ + ~/.acme.sh/acme.sh --issue -d ${domain} --standalone -k ec-256 + if [[ $? -eq 0 ]];then + echo -e "${OK} ${GreenBG} SSL 证书生成成功 ${Font}" + ~/.acme.sh/acme.sh --installcert -d ${domain} --fullchainpath /etc/v2ray/v2ray.crt --keypath /etc/v2ray/v2ray.key --ecc + if [[ $? -eq 0 ]];then + echo -e "${OK} ${GreenBG} 证书配置成功 ${Font}" + fi + else + echo -e "${Error} ${RedBG} SSL 证书生成失败 ${Font}" + exit 1 + fi +} +v2ray_conf_add(){ + cat>${v2ray_conf_dir}/config.json<${nginx_conf_dir}/v2ray.conf<