Skip to content
This repository has been archived by the owner on Jul 4, 2023. It is now read-only.

Commit

Permalink
apcupsd 3.14.13 (fixed)
Browse files Browse the repository at this point in the history
Closes #45899.

Signed-off-by: Mike McQuaid <mike@mikemcquaid.com>
  • Loading branch information
reitermarkus authored and MikeMcQuaid committed Dec 7, 2015
1 parent a7dbff0 commit 7ce08fe
Showing 1 changed file with 30 additions and 44 deletions.
74 changes: 30 additions & 44 deletions Library/Formula/apcupsd.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,89 +4,75 @@ class Apcupsd < Formula
url "https://downloads.sourceforge.net/project/apcupsd/apcupsd%20-%20Stable/3.14.13/apcupsd-3.14.13.tar.gz"
sha256 "57ecbde01d0448bf8c4dbfe0ad016724ae66ab98adf2de955bf2be553c5d03f9"

option "with-usb", "Build with support for USB UPSes."

depends_on "gd"
depends_on "libusb-compat"

def install
# Paths below are hard-coded upstream for creation of `.pkg` installer.

sysconfdir = etc/name

cd "src/apcagent" do
# Install apcagent.app to `prefix` instead of /Applications.
inreplace "Makefile", "Applications", "#{"#{prefix}".gsub(%r{/^\//}, "")}"
# Install apcagent.app to `prefix`.
inreplace "Makefile", "Applications", prefix
end

sysconfdir = "#{etc}/apcupsd"

cd "platforms/darwin" do
# Install binaries to `prefix`.
# Fixes the `--sbindir` option.
# Patch submitted to upstream repo:
# https://sourceforge.net/p/apcupsd/mailman/message/34627459/
# https://sourceforge.net/p/apcupsd/mailman/message/34627459/
inreplace "Makefile", "/sbin", "$(sbindir)"

# Install the LaunchDaemon and kernel extension to `prefix`.
# Install launch daemon and kernel extension to subdirectories of `prefix`.
inreplace "Makefile", "/Library/LaunchDaemons", "#{prefix}/Library/LaunchDaemons"
inreplace "Makefile", "/System/Library/Extensions", kext_prefix

# Tell the launch script and LaunchDaemon to use the appropriate sbin and config directories.
# Use appropriate paths for launch daemon and launch script.
inreplace "apcupsd-start", "/sbin", opt_sbin
inreplace "apcupsd-start", "/etc/apcupsd", sysconfdir
inreplace "org.apcupsd.apcupsd.plist", "/sbin", opt_sbin
inreplace "org.apcupsd.apcupsd.plist", "/etc/apcupsd", sysconfdir

# Custom uninstaller is not needed as everything is installed to `prefix`.
# Custom uninstaller not needed as this is handled by Homebrew.
inreplace "Makefile", /.*apcupsd-uninstall.*/, ""
end

args = [
"--disable-option-checking",
"--prefix=#{prefix}",
"--sbindir=#{sbin}",
"--sysconfdir=#{sysconfdir}",
"--with-cgi-bin=#{sysconfdir}",
"--enable-cgi",
]
system "./configure", "--prefix=#{prefix}",
"--sbindir=#{sbin}",
"--sysconfdir=#{sysconfdir}",
"--enable-cgi", "--with-cgi-bin=#{sysconfdir}",
"--enable-usb", "--enable-modbus-usb"

args << "--enable-usb" << "--enable-modbus-usb" if build.with? "usb"

system "./configure", *args
system "make", "install"
end

def caveats
s = <<-EOS.undent
The #{name} configuration files are located here:
#{etc}/apcupsd
EOS
For #{name} to be able to communicate with UPSes connected via USB,
the kernel extension must be installed by the root user:
if build.with? "usb"
if MacOS.version >= :el_capitan
s += <<-EOS.undent
Note: On OS X El Capitan and above, System Integrity Protection (SIP)
prevents the #{name} kernel extension from loading, which is needed
to communicate with UPSes connected via USB.
sudo cp -pR #{kext_prefix}/ApcupsdDummy.kext /System/Library/Extensions/
sudo chown -R root:wheel /System/Library/Extensions/ApcupsdDummy.kext
sudo touch /System/Library/Extensions/
You will have to unplug and plug the USB cable back in after each
reboot in order for #{name} to be able to connect to the UPS.
EOS

EOS
else
s += <<-EOS.undent
For #{name} to be able to communicate with UPSes connected via USB,
the #{name} kernel extension must be installed by the root user:
if MacOS.version >= :el_capitan
s += <<-EOS.undent
Note: On OS X El Capitan and above, the kernel extension currently
does not work as expected.
sudo cp -pR #{kext_prefix}/ApcupsdDummy.kext /System/Library/Extensions/
sudo chown -R root:wheel /System/Library/Extensions/ApcupsdDummy.kext
sudo touch /System/Library/Extensions/
You will have to unplug and plug the USB cable back in after each
reboot in order for #{name} to be able to connect to the UPS.
EOS
end
EOS
end

s += <<-EOS.undent
To load #{name} at startup, activate the included Launch Daemon:
sudo cp #{prefix}/Library/LaunchDaemons/org.apcupsd.apcupsd.plist /Library/LaunchDaemons
sudo chmod 644 /Library/LaunchDaemons/org.apcupsd.apcupsd.plist
sudo launchctl load -w /Library/LaunchDaemons/org.apcupsd.apcupsd.plist
If this is an upgrade and you already have the Launch Daemon loaded, you
Expand Down

0 comments on commit 7ce08fe

Please sign in to comment.