# Contributor: Ted Trask <ttrask01@yahoo.com>
# Maintainer: Ted Trask <ttrask01@yahoo.com>
pkgname=acf-provisioning-polycom
pkgver=5.5.1
pkgrel=0
pkgdesc="Files for provisioning Polycom IP phones"
url="http://www.polycom.com/products/voice/index.html"
arch="noarch"
license="AS-IS"
depends=""
makedepends=""
# Make sure 5.5.1 comes after 4.0.11 so that older files are overwritten
source="http://downloads.polycom.com/voice/voip/uc/Polycom_UC_Software_4_0_11_rts15_release_sig_split.zip
http://downloads.polycom.com/voice/voip/uc/SoundPoint_IP_BootROM_4_4_0B_Upgrader_release_sig.zip
http://downloads.polycom.com/voice/voip/uc/Polycom_UC_Software_5_5_1_rts35_release_sig_split.zip
000000000000.cfg.patch
000000000000-phone.cfg
000000000000-web.cfg
000000000000-directory.xml"
subpackages=""

_builddir="$srcdir/"

link_dupes() {
	local dir=
	local old_pwd="$PWD"
	for dir; do
		echo "Creating links of duplicate files at '$dir'"
		cd "$dir" || break
		prevsum=
		prevfile=
		md5sum *.ld | sort | while read sum file; do
			if [ "$sum" = "$prevsum" ]; then
				echo "* Creating link of '$file'"
				rm $file && ln -s $prevfile $file || break
			else
				prevsum=$sum
				prevfile=$file
			fi
		done || break
	done
	local ret=$?
	cd "$old_pwd"
	return $ret
}

prepare() {
	local i
	cd "$_builddir"
	sed -i -e 's/\r//' 000000000000.cfg
	for i in $source; do
		case $i in
		*.patch) msg "Applying ${i}"; patch -p1 -i $i || return 1;;
		esac
	done
}

package() {
	cd "$_builddir"
	link_dupes "$_builddir" || return 1
	mkdir -p "$pkgdir"/var/www/provisioning/htdocs/Polycom
	mkdir -p "$pkgdir"/var/www/provisioning/htdocs/log
	echo "$pkgname-$pkgver-r$pkgrel" > "$pkgdir"/var/www/provisioning/htdocs/Polycom/package-version
	cp -r *.ld *.wav SoundPointIPLocalization VVXLocalization 000000000000.cfg "$pkgdir"/var/www/provisioning/htdocs
	cp 000000000000-directory.xml 000000000000-phone.cfg 000000000000-web.cfg "$pkgdir"/var/www/provisioning/htdocs/Polycom
}

# unpack the sources
default_unpack() {
	local u
	if [ -z "$force" ]; then
		verify || return 1
		initdcheck || return 1
	fi
	mkdir -p "$srcdir"
	for u in $source; do
		local s="$SRCDEST/$(filename_from_uri $u)"
		case "$s" in
			*.zip)
				msg "Unpacking $s..."
				unzip -o "$s" -d "$srcdir" || return 1;;
		esac
	done
}

md5sums="e349c0b24cc118a5ef85b52d7e82b116  Polycom_UC_Software_4_0_11_rts15_release_sig_split.zip
b5ac28a1b4ede82fca226675c0b6981d  SoundPoint_IP_BootROM_4_4_0B_Upgrader_release_sig.zip
cdbf5322601881e37268b17048306097  Polycom_UC_Software_5_5_1_rts35_release_sig_split.zip
936110c5fbb17545526dc005f5b49c40  000000000000.cfg.patch
2c32486b7c9d692326fd6270664eac01  000000000000-phone.cfg
2c32486b7c9d692326fd6270664eac01  000000000000-web.cfg
4a6ff93b944a710da0c3eb99938f42cc  000000000000-directory.xml"
sha256sums="0904a07dbcf3e8c6a697f76201581c6b4d6c200aa8c5ef420b43824eb4abb310  Polycom_UC_Software_4_0_11_rts15_release_sig_split.zip
4565248f354321901323d01b1aeed8bb6e00beedc331a3f7545cbae83d194113  SoundPoint_IP_BootROM_4_4_0B_Upgrader_release_sig.zip
464f360201f8b0c8506686f64b0a1c9981ff62c790cc06a69bd22ba9cf2d38e0  Polycom_UC_Software_5_5_1_rts35_release_sig_split.zip
286b77f8b18a70a7e42b6eaa6ff9ae7e849e3335dbf2cfb6390ee69243f0d4c7  000000000000.cfg.patch
e2f3dcd842d6eb44a98140e7fb60487ca70e519d5d09872a54ce1372d5a432b4  000000000000-phone.cfg
e2f3dcd842d6eb44a98140e7fb60487ca70e519d5d09872a54ce1372d5a432b4  000000000000-web.cfg
875f5bbec057d29508bcd671a203d8e2852cd959aeaeb937443cedbe824e0a41  000000000000-directory.xml"
sha512sums="e416838352d6e8a524ca48981875e9ebe384ba4bd27d056842fb8c6de73356599aec65466867fa242214d79e0060d262268b0e82008674da694a2fc48a31b3fc  Polycom_UC_Software_4_0_11_rts15_release_sig_split.zip
b624b6618af41c21de016ead0746be9702834632e32de1bd62a5b47ad2308f0fb9def72fcfb35259731b7431d00a958e9c4ad3ad7d7257a29bba9e976dc70c4c  SoundPoint_IP_BootROM_4_4_0B_Upgrader_release_sig.zip
adeefe00bf5af0a7408dacc6175575634c5d47f0f796e3b251166957e266f3bb1c30e79a1af68b4675d62458680ccd604ea38d2ff0510bb463caebff8080bed3  Polycom_UC_Software_5_5_1_rts35_release_sig_split.zip
32e1c0585baa3d827e12f2a501955ae7ee4f8f0594b14d188235a4f3dbdcb6d241ba2bf52ed4abfc94456dc5984d170f1f8aaa72a8fc56b5b578f6ba289b38b6  000000000000.cfg.patch
db2da0f4c393bdea773f3e5a7daa581a58caca738538db6153b223383176aae30e2081c198291d78c44eddd446a1cab9cffef78646360847ce4955c59f288300  000000000000-phone.cfg
db2da0f4c393bdea773f3e5a7daa581a58caca738538db6153b223383176aae30e2081c198291d78c44eddd446a1cab9cffef78646360847ce4955c59f288300  000000000000-web.cfg
9adc73d02aa4f545aca893c335284d77099c56fcc17a48f61003ede8713e96aeb8f467896f4dfbf7db67255cc3d60faf353b76ab86c5881d0ba884d1c0acffb3  000000000000-directory.xml"
