From 0ccce0ff7ecb2931baa3ff5b69416ab1d0a27f54 Mon Sep 17 00:00:00 2001 From: Darien Raymond Date: Tue, 8 Dec 2015 11:41:20 +0000 Subject: [PATCH] include systemv script in linux package --- release/config/vpoint_vmess_freedom.json | 4 ++- release/install-release.sh | 24 ++++++++++++++-- tools/build/config.go | 36 ++++++++++++++++++------ 3 files changed, 51 insertions(+), 13 deletions(-) diff --git a/release/config/vpoint_vmess_freedom.json b/release/config/vpoint_vmess_freedom.json index 9ec504af..678432e3 100644 --- a/release/config/vpoint_vmess_freedom.json +++ b/release/config/vpoint_vmess_freedom.json @@ -1,7 +1,9 @@ { "port": 37192, "log" : { - "access": "access.log" + "access": "/var/log/v2ray/access.log", + "error": "/var/log/v2ray/error.log", + "loglevel": "warning" }, "inbound": { "protocol": "vmess", diff --git a/release/install-release.sh b/release/install-release.sh index 8c148452..67bea2d4 100755 --- a/release/install-release.sh +++ b/release/install-release.sh @@ -1,5 +1,7 @@ #!/bin/bash +echo "Please make sure unzip and daemon are installed before running this script." + VER="v1.1" ARCH=$(uname -m) @@ -7,6 +9,10 @@ VDIS="64" if [ "$ARCH" == "i686" ] || [ "$ARCH" == "i386" ]; then VDIS="32" +elif [ "$ARCH" == *"armv7"* ]; then + VDIS="arm" +elif [ "$ARCH" == *"armv8"* ]; then + VDIS="arm64" fi DOWNLOAD_LINK="https://github.com/v2ray/v2ray-core/releases/download/${VER}/v2ray-linux-${VDIS}.zip" @@ -17,15 +23,18 @@ mkdir -p /tmp/v2ray curl -L -o "/tmp/v2ray/v2ray.zip" ${DOWNLOAD_LINK} unzip "/tmp/v2ray/v2ray.zip" -d "/tmp/v2ray/" -mkdir -p /usr/bin/v2ray -mkdir -p /etc/v2ray +# Create folder for V2Ray log. mkdir -p /var/log/v2ray +# Install V2Ray binary to /usr/bin/v2ray +mkdir -p /usr/bin/v2ray cp "/tmp/v2ray/v2ray-${VER}-linux-${VDIS}/v2ray" "/usr/bin/v2ray/v2ray" +# Install V2Ray server config to /etc/v2ray +mkdir -p /etc/v2ray if [ ! -f "/etc/v2ray/config.json" ]; then cp "/tmp/v2ray/v2ray-${VER}-linux-${VDIS}/vpoint_vmess_freedom.json" "/etc/v2ray/config.json" - + #PORT=$(expr $RANDOM + 10000) #sed -i "s/37192/${PORT}/g" "/etc/v2ray/config.json" @@ -35,3 +44,12 @@ if [ ! -f "/etc/v2ray/config.json" ]; then #echo "PORT:${PORT}" echo "UUID:${UUID}" fi + +# Configure SysV if necessary. +if [ -d "/etc/init.d" ]; then + if [ ! -f "/etc/init.d/v2ray" ]; then + cp "/tmp/v2ray/systemv/v2ray" "/etc/init.d/v2ray" + chmod +x "/etc/init.d/v2ray" + update-rc.d v2ray defaults + fi +fi diff --git a/tools/build/config.go b/tools/build/config.go index 067ec418..34c7561b 100644 --- a/tools/build/config.go +++ b/tools/build/config.go @@ -7,17 +7,20 @@ import ( "strings" ) -func copyConfigFile(src, dest string, goOS GoOS) error { +func copyConfigFile(src, dest string, goOS GoOS, format bool) error { content, err := ioutil.ReadFile(src) if err != nil { return err } - str := string(content) - str = strings.Replace(str, "\r\n", "\n", -1) - if goOS == Windows { - str = strings.Replace(str, "\n", "\r\n", -1) + if format { + str := string(content) + str = strings.Replace(str, "\r\n", "\n", -1) + if goOS == Windows { + str = strings.Replace(str, "\n", "\r\n", -1) + } + content = []byte(str) } - return ioutil.WriteFile(dest, []byte(str), 0777) + return ioutil.WriteFile(dest, content, 0777) } func copyConfigFiles(dir string, goOS GoOS) error { @@ -28,8 +31,7 @@ func copyConfigFiles(dir string, goOS GoOS) error { if goOS == Windows || goOS == MacOS { dest = filepath.Join(dir, "config.json") } - err := copyConfigFile(src, dest, goOS) - if err != nil { + if err := copyConfigFile(src, dest, goOS, true); err != nil { return err } @@ -39,5 +41,21 @@ func copyConfigFiles(dir string, goOS GoOS) error { src = filepath.Join(srcDir, "vpoint_vmess_freedom.json") dest = filepath.Join(dir, "vpoint_vmess_freedom.json") - return copyConfigFile(src, dest, goOS) + + if err := copyConfigFile(src, dest, goOS, true); err != nil { + return err + } + + if goOS == Linux { + if err := os.MkdirAll(filepath.Join(dir, "systemv"), os.ModeDir|0777); err != nil { + return err + } + src = filepath.Join(srcDir, "systemv", "v2ray") + dest = filepath.Join(dir, "systemv", "v2ray") + if err := copyConfigFile(src, dest, goOS, false); err != nil { + return err + } + } + + return nil }