binwiederhier / ntfy

Send push notifications to your phone or desktop using PUT/POST
https://ntfy.sh
Apache License 2.0
18.55k stars 730 forks source link

[Question] - FreeBSD Port #1130

Open rmszc81 opened 5 months ago

rmszc81 commented 5 months ago

Hello,

Straight to the point: are there any plans to port ntfy.sh to FreeBSD?

It would be great to have this tool available there. I will try to build and run it from the sources to see what happens.

Best regards,
Ross

rmszc81 commented 5 months ago

So,

here's what I did:

I started by reading this:

https://docs.ntfy.sh/develop/

Then I cloned the sources into the following repository:

https://github.com/rmszc81/ntfy/tree/freebsd14

I made changes in the following files:

Makefile, .goreleaser.yml

To be able to build in FreeBSD 14.

I installed the following packages in the OS:

pkg install git go goreleaser node20 npm-node20 py311-mkdocs py311-pip py311-pylint-venv

Then I ran:

make cli-freebsd-amd64, apparently it builds the application correctly, and the binary is generated at ntfy_freebsd_amd64_freebsd_amd64_v1

When I run ./dist/ntfy_freebsd_amd64_freebsd_amd64_v1/ntfy, I get the following output:

root@ntfy:/app/ntfy # ./dist/ntfy_freebsd_amd64_freebsd_amd64_v1/ntfy
NAME:
   ntfy - Simple pub-sub notification service

USAGE:
   ntfy [OPTION..]

COMMANDS:
   help, h  Shows a list of commands or help for one command
   Client commands:
     publish, pub, send, trigger  Send message via a ntfy server
     subscribe, sub               Subscribe to one or more topics on a ntfy server
   Server commands:
     access   Grant/revoke access to a topic, or show access
     serve    Run the ntfy server
     tier     Manage/show tiers
     token    Create, list or delete user tokens
     user     Manage/show users
     webpush  Generate keys, in the future manage web push subscriptions

GLOBAL OPTIONS:
   --debug, -d
       enable debug logging (default: false) [$NTFY_DEBUG]
   --trace
       enable tracing (very verbose, be careful) (default: false) [$NTFY_TRACE]
   --no-log-dates, --no_log_dates
       disable the date/time prefix (default: false) [$NTFY_NO_LOG_DATES]
   --log-level value, --log_level value
       set log level (default: "INFO") [$NTFY_LOG_LEVEL]
   --log-level-overrides value, --log_level_overrides value [ --log-level-overrides value, --log_level_overrides value ]  set log level overrides [$NTFY_LOG_LEVEL_OVERRIDES]
   --log-format value, --log_format value
       set log format (default: "text") [$NTFY_LOG_FORMAT]
   --log-file value, --log_file value
       set log file, default is STDOUT [$NTFY_LOG_FILE]
   --help, -h
       show help

Try 'ntfy COMMAND --help' or https://ntfy.sh/docs/ for more information.

To report a bug, open an issue on GitHub: https://github.com/binwiederhier/ntfy/issues.
If you want to chat, simply join the Discord server (https://discord.gg/cT7ECsZj9w), or
the Matrix room (https://matrix.to/#/#ntfy:matrix.org).

ntfy v2.11.0-next (f0dc666), runtime go1.21.10, built at 2024-06-12T02:42:16Z
Copyright (C) 2022 Philipp C. Heckel, licensed under Apache License 2.0 & GPLv2

So it seems that the binary is working as intended.

make install-freebsd-amd64 shows the following error:

rm -f /usr/local/bin/ntfy
cp -a dist/ntfy_freebsd_amd64_freebsd_amd64/ntfy /usr/local/bin/ntfy
cp: dist/ntfy_freebsd_amd64_freebsd_amd64/ntfy: No such file or directory
*** Error code 1

Stop.
make: stopped in /app/ntfy

I know the error above is related to the target path being different. I just don't know why in FreeBSD _v1 is being concatenated to the end of the path when the binary is generated.

make web executes correctly and the UI works fine.

make docs stops at this point:

Successfully installed certifi-2024.6.2 charset-normalizer-3.3.2 colorama-0.4.6 csscompressor-0.9.5 htmlmin2-0.1.13 idna-3.7 jsmin-3.0.1 markdown-3.6 mkdocs-material-9.5.26 mkdocs-material-extensions-1.3.1 mkdocs-minify-plugin-0.8.0 paginate-0.5.6 pygments-2.18.0 pymdown-extensions-10.8.1 regex-2024.5.15 requests-2.32.3 urllib3-2.2.1
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behavior with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
(. venv/bin/activate && python3.11 -m mkdocs build)
/app/ntfy/venv/bin/python3.11: No module named mkdocs
*** Error code 1

Stop.
make: stopped in /app/ntfy

make docs-deps runs without any errors.

make docs-build returns the following:

root@ntfy:/app/ntfy # make docs-build
python3.11 -m venv ./venv
(. venv/bin/activate && python3.11 -m mkdocs build)
/app/ntfy/venv/bin/python3.11: No module named mkdocs
*** Error code 1

Stop.
make: stopped in /app/ntfy

I didn't have enough time to go deeper into this but still, I'd like to have some insights from you guys on how I could solve it.

Best! @rmszc81

positiveEV commented 5 months ago

Hi, Thank you for doing most of the work

pkg install git go goreleaser node20 npm-node20 py311-mkdocs py311-pip py311-pylint-venv

No need to install py311-mkdocs as it will be installed by pip in the venv

make install-freebsd-amd64 shows the following error:

rm -f /usr/local/bin/ntfy
cp -a dist/ntfy_freebsd_amd64_freebsd_amd64/ntfy /usr/local/bin/ntfy
cp: dist/ntfy_freebsd_amd64_freebsd_amd64/ntfy: No such file or directory
*** Error code 1

Stop.
make: stopped in /app/ntfy

I know the error above is related to the target path being different. I just don't know why in FreeBSD _v1 is being concatenated to the end of the path when the binary is generated.

Look at install-linux-amd64 _v1 is also append to the directory name so I guess that it is an expected behavior when building for amd64.

root@ntfy:/app/ntfy # make docs-build
python3.11 -m venv ./venv
(. venv/bin/activate && python3.11 -m mkdocs build)
/app/ntfy/venv/bin/python3.11: No module named mkdocs
*** Error code 1

Stop.
make: stopped in /app/ntfy

You set pip-3.11 as the pip command but it is only available at /usr/local/bin/pip-3.11 and not in the venv. So when running docs-dep it installed the requirements on the system, not in the venv. pip commands available in the venv are pip, pip3 and pip3.11

rmszc81 commented 4 months ago

ok, I'll try to come back to this in this week. is there any other tips for me to continue from here beyond the ones that you already shaerd?

best! @rmszc81

positiveEV commented 4 months ago

No, nothing else. I did not test the binary yet

rmszc81 commented 4 months ago

Looking forward for having ntfy.sh available for FreeBSD @positiveEV! Thank you for the great work!

lindely commented 2 months ago

I was just looking into FreeBSD support when I found this. I did the same as rmszc81 and now have ntfy running on my server. I tested the android app against it and it all seems to work just fine. My diffs:

diff --git a/Makefile b/Makefile
index 4355423e..124b46cb 100644
--- a/Makefile
+++ b/Makefile
@@ -163,6 +163,9 @@ web-lint:
 cli: cli-deps
        goreleaser build --snapshot --clean

+cli-freebsd-amd64: cli-deps-static-sites
+       goreleaser build --snapshot --clean --id ntfy_freebsd_amd64
+
 cli-linux-amd64: cli-deps-static-sites
        goreleaser build --snapshot --clean --id ntfy_linux_amd64
diff --git a/.goreleaser.yml b/.goreleaser.yml
index 062cce1f..65572787 100644
--- a/.goreleaser.yml
+++ b/.goreleaser.yml
@@ -3,6 +3,16 @@ before:
     - go mod download
     - go mod tidy
 builds:
+  -
+    id: ntfy_freebsd_amd64
+    binary: ntfy
+    env:
+      - CGO_ENABLED=1
+    tags: [sqlite_omit_load_extension,osusergo,netgo]
+    ldflags:
+      - "-linkmode=external -extldflags=-static -s -w -X main.version={{.Version}} -X main.commit={{.Commit}} -X main.date={{.Date}}"
+    goos: [freebsd]
+    goarch: [amd64]
   -
     id: ntfy_linux_amd64
     binary: ntfy

Then I create a server.yml and started the daemon with /dist/ntfy_freebsd_amd64_freebsd_amd64_v1/ntfy serve --config /path/to/ntfy.yml. So if anyone else seeks out to try this, it seems (I only tested briefly) to work fine with these minor changes.

This is on FreeBSD 14.1, by the way.