#!/bin/sh
#
# Ugly, ugly, ugly script for adding FreeNAS plugins to the PBI repo
# index and meta files. This is sort of tedious and we need automation.
#
# Currently, plugins must be added one at a time.
#


plugins="/mnt/tank/ixsystems/repo/plugins/9/x64"
metadir="${plugins}/pbi-meta"

imgurl="http://download.freenas.org/plugins/9/x64/icons"
pbiurl="http://download.freenas.org/plugins/9/x64"

metafile="pbi-meta-9"
indexfile="pbi-index-9"
repofile="pbi-repo.rpo"


cleanup_files()
{
	rm -f "${metafile}" "${indexfile}" "${metafile}.bz2" "${indexfile}.bz2"
	touch "${metafile}" 
	touch "${indexfile}"
}

add_plugin_bacula()
{
	local bacula_pbi="bacula-sd-5.2.12_3-amd64.pbi"

	pbi_metatool add --app \
		-n "bacula-sd" \
		-a "Bacula Storage Daemon" \
		-c "System Utilities" \
		-d 'Network backup solution (server)' \
		-i "${imgurl}/bacula.png" \
		-k "system,utils,backup" \
		-l "GPL" \
		-t "Graphical" \
		-u "http://www.bacula.org/" \
		"${metafile}"

	pbi_indextool add \
		-f "${plugins}/${bacula_pbi}" \
		-u "/${bacula_pbi}" \
		"${indexfile}"
}

add_plugin_couchpotato()
{
#	local couchpotato_pbi="couchpotato-9.3.0-amd64.pbi"
#	local couchpotato_pbi="couchpotato-9.3.1-amd64.pbi"
#	local couchpotato_pbi="couchpotato-autoupdate.9_2-amd64.pbi"
#	local couchpotato_pbi="couchpotato-autoupdate.9_3-amd64.pbi"
#	local couchpotato_pbi="couchpotato-autoupdate.9_4-amd64.pbi"
	local couchpotato_pbi="couchpotato-autoupdate.9_5-amd64.pbi"

	pbi_metatool add --app \
		-n "CouchPotato" \
		-a "RuudBurger" \
		-c "Network - P2P" \
		-d 'An automatic NZB and torrent downloader' \
		-i "${imgurl}/couchpotato.png" \
		-k "net,p2p,share,nzb" \
		-l "GPLv3" \
		-t "Graphical" \
		-u "https://couchpota.to/" \
		"${metafile}"

	pbi_indextool add \
		-f "${plugins}/${couchpotato_pbi}" \
		-u "/${couchpotato_pbi}" \
		"${indexfile}"
}

add_plugin_crashplan()
{
	local crashplan_pbi="crashplan-3.6.3_1-amd64.pbi"

	pbi_metatool add --app \
		-n "crashplan" \
		-a "CrashPlan program" \
		-c "System Utilities" \
		-d 'Crashplan backs up data to remote servers, other computers, or hard drives' \
		-i "${imgurl}/crashplan.png" \
		-k "system,utils,backup" \
		-l "Unknown" \
		-t "Graphical" \
		-u "http://www.crashplan.com/" \
		"${metafile}"

	pbi_indextool add \
		-f "${plugins}/${crashplan_pbi}" \
		-u "/${crashplan_pbi}" \
		"${indexfile}"
}

add_plugin_emby()
{
#	local emby_pbi="emby-3.0.5572.0-amd64.pbi"
#	local emby_pbi="emby-3.0.5572.0_1-amd64.pbi"
#	local emby_pbi="emby-3.0.5582.4-amd64.pbi"
#	local emby_pbi="emby-3.0.5597.1-amd64.pbi"
#	local emby_pbi="emby-3.0.5607.2-amd64.pbi"
#	local emby_pbi="emby-3.0.5621.4-amd64.pbi"
#	local emby_pbi="emby-3.0.5641.5-amd64.pbi"
#	local emby_pbi="emby-3.0.5667.6-amd64.pbi"
#	local emby_pbi="emby-3.0.5675.1-amd64.pbi"
#	local emby_pbi="emby-3.0.5724.3-amd64.pbi"
#	local emby_pbi="emby-3.0.5724.4-amd64.pbi"
#	local emby_pbi="emby-3.0.5724.5-amd64.pbi"
#	local emby_pbi="emby-3.0.5768.7-amd64.pbi"
#	local emby_pbi="emby-3.0.5781.0-amd64.pbi"
#	local emby_pbi="emby-3.0.5781.1-amd64.pbi"
#	local emby_pbi="emby-3.0.5781.3-amd64.pbi"
#	local emby_pbi="emby-3.0.5781.4-amd64.pbi"
#	local emby_pbi="emby-3.0.5781.5-amd64.pbi"
#	local emby_pbi="emby-3.0.5781.8-amd64.pbi"
#	local emby_pbi="emby-3.0.5785-amd64.pbi"
#	local emby_pbi="emby-3.0.5786-amd64.pbi"
#	local emby_pbi="emby-3.0.5821-amd64.pbi"
#	local emby_pbi="emby-3.0.5871-amd64.pbi"
#	local emby_pbi="emby-3.0.5882-amd64.pbi"
#	local emby_pbi="emby-3.0.5911-amd64.pbi"
#	local emby_pbi="emby-3.0.5912-amd64.pbi"
#	local emby_pbi="emby-3.0.5913-amd64.pbi"
#	local emby_pbi="emby-3.0.5931-amd64.pbi"
#	local emby_pbi="emby-3.0.5934-amd64.pbi"
#	local emby_pbi="emby-3.0.5972-amd64.pbi"
#	local emby_pbi="emby-3.0.5986-amd64.pbi"
#	local emby_pbi="emby-3.0.6030-amd64.pbi"
#	local emby_pbi="emby-3.0.6060-amd64.pbi"
#	local emby_pbi="emby-3.0.6070-amd64.pbi"
#	local emby_pbi="emby-3.0.6400-amd64.pbi"
#	local emby_pbi="emby-3.0.7200-amd64.pbi"
#	local emby_pbi="emby-3.0.8200-amd64.pbi"
#	local emby_pbi="emby-3.0.8300-amd64.pbi"
#	local emby_pbi="emby-3.0.8500-amd64.pbi"
#	local emby_pbi="emby-3.1.0-amd64.pbi"
#	local emby_pbi="emby-3.1.2-amd64.pbi"
#	local emby_pbi="emby-3.2.1-amd64.pbi"
#	local emby_pbi="emby-3.2.4-amd64.pbi"
#	local emby_pbi="emby-3.2.5-amd64.pbi"
#	local emby_pbi="emby-3.2.7-amd64.pbi"
#	local emby_pbi="emby-3.2.9-amd64.pbi"
#	local emby_pbi="emby-3.2.12-amd64.pbi"
#	local emby_pbi="emby-3.2.13.0-amd64.pbi"
#	local emby_pbi="emby-3.2.15.0-amd64.pbi"
#	local emby_pbi="emby-3.2.17.0-amd64.pbi"
#	local emby_pbi="emby-3.2.20.0-amd64.pbi"
#	local emby_pbi="emby-3.2.25.0-amd64.pbi"
#	local emby_pbi="emby-3.2.26.0-amd64.pbi"
#	local emby_pbi="emby-3.2.28.0-amd64.pbi"
#	local emby_pbi="emby-3.2.30.0-amd64.pbi"
#	local emby_pbi="emby-3.2.32.0-amd64.pbi"
#	local emby_pbi="emby-3.2.33.0-amd64.pbi"
#	local emby_pbi="emby-3.2.36.0-amd64.pbi"
#	local emby_pbi="emby-3.2.50.0-amd64.pbi"
#	local emby_pbi="emby-3.2.60.0-amd64.pbi"
#	local emby_pbi="emby-3.2.70.0-amd64.pbi"
	local emby_pbi="emby-3.3.1.0-amd64.pbi"

	pbi_metatool add --app \
		-n "Emby" \
		-a "Emby Team" \
		-c "Multimedia" \
		-d 'A home media server built using other popular open source technologies' \
		-i "${imgurl}/emby.png" \
		-k "multimedia" \
		-l "GPL" \
		-t "Graphical" \
		-u "http://emby.media/" \
		"${metafile}"

	pbi_indextool add \
		-f "${plugins}/${emby_pbi}" \
		-u "/${emby_pbi}" \
		"${indexfile}"
}

add_plugin_firefly()
{
	local firefly_pbi="firefly-1696_8-amd64.pbi"

	pbi_metatool add --app \
		-n "firefly" \
		-a "Firefly Server" \
		-c "Multimedia" \
		-d "Firefly (mt-daapd) is an open-source media server for the Roku SoundBridge and Apple iTunes" \
		-i "${imgurl}/firefly.png" \
		-k "media,music,movies,tv,av,daap" \
		-l "GPL" \
		-t "Graphical" \
		-u "http://www.fireflymediaserver.org/" \
		"${metafile}"

	pbi_indextool add \
		-f "${plugins}/${firefly_pbi}" \
		-u "/${firefly_pbi}" \
		"${indexfile}"
}

add_plugin_headphones()
{
#	local headphones_pbi="headphones-9.3.0-amd64.pbi"
	local headphones_pbi="headphones-9.3.1-amd64.pbi"

	pbi_metatool add --app \
		-n "Headphones" \
		-a "HEADPHONES" \
		-c "Multimedia" \
		-d 'Automatic music downloader for SABnzbd' \
		-i "${imgurl}/headphones.png" \
		-k "media,music,av" \
		-l "GPL" \
		-t "Graphical" \
		-u "https://github.com/rembo10/headphones" \
		"${metafile}" 

	pbi_indextool add \
		-f "${plugins}/${headphones_pbi}" \
		-u "/${headphones_pbi}" \
		"${indexfile}"
}

add_plugin_htpc_manager()
{
#	local htpc_manager_pbi="htpc-manager-9.3.0-amd64.pbi"
#	local htpc_manager_pbi="htpc-manager-9.3.1-amd64.pbi"
#	local htpc_manager_pbi="htpc-manager-autoupdate.9_1-amd64.pbi"
	local htpc_manager_pbi="htpc-manager-autoupdate.9_2-amd64.pbi"

	pbi_metatool add --app \
		-n "HTPC-Manager" \
		-a "Hellowlol" \
		-c 'Multimedia' \
		-d 'A fully responsive interface to manage all your favorite software on your Htpc.' \
		-i "${imgurl}/htpc-manager.png" \
		-k "media,music,movies,tv,dlna,upnp,av" \
		-l "GPLv3" \
		-t "Graphical" \
		-u "http://htpc.io" \
		"${metafile}"

	pbi_indextool add \
		-f "${plugins}/${htpc_manager_pbi}" \
		-u "/${htpc_manager_pbi}" \
		"${indexfile}"
}

add_plugin_lazylibrarian()
{
	local lazylibrarian_pbi="lazylibrarian-9.3.0-amd64.pbi"

	pbi_metatool add --app \
		-n "LazyLibrarian" \
		-a "DobyTang" \
		-c "Desk Utilities" \
		-d 'A program to follow authors and grab metadata for all your digital reading needs.' \
		-i "${imgurl}/lazylibrarian.png" \
		-k "eBooks,multimedia,books,magazines" \
		-l "GPLv3" \
		-t "Graphical" \
		-u "https://github.com/DobyTang/LazyLibrarian" \
		"${metafile}"

	pbi_indextool add \
		-f "${plugins}/${lazylibrarian_pbi}" \
		-u "/${lazylibrarian_pbi}" \
		"${indexfile}"
}

add_plugin_madsonic()
{
#	local madsonic_pbi="madsonic-6.0-amd64.pbi"
	local madsonic_pbi="madsonic-6.1-amd64.pbi"

	pbi_metatool add --app \
		-n "Madsonic" \
		-a "MADSONIC" \
		-c "Multimedia" \
		-d 'A web-based media streamer and jukebox fork of Subsonic.' \
		-i "${imgurl}/madsonic.png" \
		-k "media,music,movies,tv,dlna,upnp,av" \
		-l "GPL" \
		-t "Graphical" \
		-u "http://www.madsonic.org" \
		"${metafile}" 

	pbi_indextool add \
		-f "${plugins}/${madsonic_pbi}" \
		-u "/${madsonic_pbi}" \
		"${indexfile}"
}

add_plugin_maraschino()
{
#	local maraschino_pbi="maraschino-9.3.0-amd64.pbi"
	local maraschino_pbi="maraschino-9.3.1-amd64.pbi"

	pbi_metatool add --app \
		-n "Maraschino" \
		-a "mrkipling" \
		-c 'Multimedia' \
		-d 'A simple web interface to act as a nice overview/front page for an XBMC HTPC' \
		-i "${imgurl}/maraschino.png" \
		-k "media,music,movies,tv,dlna,upnp,av" \
		-l "MIT" \
		-t "Graphical" \
		-u "http://www.maraschinoproject.com" \
		"${metafile}"

	pbi_indextool add \
		-f "${plugins}/${maraschino_pbi}" \
		-u "/${maraschino_pbi}" \
		"${indexfile}"
}

add_plugin_mineos()
{
#	local mineos_pbi="mineos-9.2.1-amd64.pbi"
#	local mineos_pbi="mineos-9.3.0-amd64.pbi"
#	local mineos_pbi="mineos-9.3.1-amd64.pbi"
#	local mineos_pbi="mineos-9.3.2-amd64.pbi"
#	local mineos_pbi="mineos-9.3.3-amd64.pbi"
#	local mineos_pbi="mineos-9.3.4-amd64.pbi"
	local mineos_pbi="mineos-9.3.5-amd64.pbi"

	pbi_metatool add --app \
		-n "MineOS" \
		-a "MINEOS" \
		-c "Games" \
		-d 'A web interface to create and manage Minecraft server instances.' \
		-i "${imgurl}/mineos.png" \
		-k "games" \
		-l "GPL" \
		-t "Graphical" \
		-u "http://minecraft.codeemo.com/" \
		"${metafile}"

	pbi_indextool add \
		-f "${plugins}/${mineos_pbi}" \
		-u "/${mineos_pbi}" \
		"${indexfile}"
}

add_plugin_mylar()
{
#	local mylar_pbi="mylar-9.3.0-amd64.pbi"
#	local mylar_pbi="mylar-9.3.1-amd64.pbi"
	local mylar_pbi="mylar-9.3.2-amd64.pbi"

	pbi_metatool add --app \
		-n "Mylar" \
		-a "evilhero" \
		-c "Network - P2P" \
		-d 'An automated Comic Book downloader (cbr/cbz) trying to follow in the lines of sickbeard and headphones.' \
		-i "${imgurl}/mylar.png" \
		-k "net,p2p,share,nzb" \
		-l "GPLv3" \
		-t "Graphical" \
		-u "https://github.com/evilhero/mylar" \
		"${metafile}"

	pbi_indextool add \
		-f "${plugins}/${mylar_pbi}" \
		-u "/${mylar_pbi}" \
		"${indexfile}"
}

add_plugin_nextcloud()
{
	local nextcloud_pbi="nextcloud-10.0.1-amd64.pbi"

	pbi_metatool add --app \
		-n "Nextcloud" \
		-a "Nextcloud" \
		-c "Web" \
		-d 'Nextcloud is a system for the creation and management of personal cloud resources' \
		-i "${imgurl}/nextcloud.png" \
		-k "net,www,web,cloud" \
		-l "GPL" \
		-t "Graphical" \
		-u "https://nextcloud.com/" \
		"${metafile}"

	pbi_indextool add \
		-f "${plugins}/${nextcloud_pbi}" \
		-u "/${nextcloud_pbi}" \
		"${indexfile}"
}

add_plugin_nzbhydra()
{
	local nzbhydra_pbi="nzbhydra-autoupdate.9_1-amd64.pbi"

	pbi_metatool add --app \
		-n "NZBHydra" \
		-a "theotherp" \
		-c "News" \
		-d 'A meta search for NZB indexers' \
		-i "${imgurl}/nzbhydra.png" \
		-k "news,nzb" \
		-l "Apachev2.0" \
		-t "Graphical" \
		-u "https://github.com/theotherp/nzbhydra" \
		"${metafile}"

	pbi_indextool add \
		-f "${plugins}/${nzbhydra_pbi}" \
		-u "/${nzbhydra_pbi}" \
		"${indexfile}"
}

add_plugin_owncloud()
{
#	local owncloud_pbi="owncloud-8.0.2-amd64.pbi"
#	local owncloud_pbi="owncloud-8.0.3-amd64.pbi"
#	local owncloud_pbi="owncloud-8.1.0-amd64.pbi"
#	local owncloud_pbi="owncloud-8.1.0_1-amd64.pbi"
#	local owncloud_pbi="owncloud-8.1.1-amd64.pbi"
#	local owncloud_pbi="owncloud-8.2.0-amd64.pbi"
#	local owncloud_pbi="owncloud-8.2.1-amd64.pbi"
#	local owncloud_pbi="owncloud-9.0.0-amd64.pbi"
#	local owncloud_pbi="owncloud-9.0.1-amd64.pbi"
#	local owncloud_pbi="owncloud-9.0.3-amd64.pbi"
#	local owncloud_pbi="owncloud-9.1.0-amd64.pbi"
	local owncloud_pbi="owncloud-9.1.2-amd64.pbi"

	pbi_metatool add --app \
		-n "ownCloud" \
		-a "ownCloud" \
		-c "Web" \
		-d 'Owncloud is a system for the creation and management of personal cloud resources' \
		-i "${imgurl}/owncloud.png" \
		-k "net,www,web,cloud" \
		-l "GPL" \
		-t "Graphical" \
		-u "http://www.owncloud.org/" \
		"${metafile}"

	pbi_indextool add \
		-f "${plugins}/${owncloud_pbi}" \
		-u "/${owncloud_pbi}" \
		"${indexfile}"
}

add_plugin_plexmediaserver()
{
#	local plexmediaserver_pbi="plexmediaserver-0.9.11.7.803-amd64.pbi"
#	local plexmediaserver_pbi="plexmediaserver-0.9.11.16.958-amd64.pbi"
#	local plexmediaserver_pbi="plexmediaserver-0.9.12.0.1071-amd64.pbi"
#	local plexmediaserver_pbi="plexmediaserver-0.9.12.1.1079-amd64.pbi"
#	local plexmediaserver_pbi="plexmediaserver-0.9.12.3.1173-amd64.pbi"
#	local plexmediaserver_pbi="plexmediaserver-0.9.12.4.1192-amd64.pbi"
#	local plexmediaserver_pbi="plexmediaserver-0.9.12.8.1362-amd64.pbi"
#	local plexmediaserver_pbi="plexmediaserver-0.9.12.11.1406-amd64.pbi"
#	local plexmediaserver_pbi="plexmediaserver-0.9.12.13.1464-amd64.pbi"
#	local plexmediaserver_pbi="plexmediaserver-0.9.12.18.1520-amd64.pbi"
#	local plexmediaserver_pbi="plexmediaserver-0.9.12.19.1537-amd64.pbi"
#	local plexmediaserver_pbi="plexmediaserver-0.9.14.6.1620-amd64.pbi"
#	local plexmediaserver_pbi="plexmediaserver-0.9.15.2.1663-amd64.pbi"
#	local plexmediaserver_pbi="plexmediaserver-0.9.15.3.1674_3-amd64.pbi"
#	local plexmediaserver_pbi="plexmediaserver-0.9.15.6.1714-amd64.pbi"
#	local plexmediaserver_pbi="plexmediaserver-0.9.16.3.1840-amd64.pbi"
#	local plexmediaserver_pbi="plexmediaserver-0.9.16.4.1911-amd64.pbi"
#	local plexmediaserver_pbi="plexmediaserver-0.9.16.6.1993-amd64.pbi"
#	local plexmediaserver_pbi="plexmediaserver-1.0.0.2261-amd64.pbi"
#	local plexmediaserver_pbi="plexmediaserver-1.0.3.2461-amd64.pbi"
#	local plexmediaserver_pbi="plexmediaserver-1.1.3.2700-amd64.pbi"
#	local plexmediaserver_pbi="plexmediaserver-1.1.4.2757-amd64.pbi"
#	local plexmediaserver_pbi="plexmediaserver-1.2.7.2987-amd64.pbi"
#	local plexmediaserver_pbi="plexmediaserver-1.3.3.3148-amd64.pbi"
#	local plexmediaserver_pbi="plexmediaserver-1.3.4.3285-amd64.pbi"
#	local plexmediaserver_pbi="plexmediaserver-1.4.4.3495-amd64.pbi"
#	local plexmediaserver_pbi="plexmediaserver-1.5.5.3634-amd64.pbi"
#	local plexmediaserver_pbi="plexmediaserver-1.7.5.4035-amd64.pbi"
#	local plexmediaserver_pbi="plexmediaserver-1.8.1.4139-amd64.pbi"
#	local plexmediaserver_pbi="plexmediaserver-1.8.4.4249-amd64.pbi"
#	local plexmediaserver_pbi="plexmediaserver-1.9.2.4285-amd64.pbi"
#	local plexmediaserver_pbi="plexmediaserver-1.9.4.4325-amd64.pbi"
#	local plexmediaserver_pbi="plexmediaserver-1.9.6.4429-amd64.pbi"
#	local plexmediaserver_pbi="plexmediaserver-1.10.1.4602-amd64.pbi"
	local plexmediaserver_pbi="plexmediaserver-1.12.2.4929-amd64.pbi"

	pbi_metatool add --app \
		-n "PlexMediaServer" \
		-a "PLEX" \
		-c "Multimedia" \
		-d 'The Plex Media Server component' \
		-i "${imgurl}/plexmediaserver.png" \
		-k "media,music,movies,tv,dlna,upnp,av" \
		-l "GPL" \
		-t "Graphical" \
		-u "http://www.plexapp.com/" \
		"${metafile}"

	pbi_indextool add \
		-f "${plugins}/${plexmediaserver_pbi}" \
		-u "/${plexmediaserver_pbi}" \
		"${indexfile}"
}

add_plugin_resilio()
{
#	local resilio_pbi="resilio-2.4.1-amd64.pbi"
#	local resilio_pbi="resilio-2.4.2-amd64.pbi"
#	local resilio_pbi="resilio-2.4.4-amd64.pbi"
	local resilio_pbi="resilio-2.5.9-amd64.pbi"

	pbi_metatool add --app \
		-n "Resilio" \
		-a "Resilio, Inc." \
		-c 'Network - P2P' \
		-d 'Distributed peer-to-peer file syncing application' \
		-i "${imgurl}/resilio.png" \
		-k "net,p2p,share" \
		-l "Custom" \
		-t "Graphical" \
		-u "https://www.resilio.com/" \
		"${metafile}"

	pbi_indextool add \
		-f "${plugins}/${resilio_pbi}" \
		-u "/${resilio_pbi}" \
		"${indexfile}"
}

add_plugin_s3cmd()
{
	local s3cmd_pbi="s3cmd-1.0.1_1-amd64.pbi"

	pbi_metatool add --app \
		-n "s3cmd" \
		-a "iXsystems" \
		-c "Backup" \
		-d "A plugin which allows you to backup a dataset to Amazon's S3 service" \
		-i "${imgurl}/s3cmd.png" \
		-k "amazon,backup,replication" \
		-l "BSD" \
		-t "Graphical" \
		-u "https://www.dropbox.com/s/2prrmjlxuasuz34/s3cmd-1.0.1_1-amd64.pbi" \
		"${metafile}"

	pbi_indextool add \
		-f "${plugins}/${s3cmd_pbi}" \
		-u "/${s3cmd_pbi}" \
		"${indexfile}"
}

add_plugin_sabnzbd()
{
#	local sabnzbd_pbi="sabnzbd-0.7.20-amd64.pbi"
#	local sabnzbd_pbi="sabnzbd-1.0.0-amd64.pbi"
#	local sabnzbd_pbi="sabnzbd-1.0.1-amd64.pbi"
#	local sabnzbd_pbi="sabnzbd-1.0.2-amd64.pbi"
#	local sabnzbd_pbi="sabnzbd-1.0.3-amd64.pbi"
#	local sabnzbd_pbi="sabnzbd-1.1.0-amd64.pbi"
#	local sabnzbd_pbi="sabnzbd-1.1.1-amd64.pbi"
#	local sabnzbd_pbi="sabnzbd-1.2.0-amd64.pbi"
#	local sabnzbd_pbi="sabnzbd-1.2.1-amd64.pbi"
#	local sabnzbd_pbi="sabnzbd-1.2.3-amd64.pbi"
#	local sabnzbd_pbi="sabnzbd-2.0.0-amd64.pbi"
#	local sabnzbd_pbi="sabnzbd-2.2.0-amd64.pbi"
#	local sabnzbd_pbi="sabnzbd-2.2.1-amd64.pbi"
#	local sabnzbd_pbi="sabnzbd-2.3.0-amd64.pbi"
#	local sabnzbd_pbi="sabnzbd-2.3.1-amd64.pbi"
#	local sabnzbd_pbi="sabnzbd-2.3.2-amd64.pbi"
	local sabnzbd_pbi="sabnzbd-2.3.4-amd64.pbi"

	pbi_metatool add --app \
		-n "SABnzbd" \
		-a "SABnzbd" \
		-c "News" \
		-d 'Open Source Binary Newsreader' \
		-i "${imgurl}/sabnzbd.png" \
		-k "news,nzb" \
		-l "GPL" \
		-t "Graphical" \
		-u "http://sabnzbd.org/" \
		"${metafile}"

	pbi_indextool add \
		-f "${plugins}/${sabnzbd_pbi}" \
		-u "/${sabnzbd_pbi}" \
		"${indexfile}"
}

add_plugin_sickbeard()
{
#	local sickbeard_pbi="sickbeard-9.3.0-amd64.pbi"
	local sickbeard_pbi="sickbeard-9.3.1-amd64.pbi"

	pbi_metatool add --app \
		-n "SickBeard" \
		-a "SABnzbd Team" \
		-c "Multimedia" \
		-d ' PVR for newsgroup users' \
		-i "${imgurl}/sickbeard.png" \
		-k "media,movies,tv,av" \
		-l "GPLv3" \
		-t "Graphical" \
		-u "http://sickbeard.com/" \
		"${metafile}"

	pbi_indextool add \
		-f "${plugins}/${sickbeard_pbi}" \
		-u "/${sickbeard_pbi}" \
		"${indexfile}"
}

add_plugin_sickrage()
{
#	local sickrage_pbi="sickrage-9.3.1-amd64.pbi"
#	local sickrage_pbi="sickrage-9.3.2-amd64.pbi"
#	local sickrage_pbi="sickrage-9.3.3-amd64.pbi"
	local sickrage_pbi="sickrage-autoupdate.9_1-amd64.pbi"

	pbi_metatool add --app \
		-n "SickRage" \
		-a "SickRage" \
		-c "Multimedia" \
		-d 'Video File Manager for TV Shows' \
		-i "${imgurl}/sickrage.png" \
		-k "multimedia" \
		-l "GPL" \
		-t "Graphical" \
		-u "https://sickrage.github.io/" \
		"${metafile}"

	pbi_indextool add \
		-f "${plugins}/${sickrage_pbi}" \
		-u "/${sickrage_pbi}" \
		"${indexfile}"
}

add_plugin_sonarr()
{
#	local sonarr_pbi="sonarr-2.0.0.2850-amd64.pbi"
#	local sonarr_pbi="sonarr-2.0.0.3645_3-amd64.pbi"
	local sonarr_pbi="sonarr-2.0.0.3732-amd64.pbi"

	pbi_metatool add --app \
		-n "Sonarr" \
		-a "SONARR" \
		-c "Multimedia" \
		-d 'Smart PVR for newsgroup and bittorrent users.' \
		-i "${imgurl}/sonarr.png" \
		-k "multimedia" \
		-l "GPL" \
		-t "Graphical" \
		-u "https://sonarr.tv/" \
		"${metafile}"

	pbi_indextool add \
		-f "${plugins}/${sonarr_pbi}" \
		-u "/${sonarr_pbi}" \
		"${indexfile}"
}

add_plugin_subsonic()
{
#	local subsonic_pbi="subsonic-5.2.1-amd64.pbi"
#	local subsonic_pbi="subsonic-5.3-amd64.pbi"
#	local subsonic_pbi="subsonic-6.0-amd64.pbi"
#	local subsonic_pbi="subsonic-6.0_1-amd64.pbi"
	local subsonic_pbi="subsonic-6.0_2-amd64.pbi"

	pbi_metatool add --app \
		-n "Subsonic" \
		-a "SUBSONIC" \
		-c "Multimedia" \
		-d 'A free, web-based media streamer, providing ubiquitous access to your music.' \
		-i "${imgurl}/subsonic.png" \
		-k "media,music,movies,tv,dlna,upnp,av" \
		-l "GPL" \
		-t "Graphical" \
		-u "http://www.subsonic.org/pages/index.jsp" \
		"${metafile}" 

	pbi_indextool add \
		-f "${plugins}/${subsonic_pbi}" \
		-u "/${subsonic_pbi}" \
		"${indexfile}"
}

add_plugin_syncthing()
{
#	local syncthing_pbi="syncthing-0.10.30-amd64.pbi"
#	local syncthing_pbi="syncthing-0.11.1-amd64.pbi"
#	local syncthing_pbi="syncthing-0.11.2-amd64.pbi"
#	local syncthing_pbi="syncthing-0.11.3-amd64.pbi"
#	local syncthing_pbi="syncthing-0.11.5-amd64.pbi"
#	local syncthing_pbi="syncthing-0.11.6-amd64.pbi"
#	local syncthing_pbi="syncthing-0.11.7-amd64.pbi"
#	local syncthing_pbi="syncthing-0.11.8-amd64.pbi"
#	local syncthing_pbi="syncthing-0.11.9-amd64.pbi"
#	local syncthing_pbi="syncthing-0.11.10-amd64.pbi"
#	local syncthing_pbi="syncthing-0.11.11-amd64.pbi"
#	local syncthing_pbi="syncthing-0.12.2-amd64.pbi"
#	local syncthing_pbi="syncthing-0.13.7-amd64.pbi"
	local syncthing_pbi="syncthing-0.14.3-amd64.pbi"

	pbi_metatool add --app \
		-n "Syncthing" \
		-a "Syncthing" \
		-c "System Utilities" \
		-d 'Open Source Continuous Replication / Cluster Synchronization Thing' \
		-i "${imgurl}/syncthing.png" \
		-k "sync,replication" \
		-l "MIT" \
		-t "Graphical" \
		-u "http://www.syncthing.net/" \
		"${metafile}"

	pbi_indextool add \
		-f "${plugins}/${syncthing_pbi}" \
		-u "/${syncthing_pbi}" \
		"${indexfile}"
}

add_plugin_transmission()
{
#	local transmission_pbi="transmission-2.84_2-amd64.pbi"
#	local transmission_pbi="transmission-2.90-amd64.pbi"
#	local transmission_pbi="transmission-2.92-amd64.pbi"
	local transmission_pbi="transmission-2.93-amd64.pbi"

	pbi_metatool add --app \
		-n "Transmission" \
		-a "Transmission Daemon" \
		-c 'Network - P2P' \
		-d 'A lightweight, yet powerful BitTorrent client' \
		-i "${imgurl}/transmission.png" \
		-k "net,p2p,share" \
		-l "GPL" \
		-t "Graphical" \
		-u "http://www.transmissionbt.com/" \
		"${metafile}"

	pbi_indextool add \
		-f "${plugins}/${transmission_pbi}" \
		-u "/${transmission_pbi}" \
		"${indexfile}"
}

add_plugin_xdm()
{
#	local xdm_pbi="xdm-9.3.0-amd64.pbi"
	local xdm_pbi="xdm-9.3.1-amd64.pbi"

	pbi_metatool add --app \
		-n "XDM" \
		-a "XDM" \
		-c "Multimedia" \
		-d 'eXtendable Download Manager. Plugin based media collection manager.' \
		-i "${imgurl}/xdm.png" \
		-k "books,games,media,music,movies,tv,av" \
		-l "GPL" \
		-t "Graphical" \
		-u "http://xdm.lad1337.de/" \
		"${metafile}" 

	pbi_indextool add \
		-f "${plugins}/${xdm_pbi}" \
		-u "/${xdm_pbi}" \
		"${indexfile}"
}

add_plugin_xmrig()
{
#	local xmrig_pbi="xmrig-2.4.3-amd64.pbi"
#	local xmrig_pbi="xmrig-2.4.3_1-amd64.pbi"
#	local xmrig_pbi="xmrig-2.4.5-amd64.pbi"
#	local xmrig_pbi="xmrig-2.5.2-amd64.pbi"
#	local xmrig_pbi="xmrig-2.6.2-amd64.pbi"
	local xmrig_pbi="xmrig-2.8.1-amd64.pbi"

	pbi_metatool add --app \
		-n "XMRig" \
		-a "XMRig Miner" \
		-c "Network - P2P" \
		-d 'High performance Monero (XMR) CPU miner.' \
		-i "${imgurl}/xmrig.png" \
		-k "net,p2p" \
		-l "GPL" \
		-t "Graphical" \
		-u "https://github.com/xmrig/xmrig" \
		"${metafile}" 

	pbi_indextool add \
		-f "${plugins}/${xmrig_pbi}" \
		-u "/${xmrig_pbi}" \
		"${indexfile}"
}

add_plugins()
{
	set -x
	add_plugin_bacula
	add_plugin_couchpotato
	add_plugin_crashplan
	add_plugin_emby
	add_plugin_firefly
	add_plugin_headphones
	add_plugin_htpc_manager
	add_plugin_lazylibrarian
	add_plugin_madsonic
	add_plugin_maraschino
	add_plugin_mineos
	add_plugin_mylar
	add_plugin_nextcloud
	add_plugin_nzbhydra
	add_plugin_owncloud
	add_plugin_plexmediaserver
	add_plugin_resilio
	add_plugin_s3cmd
	add_plugin_sabnzbd
	add_plugin_sickbeard
	add_plugin_sickrage
	add_plugin_sonarr
	add_plugin_subsonic
	add_plugin_syncthing
	add_plugin_transmission
	add_plugin_xdm
	add_plugin_xmrig
	set +x
}

install_files()
{
	bzip2 "${metafile}"
	bzip2 "${indexfile}"

	mkdir -p "${metadir}"
	chmod 755 "${metadir}"

	cp "${metafile}.bz2" "${metadir}/"
	cp "${indexfile}.bz2" "${metadir}/"
	cp "${repofile}" "${metadir}/"

	chmod 644 "${metadir}/${metafile}.bz2"
	chmod 644 "${metadir}/${indexfile}.bz2"
	chmod 644 "${metadir}/${repofile}"

	chown www:www "${metadir}"
	chown www:www "${metadir}/${metafile}.bz2"
	chown www:www "${metadir}/${indexfile}.bz2"
	chown www:www "${metadir}/${repofile}"
}

main()
{
	cleanup_files
	add_plugins
	install_files
}


main $*
