#!/bin/bash

#
# NAME
#	resource/htmlList
#
# SYNOPSIS
#	curl http://ip_address/cgi-bin/sdk/resource/htmlList
#
# DESCRIPTION
#	This HTTP API function returns a list of currently loaded resources in an HTML formatted
#	page with imbedded HTML hypertext links to allow the user to select a resource to free up.
#
# VERSION
#	V1.0	2016-12-13	Initial release.
#
save_IFS=$IFS
IFS=$'\n'

echo "Content-type: text/plain"
echo ""

echo "Click on a resource to free it from memory (don't worry, it will be reloaded on the next reboot)<br>"
echo "type=Background"
echo "<ul>"
curl -s "http://127.0.0.1/cgi-bin/platform/resource?function=list&type=Background" -o /tmp/resource.txt
for line in `cat /tmp/resource.txt | grep "name="`; do
  name=`echo $line | sed 's/name=//' | sed "s/'//g" | awk '{ print $2 }'`
  echo "  <li><a href=\"javascript:resourceFree_2('$name','Background');\">$name</a>"
done
echo "</ul>"

echo "type=keyboard"
echo "<ul>"
curl -s "http://127.0.0.1/cgi-bin/platform/resource?function=list&type=keyboard" -o /tmp/resource.txt
for line in `cat /tmp/resource.txt | grep "name="`; do
  name=`echo $line | sed 's/name=//' | sed "s/'//g" | awk '{ print $2 }'`
  echo "  <li><a href=\"javascript:resourceFree_2('$name','keyboard');\">$name</a>"
done
echo "</ul>"
IFS=$save_IFS
