#!/bin/bash

NEEDS=""
rm -r ~/.Bundle_Store
mkdir ~/.Bundle_Store
cd ~/.Bundle_Store

wget https://bundlestoreclient.nebisoftware.com/app-database/NebiOS_Update.ninf
if [ "$(cat ./NebiOS_Update.ninf | grep "Version=" | sed 's+Version=++g' | sed 's+\"++g')" != "$(lsb_release -rs)" ]; then
	notify-send --icon /Applications/.Bundle_Store.napp.png --app-name "Bundle Store" "New System Update" "NebiOS $(cat ./NebiOS_Update.ninf | grep "Version=" | sed 's+Version=++g' | sed 's+\"++g') now available."
fi

for i in $(ls /Applications/ | grep -v -e "NebiOS_Update.napp" -e "Bundle_Store.napp" -e "Hardware_Info_and_Drivers.napp" -e "NebiAshley.napp" -e "NebiChat.napp" | grep .napp); do
	APP_VERSION="$(/Applications/$i --lsm | grep "Version=" | sed 's+Version=++g' | sed 's+\"++g' )"
	wget https://bundlestoreclient.nebisoftware.com/app-database/$(echo $i | sed "s+\.napp+\.ninf+g")
	if [ "$(cat ./$(echo $i | sed "s+\.napp+\.ninf+g") | grep "Version=" | sed 's+Version=++g' | sed 's+\"++g')" != "$APP_VERSION" ]; then
		NEEDS="$i|$NEEDS"
	fi
done
COUNT=0
for c in $(echo $NEEDS | sed "s+|+\n+g"); do
	COUNT=$(($COUNT + 1))
done
COUNT=$(($COUNT - 4))
if (( $COUNT > 0 )); then
	notify-send --icon /Applications/.Bundle_Store.napp.png --app-name "Bundle Store" "Updates" "Update available for $COUNT apps."
fi
