From 613b47cd386a68813b11d42a2e8313ca6f98d66a Mon Sep 17 00:00:00 2001 From: nite07 Date: Tue, 19 Mar 2024 02:42:45 +0800 Subject: [PATCH] Add template path check in MergeTemplate function --- entrypoint.sh | 3 ++- pkg/util/convert.go | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/entrypoint.sh b/entrypoint.sh index 3812e15..7fcce58 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,8 +1,9 @@ #!/bin/sh +cd /app if [ ! -d "/app/templates" ]; then mkdir /app/templates fi if [ -z "$(ls -A /app/templates)" ]; then cp -r /app/templates-origin/* /app/templates fi -/app/sub2sing-box server +sub2sing-box server diff --git a/pkg/util/convert.go b/pkg/util/convert.go index 33a35ad..eb4d3bf 100644 --- a/pkg/util/convert.go +++ b/pkg/util/convert.go @@ -7,6 +7,7 @@ import ( "io" "net/http" "os" + "path/filepath" "regexp" "strings" @@ -97,6 +98,11 @@ func Convert(subscriptions []string, proxies []string, template string, delete s } func MergeTemplate(proxies []model.Proxy, template string) (string, error) { + if !strings.Contains(template, string(filepath.Separator)) { + if _, err := os.Stat(template); os.IsNotExist(err) { + template = filepath.Join("templates", template) + } + } config, err := ReadTemplate(template) proxyTags := make([]string, 0) if err != nil {