UPS: apcupsd clean sources
[tomato.git] / release / src / router / apcupsd / platforms / gentoo / ebuild
blob0823031dde581cd91bc7c68193fa7c011288ff6f
1 # Copyright 1999-2002 Gentoo Technologies, Inc.
2 # Distributed under the terms of the GNU General Public License, v2 or later
3 # $Header: /cvsroot/apcupsd/apcupsd/platforms/gentoo/ebuild,v 1.3 2004/04/01 20:32:22 wrking Exp $
5 S=${WORKDIR}/${P}
6 DESCRIPTION="APC UPS daemon with integrated tcp/ip remote shutdown (*ALPHA*)"
7 SRC_URI="http://www.sibbald.com/apcupsd/development/${P}.tar.gz \
8         http://www.sibbald.com/apcupsd/contrib/gd1.2.tar.gz"
9 HOMEPAGE="http://www.sibbald.com/apcupsd/"
10 KEYWORDS="x86"
11 SLOT="0"
12 LICENSE="GPL-2"
14 DEPEND="virtual/glibc
15         net-mail/ssmtp
16         sys-libs/ncurses"
18 XPIDDIR=/var/run
19 XLOGDIR=/var/log
20 XLOCKDIR=/var/lock
21 XSYSCONFDIR=/etc/apcupsd
22 XPWRFAILDIR=${XSYSCONFDIR}
24 src_unpack() {
25         unpack ${A}
27         cp -a ${WORKDIR}/gd1.2 ${S}/src/
28         cp -a ${S} ${S}-orig
29         ln -s /usr/portage/sys-apps/apcupsd/files ${WORKDIR}/files
31         cd ${S}
32         patch -p1 < ${FILESDIR}/${P}-gentoo.patch
35 src_compile() {
36         # patch touches configure.in, so we must regenerate configure
37         WANT_AUTOCONF_2_5=1 autoconf/autoregen.sh
38         APCUPSD_MAIL=/usr/sbin/ssmtp ./configure \
39                 --prefix=/usr \
40                 --sbindir=/usr/sbin \
41                 --sysconfdir=${XSYSCONFDIR} \
42                 --with-pwrfail-dir=${XPWRFAILDIR} \
43                 --with-lock-dir=${XLOCKDIR} \
44                 --with-pid-dir=${XPIDDIR} \
45                 --with-log-dir=${XLOGDIR} \
46                 --with-distname=gentoo \
47                 --with-upstype=usb \
48                 --with-upscable=usb \
49                 --with-serial-dev=/dev/usb/hid/hiddev[0-9] \
50                 --with-net-port=6666 \
51                 --with-nis-port=7000 \
52                 --enable-usb \
53                 --enable-net \
54                 --enable-powerflute \
55                 --enable-pthreads \
56                 --with-cgi-bin=/home/httpd/apcupsd \
57                 --enable-cgi \
58                 || die   
59         make || die
62 src_install () {
63         GEN2DD=${D}
64         make DESTDIR=${GEN2DD%*/} install
66         # fixup smtp scripts for ssmtp compatibility
67         echo "Editing mail scripts for ssmtp compatibility..."
68         cd ${D}etc/apcupsd/
69         patch -p1 < ${FILESDIR}/${P}-ssmtp.patch
71         echo "Installing full documentation into /usr/share/doc/${P}..."
72         cd ${S}/doc
73         dodoc README.*
74         docinto developers_manual
75         dodoc developers_manual/*
76         docinto logo
77         dodoc logo/*
78         docinto manual
79         dodoc manual/*
80         docinto old_documents
81         dodoc old_documents/*
82         docinto vim
83         dodoc vim/*
87 stop_apcupsd() {
88         echo "Stopping old apcupsd daemon..."
89         /etc/init.d/apcupsd stop
92 XAPCPID=${XPIDDIR}/apcupsd.pid
94 pkg_preinst() {
95         if test -f $XAPCPID -a -d /proc/`cat $XAPCPID`; then
96                 stop_apcupsd
97                 touch /etc/apcupsd/.wasrunning
98         elif ! test -f /etc/apcupsd/apcupsd.conf; then
99                 mkdir -p /etc/apcupsd
100                 touch /etc/apcupsd/.newinstall
101         fi
104 pkg_postinst() {
105         if test -f /etc/apcupsd/.wasrunning; then
106                 echo "Restarting new apcupsd daemon..."
107                 /etc/init.d/apcupsd start
108                 rm -f /etc/apcupsd/.wasrunning
109         elif test -f /etc/apcupsd/.newinstall; then
110                 echo "Adding to standard runlevels..."
111                 rc-update add apcupsd boot default nonetwork single
112                 rm -f /etc/apcupsd/.newinstall
113                 echo "Edit ${SYSCONFDIR}/apcupsd.conf for your UPS."
114         fi
117 pkg_prerm() {
118         if test -f $XAPCPID -a -d /proc/`cat $XAPCPID`; then
119                 stop_apcupsd
120         fi
123 pkg_postrm() {
124         # if all packages instances are unmerged, daemon will go missing
125         if ! test -x /usr/sbin/apcupsd -o -x /sbin/apcupsd; then
126                 # so then clean up the config files to avoid a messy /etc
127                 echo "Removing apcupsd from all runlevels..."
128                 rc-update del apcupsd
129                 echo "Removing apcupsd configuration files..."
130                 rm -rf /etc/apcupsd
131                 rm -f /etc/init.d/apcupsd
132                 rm -f /etc/init.d/halt  # we installed it, but still...
133         fi