#
# Copyright (C) 2010 OpenWrt.org
#
# This is free software, licensed under the GNU General Public License v2.
# See /LICENSE for more information.
#

include $(TOPDIR)/rules.mk

PKG_NAME:=ucarp
PKG_VERSION:=1.5.2
PKG_RELEASE:=2

PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.bz2
PKG_SOURCE_URL:=http://download.pureftpd.org/pub/ucarp
PKG_MD5SUM:=723636dbf79fc6abd329a71ec4ddf79d

PKG_INSTALL:=1

include $(INCLUDE_DIR)/package.mk

define Package/ucarp
  SECTION:=net
  CATEGORY:=Network
  TITLE:=Lets several hosts share one IP
  DEPENDS:=+ip +libpcap
  URL:=http://www.ucarp.org/project/ucarp
endef

define Package/ucarp/description
 ucarp allows a couple of hosts to share common virtual IP addresses in order
 to provide automatic failover. It is a portable userland implementation of the
 secure and patent-free Common Address Redundancy Protocol
endef

define Package/ucarp/install
	$(INSTALL_DIR) $(1)/etc/config
	$(INSTALL_CONF) ./files/ucarp_hs.conf $(1)/etc/config/ucarp_hs
	$(INSTALL_CONF) ./files/ucarp_as.conf $(1)/etc/config/ucarp_as
	$(INSTALL_CONF) ./files/ucarp_mode.conf $(1)/etc/config/ucarp_mode
	$(INSTALL_DIR) $(1)/etc/init.d
	$(INSTALL_BIN) ./files/ucarp_hs.init $(1)/etc/init.d/ucarp_hs
	$(INSTALL_BIN) ./files/ucarp_as.init $(1)/etc/init.d/ucarp_as
	$(INSTALL_BIN) ./files/ucarp_mode.init $(1)/etc/init.d/ucarp_mode
	$(INSTALL_DIR) $(1)/usr/sbin
	$(INSTALL_BIN) $(PKG_BUILD_DIR)/src/ucarp $(1)/usr/sbin/
	$(INSTALL_DIR) $(1)/etc/ucarp
	$(INSTALL_BIN) ./files/ha-up_HS.sh $(1)/etc/ucarp
	$(INSTALL_BIN) ./files/ha-up_AS.sh $(1)/etc/ucarp
	$(INSTALL_BIN) ./files/ha-down_HS.sh $(1)/etc/ucarp
	$(INSTALL_BIN) ./files/ha-down_AS.sh $(1)/etc/ucarp
	$(INSTALL_BIN) ./files/backup-polling_HS.sh $(1)/etc/ucarp
	$(INSTALL_BIN) ./files/master-polling_HS.sh $(1)/etc/ucarp
	$(INSTALL_BIN) ./files/master-polling_AS.sh $(1)/etc/ucarp
	$(INSTALL_BIN) ./files/ha_poll_wanport_AS.sh $(1)/etc/ucarp
	$(INSTALL_BIN) ./files/backup-sync.sh $(1)/etc/ucarp
	$(INSTALL_DIR) $(1)/sbin/debug_collector
	$(INSTALL_BIN) ./files/HA_debug $(1)/sbin/debug_collector
endef

$(eval $(call BuildPackage,ucarp))
