homebrew-core/Formula/samba.rb

157 lines
5.3 KiB
Ruby

class Samba < Formula
# Samba can be used to share directories with the guest in QEMU user-mode
# (SLIRP) networking with the `-net nic -net user,smb=/share/this/with/guest`
# option. The shared folder appears in the guest as "\\10.0.2.4\qemu".
desc "SMB/CIFS file, print, and login server for UNIX"
homepage "https://www.samba.org/"
url "https://download.samba.org/pub/samba/stable/samba-4.17.4.tar.gz"
sha256 "c0512079db4cac707ccea4c18aebbd6b2eb3acf6e90735e7f645a326be1f4537"
license "GPL-3.0-or-later"
livecheck do
url "https://www.samba.org/samba/download/"
regex(/href=.*?samba[._-]v?(\d+(?:\.\d+)+)\.t/i)
end
bottle do
sha256 arm64_ventura: "d7b51d4816df689e904b47e7127c569dc30010d7f468eb0ee1a5ea61d38732dc"
sha256 arm64_monterey: "71e0287b92be4b6a1bf59b39a44bc1797d0c6df3a41ab4cfe289431097d4c765"
sha256 arm64_big_sur: "1d9c5c45dc7416eaa9be0274c142a4d419306340a234e8f90f68af012f8ed281"
sha256 ventura: "d8a57c488cc1b878e55fa95b75b049d5c6780678f2d885adca92d41cb2035b31"
sha256 monterey: "0114b662e6bf42af9560647e00bd058e9da57406349b1bba49dd7bcaa9012a34"
sha256 big_sur: "13749c6d7d2a3f79f33d6ca8b98000e255cf50b191b36ead4c82ba8ff335f780"
sha256 x86_64_linux: "f97c1ddf6a5dde556437655a11003015aec5acaa74a55bf702e68732d625454f"
end
# configure requires python3 binary to be present, even when --disable-python is set.
depends_on "python@3.11" => :build
depends_on "gnutls"
depends_on "krb5"
depends_on "libtasn1"
depends_on "readline"
uses_from_macos "bison" => :build
uses_from_macos "flex" => :build
uses_from_macos "perl" => :build
uses_from_macos "libxcrypt"
uses_from_macos "zlib"
on_macos do
depends_on "openssl@1.1"
end
on_linux do
depends_on "libtirpc"
end
resource "Parse::Yapp" do
url "https://cpan.metacpan.org/authors/id/W/WB/WBRASWELL/Parse-Yapp-1.21.tar.gz"
sha256 "3810e998308fba2e0f4f26043035032b027ce51ce5c8a52a8b8e340ca65f13e5"
end
def install
# avoid `perl module "Parse::Yapp::Driver" not found` error on macOS 10.xx (not required on 11)
if MacOS.version < :big_sur
ENV.prepend_create_path "PERL5LIB", buildpath/"lib/perl5"
ENV.prepend_path "PATH", buildpath/"bin"
resource("Parse::Yapp").stage do
system "perl", "Makefile.PL", "INSTALL_BASE=#{buildpath}"
system "make"
system "make", "install"
end
end
ENV.append "LDFLAGS", "-Wl,-rpath,#{lib}/private" if OS.linux?
system "./configure",
"--disable-cephfs",
"--disable-cups",
"--disable-iprint",
"--disable-glusterfs",
"--disable-python",
"--without-acl-support",
"--without-ad-dc",
"--without-ads",
"--without-ldap",
"--without-libarchive",
"--without-json",
"--without-pam",
"--without-regedit",
"--without-syslog",
"--without-utmp",
"--without-winbind",
"--with-shared-modules=!vfs_snapper",
"--with-system-mitkrb5",
"--prefix=#{prefix}",
"--sysconfdir=#{etc}",
"--localstatedir=#{var}"
system "make"
system "make", "install"
if OS.mac?
# macOS has its own SMB daemon as /usr/sbin/smbd, so rename our smbd to samba-dot-org-smbd to avoid conflict.
# samba-dot-org-smbd is used by qemu.rb .
# Rename profiles as well to avoid conflicting with /usr/bin/profiles
mv sbin/"smbd", sbin/"samba-dot-org-smbd"
mv bin/"profiles", bin/"samba-dot-org-profiles"
end
end
def caveats
on_macos do
<<~EOS
To avoid conflicting with macOS system binaries, some files were installed with non-standard name:
- smbd: #{HOMEBREW_PREFIX}/sbin/samba-dot-org-smbd
- profiles: #{HOMEBREW_PREFIX}/bin/samba-dot-org-profiles
EOS
end
end
test do
smbd = if OS.mac?
"#{sbin}/samba-dot-org-smbd"
else
"#{sbin}/smbd"
end
system smbd, "--build-options", "--configfile=/dev/null"
system smbd, "--version"
mkdir_p "samba/state"
mkdir_p "samba/data"
(testpath/"samba/data/hello").write "hello"
# mimic smb.conf generated by qemu
# https://github.com/qemu/qemu/blob/v6.0.0/net/slirp.c#L862
(testpath/"smb.conf").write <<~EOS
[global]
private dir=#{testpath}/samba/state
interfaces=127.0.0.1
bind interfaces only=yes
pid directory=#{testpath}/samba/state
lock directory=#{testpath}/samba/state
state directory=#{testpath}/samba/state
cache directory=#{testpath}/samba/state
ncalrpc dir=#{testpath}/samba/state/ncalrpc
log file=#{testpath}/samba/state/log.smbd
smb passwd file=#{testpath}/samba/state/smbpasswd
security = user
map to guest = Bad User
load printers = no
printing = bsd
disable spoolss = yes
usershare max shares = 0
[test]
path=#{testpath}/samba/data
read only=no
guest ok=yes
force user=#{ENV["USER"]}
EOS
port = free_port
spawn smbd, "--debug-stdout", "-F", "--configfile=smb.conf", "--port=#{port}", "--debuglevel=4", in: "/dev/null"
sleep 5
mkdir_p "got"
system "smbclient", "-p", port.to_s, "-N", "//127.0.0.1/test", "-c", "get hello #{testpath}/got/hello"
assert_equal "hello", (testpath/"got/hello").read
end
end