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-4-1/netatalk-4.4.1.tar.xz" sha256 "8fcab0bf3b39cd8a94fe3ee7a8264c6000515a3af377da3416696609ab13316d" license all_of: [ "GPL-2.0-only", "GPL-2.0-or-later", "LGPL-2.0-only", "LGPL-2.1-or-later", "BSD-2-Clause", "BSD-3-Clause", "MIT", ] head "https://github.com/Netatalk/netatalk.git", branch: "main" no_autobump! because: :incompatible_version_format bottle do sha256 arm64_tahoe: "a035b13e47aa4e8c0b69b8c8d1349fdbd1770498742d4355c34fdfa8438ea6dd" sha256 arm64_sequoia: "9d836b99af5ab42bba289f88704e773fbf7b943a88460d3b356cb3598fac4f46" sha256 arm64_sonoma: "00c9b000cfc0f11c3818ed4f569f23e43c2b248a954cc63ebfbaf38910d848be" sha256 sonoma: "c60acf3487cac5ef372d67eeab9f23083ff8c6812e8a039d8abfec4d72176606" sha256 arm64_linux: "ebbf5e06fe8b5d04eafee507c8be83d68ea8fc18e8c2822e1dddd3826fc37f96" sha256 x86_64_linux: "b0b70664aa88aaf213ba4d943c5f5fc0034fd5d67143ba638c4cbb7139c51046" 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 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["berkeley-db@5"].opt_lib) ENV.append "LDFLAGS", "-Wl,-rpath,#{bdb5_rpath}" if OS.linux? args = [ "-Dwith-afpstats=false", "-Dwith-appletalk=#{OS.linux?}", # macOS doesn't have an AppleTalk stack "-Dwith-bdb-path=#{Formula["berkeley-db@5"].opt_prefix}", "-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=false", "-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 <<~EOS [Global] afp port = #{port} log file = #{testpath}/afpd.log log level = default:info signature = 1234567890ABCDEF EOS 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