forked from SagerNet/sing-box
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e586d9e
commit 9560619
Showing
12 changed files
with
2,202 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -49,10 +49,19 @@ nfpms: | |
- src: release/config/config.json | ||
dst: /etc/sing-box/config.json | ||
type: config | ||
|
||
- src: release/config/sing-box.service | ||
dst: /usr/lib/systemd/system/sing-box.service | ||
- src: release/config/[email protected] | ||
dst: /usr/lib/systemd/system/[email protected] | ||
|
||
- src: release/completions/sing-box.bash | ||
dst: /usr/share/bash-completion/completions/sing-box.bash | ||
- src: release/completions/sing-box.fish | ||
dst: /usr/share/fish/vendor_completions.d/sing-box.fish | ||
- src: release/completions/sing-box.zsh | ||
dst: /usr/share/zsh/site-functions/_sing-box | ||
|
||
- src: LICENSE | ||
dst: /usr/share/licenses/sing-box/LICENSE | ||
deb: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
version: 2 | ||
project_name: sing-box | ||
builds: | ||
- &template | ||
|
@@ -25,15 +26,13 @@ builds: | |
targets: | ||
- linux_386 | ||
- linux_amd64_v1 | ||
- linux_amd64_v3 | ||
- linux_arm64 | ||
- linux_arm_6 | ||
- linux_arm_7 | ||
- linux_s390x | ||
- linux_riscv64 | ||
- linux_mips64le | ||
- windows_amd64_v1 | ||
- windows_amd64_v3 | ||
- windows_386 | ||
- windows_arm64 | ||
- darwin_amd64_v1 | ||
|
@@ -90,8 +89,6 @@ builds: | |
- android_arm64 | ||
- android_386 | ||
- android_amd64 | ||
snapshot: | ||
name_template: "{{ .Version }}.{{ .ShortCommit }}" | ||
archives: | ||
- &template | ||
id: archive | ||
|
@@ -105,7 +102,7 @@ archives: | |
wrap_in_directory: true | ||
files: | ||
- LICENSE | ||
name_template: '{{ .ProjectName }}-{{ .Version }}-{{ .Os }}-{{ .Arch }}{{ with .Arm }}v{{ . }}{{ end }}{{ with .Mips }}_{{ . }}{{ end }}{{ if not (eq .Amd64 "v1") }}{{ .Amd64 }}{{ end }}' | ||
name_template: '{{ .ProjectName }}-{{ .Version }}-{{ .Os }}-{{ .Arch }}{{ with .Arm }}v{{ . }}{{ end }}{{ if and .Mips (not (eq .Mips "hardfloat")) }}_{{ .Mips }}{{ end }}{{ if not (eq .Amd64 "v1") }}{{ .Amd64 }}{{ end }}' | ||
- id: archive-legacy | ||
<<: *template | ||
builds: | ||
|
@@ -114,7 +111,7 @@ archives: | |
nfpms: | ||
- id: package | ||
package_name: sing-box | ||
file_name_template: '{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}{{ with .Arm }}v{{ . }}{{ end }}{{ with .Mips }}_{{ . }}{{ end }}{{ if not (eq .Amd64 "v1") }}{{ .Amd64 }}{{ end }}' | ||
file_name_template: '{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}{{ with .Arm }}v{{ . }}{{ end }}{{ if and .Mips (not (eq .Mips "hardfloat")) }}_{{ .Mips }}{{ end }}{{ if not (eq .Amd64 "v1") }}{{ .Amd64 }}{{ end }}' | ||
builds: | ||
- main | ||
homepage: https://sing-box.sagernet.org/ | ||
|
@@ -125,15 +122,26 @@ nfpms: | |
- deb | ||
- rpm | ||
- archlinux | ||
# - apk | ||
# - ipk | ||
priority: extra | ||
contents: | ||
- src: release/config/config.json | ||
dst: /etc/sing-box/config.json | ||
type: config | ||
|
||
- src: release/config/sing-box.service | ||
dst: /usr/lib/systemd/system/sing-box.service | ||
- src: release/config/[email protected] | ||
dst: /usr/lib/systemd/system/[email protected] | ||
|
||
- src: release/completions/sing-box.bash | ||
dst: /usr/share/bash-completion/completions/sing-box.bash | ||
- src: release/completions/sing-box.fish | ||
dst: /usr/share/fish/vendor_completions.d/sing-box.fish | ||
- src: release/completions/sing-box.zsh | ||
dst: /usr/share/zsh/site-functions/_sing-box | ||
|
||
- src: LICENSE | ||
dst: /usr/share/licenses/sing-box/LICENSE | ||
deb: | ||
|
@@ -145,13 +153,34 @@ nfpms: | |
signature: | ||
key_file: "{{ .Env.NFPM_KEY_PATH }}" | ||
overrides: | ||
deb: | ||
conflicts: | ||
- sing-box-beta | ||
rpm: | ||
conflicts: | ||
- sing-box-beta | ||
apk: | ||
contents: | ||
- src: release/config/config.json | ||
dst: /etc/sing-box/config.json | ||
type: config | ||
|
||
- src: release/config/sing-box.initd | ||
dst: /etc/init.d/sing-box | ||
|
||
- src: release/completions/sing-box.bash | ||
dst: /usr/share/bash-completion/completions/sing-box.bash | ||
- src: release/completions/sing-box.fish | ||
dst: /usr/share/fish/vendor_completions.d/sing-box.fish | ||
- src: release/completions/sing-box.zsh | ||
dst: /usr/share/zsh/site-functions/_sing-box | ||
|
||
- src: LICENSE | ||
dst: /usr/share/licenses/sing-box/LICENSE | ||
ipk: | ||
contents: | ||
- src: release/config/config.json | ||
dst: /etc/sing-box/config.json | ||
type: config | ||
|
||
- src: release/config/openwrt.init | ||
dst: /etc/init.d/sing-box | ||
- src: release/config/openwrt.conf | ||
dst: /etc/config/sing-box | ||
source: | ||
enabled: false | ||
name_template: '{{ .ProjectName }}-{{ .Version }}.source' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"os" | ||
"os/user" | ||
"strconv" | ||
"time" | ||
|
||
_ "github.com/sagernet/sing-box/include" | ||
"github.com/sagernet/sing-box/log" | ||
"github.com/sagernet/sing/service/filemanager" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
var ( | ||
globalCtx context.Context | ||
configPaths []string | ||
configDirectories []string | ||
workingDir string | ||
disableColor bool | ||
) | ||
|
||
var mainCommand = &cobra.Command{ | ||
Use: "sing-box", | ||
PersistentPreRun: preRun, | ||
} | ||
|
||
func init() { | ||
mainCommand.PersistentFlags().StringArrayVarP(&configPaths, "config", "c", nil, "set configuration file path") | ||
mainCommand.PersistentFlags().StringArrayVarP(&configDirectories, "config-directory", "C", nil, "set configuration directory path") | ||
mainCommand.PersistentFlags().StringVarP(&workingDir, "directory", "D", "", "set working directory") | ||
mainCommand.PersistentFlags().BoolVarP(&disableColor, "disable-color", "", false, "disable color output") | ||
} | ||
|
||
func preRun(cmd *cobra.Command, args []string) { | ||
globalCtx = context.Background() | ||
sudoUser := os.Getenv("SUDO_USER") | ||
sudoUID, _ := strconv.Atoi(os.Getenv("SUDO_UID")) | ||
sudoGID, _ := strconv.Atoi(os.Getenv("SUDO_GID")) | ||
if sudoUID == 0 && sudoGID == 0 && sudoUser != "" { | ||
sudoUserObject, _ := user.Lookup(sudoUser) | ||
if sudoUserObject != nil { | ||
sudoUID, _ = strconv.Atoi(sudoUserObject.Uid) | ||
sudoGID, _ = strconv.Atoi(sudoUserObject.Gid) | ||
} | ||
} | ||
if sudoUID > 0 && sudoGID > 0 { | ||
globalCtx = filemanager.WithDefault(globalCtx, "", "", sudoUID, sudoGID) | ||
} | ||
if disableColor { | ||
log.SetStdLogger(log.NewDefaultFactory(context.Background(), log.Formatter{BaseTime: time.Now(), DisableColors: true}, os.Stderr, "", nil, false).Logger()) | ||
} | ||
if workingDir != "" { | ||
_, err := os.Stat(workingDir) | ||
if err != nil { | ||
filemanager.MkdirAll(globalCtx, workingDir, 0o777) | ||
} | ||
err = os.Chdir(workingDir) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
} | ||
if len(configPaths) == 0 && len(configDirectories) == 0 { | ||
configPaths = append(configPaths, "config.json") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
//go:build generate && generate_completions | ||
|
||
package main | ||
|
||
import "github.com/sagernet/sing-box/log" | ||
|
||
func main() { | ||
err := generateCompletions() | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
} | ||
|
||
func generateCompletions() error { | ||
err := mainCommand.GenBashCompletionFile("release/completions/sing-box.bash") | ||
if err != nil { | ||
return err | ||
} | ||
err = mainCommand.GenFishCompletionFile("release/completions/sing-box.fish", true) | ||
if err != nil { | ||
return err | ||
} | ||
err = mainCommand.GenZshCompletionFile("release/completions/sing-box.zsh") | ||
if err != nil { | ||
return err | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,74 +1,11 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"os" | ||
"os/user" | ||
"strconv" | ||
"time" | ||
|
||
_ "github.com/sagernet/sing-box/include" | ||
"github.com/sagernet/sing-box/log" | ||
"github.com/sagernet/sing/service/filemanager" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
//go:build !generate | ||
|
||
var ( | ||
globalCtx context.Context | ||
configPaths []string | ||
configDirectories []string | ||
workingDir string | ||
disableColor bool | ||
) | ||
|
||
var mainCommand = &cobra.Command{ | ||
Use: "sing-box", | ||
PersistentPreRun: preRun, | ||
} | ||
package main | ||
|
||
func init() { | ||
mainCommand.PersistentFlags().StringArrayVarP(&configPaths, "config", "c", nil, "set configuration file path") | ||
mainCommand.PersistentFlags().StringArrayVarP(&configDirectories, "config-directory", "C", nil, "set configuration directory path") | ||
mainCommand.PersistentFlags().StringVarP(&workingDir, "directory", "D", "", "set working directory") | ||
mainCommand.PersistentFlags().BoolVarP(&disableColor, "disable-color", "", false, "disable color output") | ||
} | ||
import "github.com/sagernet/sing-box/log" | ||
|
||
func main() { | ||
if err := mainCommand.Execute(); err != nil { | ||
log.Fatal(err) | ||
} | ||
} | ||
|
||
func preRun(cmd *cobra.Command, args []string) { | ||
globalCtx = context.Background() | ||
sudoUser := os.Getenv("SUDO_USER") | ||
sudoUID, _ := strconv.Atoi(os.Getenv("SUDO_UID")) | ||
sudoGID, _ := strconv.Atoi(os.Getenv("SUDO_GID")) | ||
if sudoUID == 0 && sudoGID == 0 && sudoUser != "" { | ||
sudoUserObject, _ := user.Lookup(sudoUser) | ||
if sudoUserObject != nil { | ||
sudoUID, _ = strconv.Atoi(sudoUserObject.Uid) | ||
sudoGID, _ = strconv.Atoi(sudoUserObject.Gid) | ||
} | ||
} | ||
if sudoUID > 0 && sudoGID > 0 { | ||
globalCtx = filemanager.WithDefault(globalCtx, "", "", sudoUID, sudoGID) | ||
} | ||
if disableColor { | ||
log.SetStdLogger(log.NewDefaultFactory(context.Background(), log.Formatter{BaseTime: time.Now(), DisableColors: true}, os.Stderr, "", nil, false).Logger()) | ||
} | ||
if workingDir != "" { | ||
_, err := os.Stat(workingDir) | ||
if err != nil { | ||
filemanager.MkdirAll(globalCtx, workingDir, 0o777) | ||
} | ||
err = os.Chdir(workingDir) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
} | ||
if len(configPaths) == 0 && len(configDirectories) == 0 { | ||
configPaths = append(configPaths, "config.json") | ||
} | ||
} |
Oops, something went wrong.