#!/mod/bin/jimsh

source /mod/webif/lib/setup
require system.class pretty_size

lassign [system diskspace 1] size used perc free fperc tsrbuf tsrused

# Calculate the TSR reserve
set tsrreserve $($tsrbuf - $tsrused)
# Adjust values to account for the TSR reserve
set free $($free - $tsrreserve)
set used $($size - $free)
set fperc $($free * 100 / $size)
set perc $(100 - $fperc)

set dsindex $($perc * 25 / 100 + 1)
if {$dsindex > 25} { set dsindex 25 }
set dsfile [format "%02d" $dsindex]

# The HD model only has the USB images which are blue. I prefer the green
# one so use those if available.
if {[file exists /opt/share/images/blue/345_2_14_ST_HDD_01.png]} {
	set prefix 345_2_14_ST_HDD
} else {
	set prefix 345_1_27_ST_USB
}

puts "
	<span id=tbdiskpie style=\"float: right; 
	    background:url('/images/345_1_27_ST_USB_BG.png')
	    no-repeat\">
		<a href=/diag/dspace/index.jim>
		  <img border=0 src=/images/${prefix}_$dsfile.png>
		</a>
	</span>

	<span id=tbdiskspace>
		Total space: [pretty_size $size]<br>
		Used: [pretty_size $used] ($perc%)<br>
		Free: [pretty_size $free] ($fperc%)
"
if {[system pkginst undelete]} {
	set dbs [system dustbinsize]
	puts "<br>Dustbin: [pretty_size $dbs]"
}
puts "
	</span>
"

