include systemv script in linux package

pull/58/head
Darien Raymond 9 years ago
parent e2b13bc104
commit 0ccce0ff7e

@ -1,7 +1,9 @@
{ {
"port": 37192, "port": 37192,
"log" : { "log" : {
"access": "access.log" "access": "/var/log/v2ray/access.log",
"error": "/var/log/v2ray/error.log",
"loglevel": "warning"
}, },
"inbound": { "inbound": {
"protocol": "vmess", "protocol": "vmess",

@ -1,5 +1,7 @@
#!/bin/bash #!/bin/bash
echo "Please make sure unzip and daemon are installed before running this script."
VER="v1.1" VER="v1.1"
ARCH=$(uname -m) ARCH=$(uname -m)
@ -7,6 +9,10 @@ VDIS="64"
if [ "$ARCH" == "i686" ] || [ "$ARCH" == "i386" ]; then if [ "$ARCH" == "i686" ] || [ "$ARCH" == "i386" ]; then
VDIS="32" VDIS="32"
elif [ "$ARCH" == *"armv7"* ]; then
VDIS="arm"
elif [ "$ARCH" == *"armv8"* ]; then
VDIS="arm64"
fi fi
DOWNLOAD_LINK="https://github.com/v2ray/v2ray-core/releases/download/${VER}/v2ray-linux-${VDIS}.zip" 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} curl -L -o "/tmp/v2ray/v2ray.zip" ${DOWNLOAD_LINK}
unzip "/tmp/v2ray/v2ray.zip" -d "/tmp/v2ray/" unzip "/tmp/v2ray/v2ray.zip" -d "/tmp/v2ray/"
mkdir -p /usr/bin/v2ray # Create folder for V2Ray log.
mkdir -p /etc/v2ray
mkdir -p /var/log/v2ray 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" 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 if [ ! -f "/etc/v2ray/config.json" ]; then
cp "/tmp/v2ray/v2ray-${VER}-linux-${VDIS}/vpoint_vmess_freedom.json" "/etc/v2ray/config.json" cp "/tmp/v2ray/v2ray-${VER}-linux-${VDIS}/vpoint_vmess_freedom.json" "/etc/v2ray/config.json"
#PORT=$(expr $RANDOM + 10000) #PORT=$(expr $RANDOM + 10000)
#sed -i "s/37192/${PORT}/g" "/etc/v2ray/config.json" #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 "PORT:${PORT}"
echo "UUID:${UUID}" echo "UUID:${UUID}"
fi 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

@ -7,17 +7,20 @@ import (
"strings" "strings"
) )
func copyConfigFile(src, dest string, goOS GoOS) error { func copyConfigFile(src, dest string, goOS GoOS, format bool) error {
content, err := ioutil.ReadFile(src) content, err := ioutil.ReadFile(src)
if err != nil { if err != nil {
return err return err
} }
str := string(content) if format {
str = strings.Replace(str, "\r\n", "\n", -1) str := string(content)
if goOS == Windows { str = strings.Replace(str, "\r\n", "\n", -1)
str = strings.Replace(str, "\n", "\r\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 { func copyConfigFiles(dir string, goOS GoOS) error {
@ -28,8 +31,7 @@ func copyConfigFiles(dir string, goOS GoOS) error {
if goOS == Windows || goOS == MacOS { if goOS == Windows || goOS == MacOS {
dest = filepath.Join(dir, "config.json") dest = filepath.Join(dir, "config.json")
} }
err := copyConfigFile(src, dest, goOS) if err := copyConfigFile(src, dest, goOS, true); err != nil {
if err != nil {
return err return err
} }
@ -39,5 +41,21 @@ func copyConfigFiles(dir string, goOS GoOS) error {
src = filepath.Join(srcDir, "vpoint_vmess_freedom.json") src = filepath.Join(srcDir, "vpoint_vmess_freedom.json")
dest = filepath.Join(dir, "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
} }

Loading…
Cancel
Save