v2ray-core: add new package
authorTianling Shen <cnsztl@immortalwrt.org>
Thu, 8 Sep 2022 01:52:57 +0000 (09:52 +0800)
committerRosen Penev <rosenp@gmail.com>
Fri, 9 Sep 2022 22:17:38 +0000 (15:17 -0700)
Project V is a set of network tools that help you to build your own computer network.
It secures your network connections and thus protects your privacy.

For more details, see https://www.v2fly.org/en_US/guide/faq.html

Signed-off-by: Tianling Shen <cnsztl@immortalwrt.org>
net/v2ray-core/Makefile [new file with mode: 0644]
net/v2ray-core/files/v2ray.conf [new file with mode: 0644]
net/v2ray-core/files/v2ray.init [new file with mode: 0755]
net/v2ray-core/test.sh [new file with mode: 0644]

diff --git a/net/v2ray-core/Makefile b/net/v2ray-core/Makefile
new file mode 100644 (file)
index 0000000..add4616
--- /dev/null
@@ -0,0 +1,111 @@
+# SPDX-License-Identifier: GPL-3.0-only
+#
+# Copyright (C) 2021-2022 ImmortalWrt.org
+
+include $(TOPDIR)/rules.mk
+
+PKG_NAME:=v2ray-core
+PKG_VERSION:=5.1.0
+PKG_RELEASE:=$(AUTORELEASE)
+
+PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
+PKG_SOURCE_URL:=https://codeload.github.com/v2fly/v2ray-core/tar.gz/v$(PKG_VERSION)?
+PKG_HASH:=b3dbd2bbee9486999b81d1968545c5a6caa7b0f4726a7259939f1bda54fcf5ea
+
+PKG_LICENSE:=MIT
+PKG_LICENSE_FILES:=LICENSE
+PKG_MAINTAINER:=Tianling Shen <cnsztl@immortalwrt.org>
+
+PKG_BUILD_DEPENDS:=golang/host
+PKG_BUILD_PARALLEL:=1
+PKG_USE_MIPS16:=0
+
+GO_PKG:=github.com/v2fly/v2ray-core/v5
+GO_PKG_BUILD_PKG:=$(GO_PKG)/main
+GO_PKG_LDFLAGS_X:= \
+       $(GO_PKG).build=OpenWrt \
+       $(GO_PKG).version=$(PKG_VERSION)
+
+include $(INCLUDE_DIR)/package.mk
+include ../../lang/golang/golang-package.mk
+
+define Package/v2ray/template
+  TITLE:=A platform for building proxies to bypass network restrictions
+  SECTION:=net
+  CATEGORY:=Network
+  URL:=https://www.v2fly.org
+endef
+
+define Package/v2ray-core
+  $(call Package/v2ray/template)
+  DEPENDS:=$(GO_ARCH_DEPENDS) +ca-bundle
+endef
+
+define Package/v2ray-example
+  $(call Package/v2ray/template)
+  TITLE+= (example configs)
+  DEPENDS:=v2ray-core
+  PKGARCH:=all
+endef
+
+define Package/v2ray-extra
+  $(call Package/v2ray/template)
+  TITLE+= (extra resources)
+  DEPENDS:=v2ray-core
+  PKGARCH:=all
+endef
+
+define Package/v2ray/description
+  Project V is a set of network tools that help you to build your own computer network.
+  It secures your network connections and thus protects your privacy.
+endef
+
+define Package/v2ray-core/description
+  $(call Package/v2ray/description)
+endef
+
+define Package/v2ray-example/description
+  $(call Package/v2ray/description)
+
+  This includes example configuration files for v2ray-core.
+endef
+
+define Package/v2ray-extra/description
+  $(call Package/v2ray/description)
+
+  This includes extra resources for v2ray-core.
+endef
+
+define Package/v2ray-core/conffiles
+/etc/config/v2ray
+/etc/v2ray/
+endef
+
+define Package/v2ray-core/install
+       $(call GoPackage/Package/Install/Bin,$(PKG_INSTALL_DIR))
+       $(INSTALL_DIR) $(1)/usr/bin/
+       $(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/bin/main $(1)/usr/bin/v2ray
+
+       $(INSTALL_DIR) $(1)/etc/v2ray/
+       $(INSTALL_DATA) $(PKG_BUILD_DIR)/release/config/config.json $(1)/etc/v2ray/
+
+       $(INSTALL_DIR) $(1)/etc/config/
+       $(INSTALL_CONF) $(CURDIR)/files/v2ray.conf $(1)/etc/config/v2ray
+       $(INSTALL_DIR) $(1)/etc/init.d/
+       $(INSTALL_BIN) $(CURDIR)/files/v2ray.init $(1)/etc/init.d/v2ray
+endef
+
+define Package/v2ray-example/install
+       $(INSTALL_DIR) $(1)/etc/v2ray/
+       $(INSTALL_DATA) $(PKG_BUILD_DIR)/release/config/vpoint_socks_vmess.json $(1)/etc/v2ray/
+       $(INSTALL_DATA) $(PKG_BUILD_DIR)/release/config/vpoint_vmess_freedom.json $(1)/etc/v2ray/
+endef
+
+define Package/v2ray-extra/install
+       $(INSTALL_DIR) $(1)/usr/share/v2ray/
+       $(CP) $(PKG_BUILD_DIR)/release/extra/* $(1)/usr/share/v2ray/
+endef
+
+$(eval $(call BuildPackage,v2ray-core))
+$(eval $(call BuildPackage,v2ray-example))
+$(eval $(call BuildPackage,v2ray-extra))
diff --git a/net/v2ray-core/files/v2ray.conf b/net/v2ray-core/files/v2ray.conf
new file mode 100644 (file)
index 0000000..6df1e10
--- /dev/null
@@ -0,0 +1,11 @@
+
+config v2ray 'enabled'
+       option enabled '0'
+
+config v2ray 'config'
+       option confdir '/etc/v2ray'
+       list conffiles '/etc/v2ray/config.json'
+       option datadir '/usr/share/v2ray'
+       option format 'json'
+       option memconservative '1'
+
diff --git a/net/v2ray-core/files/v2ray.init b/net/v2ray-core/files/v2ray.init
new file mode 100755 (executable)
index 0000000..e43f511
--- /dev/null
@@ -0,0 +1,57 @@
+#!/bin/sh /etc/rc.common
+
+USE_PROCD=1
+START=99
+
+CONF="v2ray"
+PROG="/usr/bin/v2ray"
+
+start_service() {
+       config_load "$CONF"
+
+       local enabled
+       config_get_bool enabled "enabled" "enabled" "0"
+       [ "$enabled" -eq "0" ] && exit 1
+
+       local confdir
+       local conffiles
+       local datadir
+       local format
+
+       config_get confdir "config" "confdir"
+       config_get conffiles "config" "conffiles"
+       config_get datadir "config" "datadir" "/usr/share/v2ray"
+       config_get format "config" "format" "json"
+       config_get_bool memconservative "config" "memconservative" "1"
+
+       procd_open_instance "$CONF"
+       procd_set_param command "$PROG" run
+       [ -n "$confdir" ] && procd_append_param command -confdir "$confdir"
+       [ -n "$conffiles" ] && {
+               for i in $conffiles
+               do
+                       procd_append_param command -config "$i"
+               done
+       }
+       [ -n "$format" ] && procd_append_param command -format "$format"
+       procd_set_param env v2ray.local.asset="$datadir"
+       [ "$memconservative" -eq "1" ] && procd_append_param env V2RAY_CONF_GEOLOADER="memconservative"
+       procd_set_param file $conffiles
+
+       procd_set_param limits core="unlimited"
+       procd_set_param limits nofile="1000000 1000000"
+       procd_set_param stdout 1
+       procd_set_param stderr 1
+       procd_set_param respawn
+
+       procd_close_instance
+}
+
+reload_service() {
+       stop
+       start
+}
+
+service_triggers() {
+       procd_add_reload_trigger "$CONF"
+}
diff --git a/net/v2ray-core/test.sh b/net/v2ray-core/test.sh
new file mode 100644 (file)
index 0000000..ef751a9
--- /dev/null
@@ -0,0 +1,7 @@
+#!/bin/sh
+
+case "$1" in
+       "v2ray-core")
+               v2ray version 2>&1 | grep "$PKG_VERSION"
+               ;;
+esac