class Netatalk < Formula desc "File server for Macs, compliant with Apple Filing Protocol (AFP)" homepage "https://netatalk.io" url "https://github.com/Netatalk/netatalk/releases/download/netatalk-4-5-0/netatalk-4.5.0.tar.xz" sha256 "62d77f5a491e69086c1706ff7d9e016912e0e48b43d0c3a7ae60c384b6d625b3" license all_of: [ "GPL-2.0-or-later", # Licenses covering individual source files or modules. MIT is omitted because we don't install Webmin module "BSD-2-Clause", # config/pap.in "BSD-3-Clause", # bin/nad/nad_{cp,util}.c, etc/afpd/nfsquota.c, etc/papd/{lp,printcap}.c, ... "HPND", # COPYRIGHT (Regents of The University of Michigan) "HPND-Pbmplus", # COPYRIGHT (Adrian Sun) "Kazlib", # etc/afpd/hash.*, include/atalk/hash.h "LGPL-2.0-or-later", # libatalk/unicode/charsets/mac_{centraleurope,cyrillic,greek,hebrew,turkish}.h "LGPL-2.1-or-later", # bin/nad/ftw.* ] head "https://github.com/Netatalk/netatalk.git", branch: "main" no_autobump! because: :incompatible_version_format bottle do rebuild 1 sha256 arm64_tahoe: "a34ddecb88d6c79ab8b1bc149a26dcf7bbd82c300f6dad2d5c604d0fafa2ada8" sha256 arm64_sequoia: "d8ccfee9249cbdc7c3eb75e0d6eed1ee731b7c8c18bed51d446f62adbe5bee2c" sha256 arm64_sonoma: "6f557473b242401dda3c38c1b4bd57271e4dfdce53cd9b796880069947a18d89" sha256 sonoma: "59d535e9ad0d6ed14b30cb37931ff08f3b5952c38a71c6e60693f3b1e3ed8e2b" sha256 arm64_linux: "6e7765cb1e13aac3cd28119be04bc12716ee1d6ff8e2e4f1fb98e4afe02646d2" sha256 x86_64_linux: "d157c8e2aa8d8150f9eb114149ec9add8addcf73670d7a5cac96f7aeac153c7c" end depends_on "cmark-gfm" => :build depends_on "meson" => :build depends_on "ninja" => :build depends_on "pkgconf" => :build depends_on "berkeley-db@5" # macOS bdb library lacks DBC type etc. depends_on "bstring" depends_on "cracklib" depends_on "iniparser" depends_on "libevent" depends_on "libgcrypt" depends_on "mariadb-connector-c" depends_on "openldap" # macOS LDAP.Framework is not fork safe depends_on "talloc" uses_from_macos "krb5" uses_from_macos "libxcrypt" uses_from_macos "perl" uses_from_macos "sqlite" on_linux do depends_on "avahi" # on macOS we use native mDNS instead depends_on "cups" # used by the AppleTalk print server depends_on "libtirpc" # on macOS we use native RPC instead depends_on "linux-pam" end def install inreplace "distrib/initscripts/macos.netatalk.in", "@sbindir@", opt_sbin inreplace "distrib/initscripts/macos.netatalk.plist.in", "@bindir@", opt_bin inreplace "distrib/initscripts/macos.netatalk.plist.in", "@sbindir@", opt_sbin inreplace "distrib/initscripts/systemd.netatalk.service.in", "@sbindir@", opt_sbin bdb5_rpath = rpath(target: formula_opt_lib("berkeley-db@5")) ENV.append "LDFLAGS", "-Wl,-rpath,#{bdb5_rpath}" if OS.linux? args = [ "-Dwith-appletalk=#{OS.linux?}", # macOS doesn't have an AppleTalk stack "-Dwith-bdb-path=#{formula_opt_prefix("berkeley-db@5")}", "-Dwith-cups-libdir-path=#{libexec}", "-Dwith-cups-pap-backend=#{OS.linux?}", "-Dwith-docs=man,readmes,html_manual", "-Dwith-homebrew=true", "-Dwith-init-dir=#{prefix}", "-Dwith-init-hooks=false", "-Dwith-install-hooks=false", "-Dwith-lockfile-path=#{var}/run", "-Dwith-pam-config-path=#{etc}/pam.d", "-Dwith-pkgconfdir-path=#{pkgetc}", "-Dwith-spotlight=true", "-Dwith-statedir-path=#{var}", "-Dwith-testsuite=true", ] system "meson", "setup", "build", *args, *std_meson_args system "meson", "compile", "-C", "build", "--verbose" system "meson", "install", "-C", "build" end service do name macos: "io.netatalk.daemon", linux: "netatalk" require_root true end def caveats on_macos do on_arm do <<~EOS Authenticating as a system user requires manually installing the PAM configuration file to a predetermined location by running: sudo install -d -o $USER -g admin /usr/local/etc mkdir -p /usr/local/etc/pam.d cp $(brew --prefix)/etc/pam.d/netatalk /usr/local/etc/pam.d See `man pam.conf` for more information. EOS end end end test do pidfile = var/"run/netatalk#{".pid" if OS.mac?}" port = free_port (testpath/"afp.conf").write <<~CONF [Global] afp port = #{port} log file = #{testpath}/afpd.log log level = default:info signature = 1234567890ABCDEF CONF fork do system sbin/"netatalk", "-d", "-F", testpath/"afp.conf" end system sbin/"afpd", "-V" system sbin/"netatalk", "-V" sleep 5 assert_match "AFP reply", shell_output("#{bin}/asip-status localhost #{port}") pid = pidfile.read.chomp.to_i ensure Process.kill("TERM", pid) end end