macOS
This commit is contained in:
parent
f63b15ba5a
commit
6d601ad141
7 changed files with 102 additions and 90 deletions
|
@ -66,6 +66,18 @@ builds:
|
||||||
hooks:
|
hooks:
|
||||||
post:
|
post:
|
||||||
- upx "{{ .Path }}" # apt install upx
|
- upx "{{ .Path }}" # apt install upx
|
||||||
|
-
|
||||||
|
id: ntfy_darwin_amd64
|
||||||
|
binary: ntfy
|
||||||
|
env:
|
||||||
|
- CGO_ENABLED=0 # explicitly disable, since we don't need go-sqlite3
|
||||||
|
ldflags:
|
||||||
|
- "-X main.version={{.Version}} -X main.commit={{.Commit}} -X main.date={{.Date}}"
|
||||||
|
goos: [darwin]
|
||||||
|
goarch: [amd64]
|
||||||
|
hooks:
|
||||||
|
post:
|
||||||
|
- upx "{{ .Path }}" # apt install upx
|
||||||
nfpms:
|
nfpms:
|
||||||
-
|
-
|
||||||
package_name: ntfy
|
package_name: ntfy
|
||||||
|
@ -131,6 +143,17 @@ archives:
|
||||||
- client/client.yml
|
- client/client.yml
|
||||||
replacements:
|
replacements:
|
||||||
amd64: x86_64
|
amd64: x86_64
|
||||||
|
-
|
||||||
|
id: ntfy_darwin
|
||||||
|
builds:
|
||||||
|
- ntfy_darwin_amd64
|
||||||
|
wrap_in_directory: true
|
||||||
|
files:
|
||||||
|
- LICENSE
|
||||||
|
- README.md
|
||||||
|
- client/client.yml
|
||||||
|
replacements:
|
||||||
|
darwin: macOS
|
||||||
checksum:
|
checksum:
|
||||||
name_template: 'checksums.txt'
|
name_template: 'checksums.txt'
|
||||||
snapshot:
|
snapshot:
|
||||||
|
|
4
Makefile
4
Makefile
|
@ -22,6 +22,7 @@ help:
|
||||||
@echo " make cli-linux-armv7 - Build server & client (Linux, armv7 only)"
|
@echo " make cli-linux-armv7 - Build server & client (Linux, armv7 only)"
|
||||||
@echo " make cli-linux-arm64 - Build server & client (Linux, arm64 only)"
|
@echo " make cli-linux-arm64 - Build server & client (Linux, arm64 only)"
|
||||||
@echo " make cli-windows-amd64 - Build client (Windows, amd64 only)"
|
@echo " make cli-windows-amd64 - Build client (Windows, amd64 only)"
|
||||||
|
@echo " make cli-darwin-amd64 - Build client (macOS, amd64 only)"
|
||||||
@echo
|
@echo
|
||||||
@echo "Build web app:"
|
@echo "Build web app:"
|
||||||
@echo " make web - Build the web app"
|
@echo " make web - Build the web app"
|
||||||
|
@ -120,6 +121,9 @@ cli-linux-arm64: cli-deps-static-sites cli-deps-gcc-arm64
|
||||||
cli-windows-amd64: cli-deps-static-sites
|
cli-windows-amd64: cli-deps-static-sites
|
||||||
goreleaser build --snapshot --rm-dist --debug --id ntfy_windows_amd64
|
goreleaser build --snapshot --rm-dist --debug --id ntfy_windows_amd64
|
||||||
|
|
||||||
|
cli-darwin-amd64: cli-deps-static-sites
|
||||||
|
goreleaser build --snapshot --rm-dist --debug --id ntfy_darwin_amd64
|
||||||
|
|
||||||
cli-deps: cli-deps-static-sites cli-deps-all cli-deps-gcc
|
cli-deps: cli-deps-static-sites cli-deps-all cli-deps-gcc
|
||||||
|
|
||||||
cli-deps-gcc: cli-deps-gcc-armv6-armv7 cli-deps-gcc-arm64
|
cli-deps-gcc: cli-deps-gcc-armv6-armv7 cli-deps-gcc-arm64
|
||||||
|
|
|
@ -63,7 +63,7 @@ Examples:
|
||||||
Please also check out the docs on publishing messages. Especially for the --tags and --delay options,
|
Please also check out the docs on publishing messages. Especially for the --tags and --delay options,
|
||||||
it has incredibly useful information: https://ntfy.sh/docs/publish/.
|
it has incredibly useful information: https://ntfy.sh/docs/publish/.
|
||||||
|
|
||||||
` + defaultClientConfigFileDescriptionSuffix,
|
` + clientCommandDescriptionSuffix,
|
||||||
}
|
}
|
||||||
|
|
||||||
func execPublish(c *cli.Context) error {
|
func execPublish(c *cli.Context) error {
|
||||||
|
|
|
@ -6,7 +6,11 @@ import (
|
||||||
"github.com/urfave/cli/v2"
|
"github.com/urfave/cli/v2"
|
||||||
"heckel.io/ntfy/client"
|
"heckel.io/ntfy/client"
|
||||||
"heckel.io/ntfy/util"
|
"heckel.io/ntfy/util"
|
||||||
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
"os/exec"
|
||||||
|
"os/user"
|
||||||
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -14,6 +18,12 @@ func init() {
|
||||||
commands = append(commands, cmdSubscribe)
|
commands = append(commands, cmdSubscribe)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const (
|
||||||
|
clientRootConfigFileUnixAbsolute = "/etc/ntfy/client.yml"
|
||||||
|
clientUserConfigFileUnixRelative = "ntfy/client.yml"
|
||||||
|
clientUserConfigFileWindowsRelative = "ntfy\\client.yml"
|
||||||
|
)
|
||||||
|
|
||||||
var cmdSubscribe = &cli.Command{
|
var cmdSubscribe = &cli.Command{
|
||||||
Name: "subscribe",
|
Name: "subscribe",
|
||||||
Aliases: []string{"sub"},
|
Aliases: []string{"sub"},
|
||||||
|
@ -71,7 +81,7 @@ ntfy subscribe --from-config
|
||||||
ntfy sub --from-config # Read topics from config file
|
ntfy sub --from-config # Read topics from config file
|
||||||
ntfy sub --config=myclient.yml --from-config # Read topics from alternate config file
|
ntfy sub --config=myclient.yml --from-config # Read topics from alternate config file
|
||||||
|
|
||||||
` + defaultClientConfigFileDescriptionSuffix,
|
` + clientCommandDescriptionSuffix,
|
||||||
}
|
}
|
||||||
|
|
||||||
func execSubscribe(c *cli.Context) error {
|
func execSubscribe(c *cli.Context) error {
|
||||||
|
@ -195,6 +205,24 @@ func runCommand(c *cli.Context, command string, m *client.Message) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func runCommandInternal(c *cli.Context, script string, m *client.Message) error {
|
||||||
|
scriptFile := fmt.Sprintf("%s/ntfy-subscribe-%s.%s", os.TempDir(), util.RandomString(10), scriptExt)
|
||||||
|
if err := os.WriteFile(scriptFile, []byte(scriptHeader+script), 0700); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer os.Remove(scriptFile)
|
||||||
|
verbose := c.Bool("verbose")
|
||||||
|
if verbose {
|
||||||
|
log.Printf("[%s] Executing: %s (for message: %s)", util.ShortTopicURL(m.TopicURL), script, m.Raw)
|
||||||
|
}
|
||||||
|
cmd := exec.Command(scriptLauncher[0], append(scriptLauncher[1:], scriptFile)...)
|
||||||
|
cmd.Stdin = c.App.Reader
|
||||||
|
cmd.Stdout = c.App.Writer
|
||||||
|
cmd.Stderr = c.App.ErrWriter
|
||||||
|
cmd.Env = envVars(m)
|
||||||
|
return cmd.Run()
|
||||||
|
}
|
||||||
|
|
||||||
func envVars(m *client.Message) []string {
|
func envVars(m *client.Message) []string {
|
||||||
env := os.Environ()
|
env := os.Environ()
|
||||||
env = append(env, envVar(m.ID, "NTFY_ID", "id")...)
|
env = append(env, envVar(m.ID, "NTFY_ID", "id")...)
|
||||||
|
@ -227,3 +255,18 @@ func loadConfig(c *cli.Context) (*client.Config, error) {
|
||||||
}
|
}
|
||||||
return client.NewConfig(), nil
|
return client.NewConfig(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func defaultConfigFileUnix() string {
|
||||||
|
u, _ := user.Current()
|
||||||
|
configFile := clientRootConfigFileUnixAbsolute
|
||||||
|
if u.Uid != "0" {
|
||||||
|
homeDir, _ := os.UserConfigDir()
|
||||||
|
return filepath.Join(homeDir, clientUserConfigFileUnixRelative)
|
||||||
|
}
|
||||||
|
return configFile
|
||||||
|
}
|
||||||
|
|
||||||
|
func defaultConfigFileWindows() string {
|
||||||
|
homeDir, _ := os.UserConfigDir()
|
||||||
|
return filepath.Join(homeDir, clientUserConfigFileWindowsRelative)
|
||||||
|
}
|
||||||
|
|
16
cmd/subscribe_darwin.go
Normal file
16
cmd/subscribe_darwin.go
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
package cmd
|
||||||
|
|
||||||
|
const (
|
||||||
|
scriptExt = "sh"
|
||||||
|
scriptHeader = "#!/bin/sh\n"
|
||||||
|
clientCommandDescriptionSuffix = `The default config file for all client commands is /etc/ntfy/client.yml (if root user),
|
||||||
|
or "~/Library/Application Support" for all other users.`
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
scriptLauncher = []string{"sh", "-c"}
|
||||||
|
)
|
||||||
|
|
||||||
|
func defaultConfigFile() string {
|
||||||
|
return defaultConfigFileUnix()
|
||||||
|
}
|
|
@ -1,57 +1,16 @@
|
||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"github.com/urfave/cli/v2"
|
|
||||||
"heckel.io/ntfy/client"
|
|
||||||
"heckel.io/ntfy/util"
|
|
||||||
"log"
|
|
||||||
"os"
|
|
||||||
"os/exec"
|
|
||||||
"os/user"
|
|
||||||
"path/filepath"
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
const (
|
||||||
defaultClientRootConfigFile = "/etc/ntfy/client.yml"
|
scriptExt = "sh"
|
||||||
defaultClientUserConfigFileRelative = "ntfy/client.yml"
|
scriptHeader = "#!/bin/sh\n"
|
||||||
defaultClientConfigFileDescriptionSuffix = `The default config file for all client commands is /etc/ntfy/client.yml (if root user),
|
clientCommandDescriptionSuffix = `The default config file for all client commands is /etc/ntfy/client.yml (if root user),
|
||||||
or ~/.config/ntfy/client.yml for all other users.`
|
or ~/.config/ntfy/client.yml for all other users.`
|
||||||
)
|
)
|
||||||
|
|
||||||
func runCommandInternal(c *cli.Context, command string, m *client.Message) error {
|
var (
|
||||||
scriptFile, err := createTmpScript(command)
|
scriptLauncher = []string{"sh", "-c"}
|
||||||
if err != nil {
|
)
|
||||||
return err
|
|
||||||
}
|
|
||||||
defer os.Remove(scriptFile)
|
|
||||||
verbose := c.Bool("verbose")
|
|
||||||
if verbose {
|
|
||||||
log.Printf("[%s] Executing: %s (for message: %s)", util.ShortTopicURL(m.TopicURL), command, m.Raw)
|
|
||||||
}
|
|
||||||
cmd := exec.Command("sh", "-c", scriptFile)
|
|
||||||
cmd.Stdin = c.App.Reader
|
|
||||||
cmd.Stdout = c.App.Writer
|
|
||||||
cmd.Stderr = c.App.ErrWriter
|
|
||||||
cmd.Env = envVars(m)
|
|
||||||
return cmd.Run()
|
|
||||||
}
|
|
||||||
|
|
||||||
func createTmpScript(command string) (string, error) {
|
|
||||||
scriptFile := fmt.Sprintf("%s/ntfy-subscribe-%s.sh.tmp", os.TempDir(), util.RandomString(10))
|
|
||||||
script := fmt.Sprintf("#!/bin/sh\n%s", command)
|
|
||||||
if err := os.WriteFile(scriptFile, []byte(script), 0700); err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
return scriptFile, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func defaultConfigFile() string {
|
func defaultConfigFile() string {
|
||||||
u, _ := user.Current()
|
return defaultConfigFileUnix()
|
||||||
configFile := defaultClientRootConfigFile
|
|
||||||
if u.Uid != "0" {
|
|
||||||
homeDir, _ := os.UserConfigDir()
|
|
||||||
return filepath.Join(homeDir, defaultClientUserConfigFileRelative)
|
|
||||||
}
|
|
||||||
return configFile
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,48 +1,15 @@
|
||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"github.com/urfave/cli/v2"
|
|
||||||
"heckel.io/ntfy/client"
|
|
||||||
"heckel.io/ntfy/util"
|
|
||||||
"log"
|
|
||||||
"os"
|
|
||||||
"os/exec"
|
|
||||||
"path/filepath"
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
const (
|
||||||
defaultClientUserConfigFileRelative = "ntfy\\client.yml"
|
scriptExt = "bat"
|
||||||
defaultClientConfigFileDescriptionSuffix = `The default config file for all client commands is %AppData%\ntfy\client.yml.`
|
scriptHeader = ""
|
||||||
|
clientCommandDescriptionSuffix = `The default config file for all client commands is %AppData%\ntfy\client.yml.`
|
||||||
)
|
)
|
||||||
|
|
||||||
func runCommandInternal(c *cli.Context, command string, m *client.Message) error {
|
var (
|
||||||
scriptFile, err := createTmpScript(command)
|
scriptLauncher = []string{"cmd.exe", "/Q", "/C"}
|
||||||
if err != nil {
|
)
|
||||||
return err
|
|
||||||
}
|
|
||||||
defer os.Remove(scriptFile)
|
|
||||||
verbose := c.Bool("verbose")
|
|
||||||
if verbose {
|
|
||||||
log.Printf("[%s] Executing: %s (for message: %s)", util.ShortTopicURL(m.TopicURL), command, m.Raw)
|
|
||||||
}
|
|
||||||
cmd := exec.Command("cmd.exe", "/Q", "/C", scriptFile)
|
|
||||||
cmd.Stdin = c.App.Reader
|
|
||||||
cmd.Stdout = c.App.Writer
|
|
||||||
cmd.Stderr = c.App.ErrWriter
|
|
||||||
cmd.Env = envVars(m)
|
|
||||||
return cmd.Run()
|
|
||||||
}
|
|
||||||
|
|
||||||
func createTmpScript(command string) (string, error) {
|
|
||||||
scriptFile := fmt.Sprintf("%s/ntfy-subscribe-%s.bat", os.TempDir(), util.RandomString(10))
|
|
||||||
if err := os.WriteFile(scriptFile, []byte(command), 0700); err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
return scriptFile, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func defaultConfigFile() string {
|
func defaultConfigFile() string {
|
||||||
homeDir, _ := os.UserConfigDir()
|
return defaultConfigFileWindows()
|
||||||
return filepath.Join(homeDir, defaultClientUserConfigFileRelative)
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue