pkgname=btsync
version=2.0.105
revision=2
repository=nonfree
short_desc="Automatically sync files via secure, distributed technology"
maintainer="Juhani Imberg <juhani@imberg.fi>"
license="Proprietary license"
homepage="https://www.getsync.com"
only_for_archs="x86_64 i686 armv7l armv6l"

case "${XBPS_TARGET_MACHINE}" in
x86_64)
	_type=x64
	_hash=9e1427b7a6c6e960a378b97ac458ad53c445457ed0e5c8bf693f446597377b78
	;;
i686)
	_type=i386
	_hash=4d446255ff6332da9a244737d6c20e7dcd32d24a8eaabffbaf73147e5898ed8f
	;;
arm*)
	_type=arm
	_hash=c63fccb76ba3f5dd1197f33bfb8427747faaca9c030f9d8c7f5dfc016d293807
	;;
esac

_filename="BitTorrent-Sync_${_type}.tar.gz"
distfiles="https://download-cdn.getsyncapp.com/${version}/linux-${_type}/${_filename}"
checksum="$_hash"
skip_extraction=$_filename
create_wrksrc=yes
system_accounts="btsync"
btsync_homedir="/var/lib/btsync"
conf_files="/etc/btsync.conf"

do_fetch() {
	mkdir -p $wrksrc
	cd $wrksrc
	xbps-uhelper fetch $distfiles
	echo "$checksum	 $_filename" | sha256sum -c || { sha256sum "$_filename"; return 1; }
}

do_extract() {
	:
}

do_build() {
	sed \
		-e "s|%BTSYNC_URL%|${distfiles}|" \
		-e "s|%BTSYNC_CHECKSUM%|${checksum}|" \
			${FILESDIR}/btsync-vars.sh.in > btsync-vars.sh
}

do_install() {
	vmkdir "usr/lib/btsync"
	vcopy btsync-vars.sh "usr/lib/btsync"

	vconf "${FILESDIR}/btsync.conf"

	vlicense "${FILESDIR}/LICENSE"

	vsv btsync
}
