#!/bin/bash

ARRAY_TOTAL=$(df -BG /mnt/user | awk 'NR==2 {print $2}')
ARRAY_USED=$(df -BG /mnt/user | awk 'NR==2 {print $3}')
ARRAY_FREE=$(df -BG /mnt/user | awk 'NR==2 {print $4}')
ARRAY_PCT=$(df -h /mnt/user | awk 'NR==2 {print $5}')

CACHE_TOTAL=$(df -BG /mnt/cache 2>/dev/null | awk 'NR==2 {print $2}')
CACHE_USED=$(df -BG /mnt/cache 2>/dev/null | awk 'NR==2 {print $3}')
CACHE_FREE=$(df -BG /mnt/cache 2>/dev/null | awk 'NR==2 {print $4}')
CACHE_PCT=$(df -h /mnt/cache 2>/dev/null | awk 'NR==2 {print $5}')

cat > /mnt/user/appdata/homepage/unraid-storage.json <<EOF
{
  "array_total": "$ARRAY_TOTAL",
  "array_used": "$ARRAY_USED",
  "array_free": "$ARRAY_FREE",
  "array_percent": "$ARRAY_PCT",
  "cache_total": "$CACHE_TOTAL",
  "cache_used": "$CACHE_USED",
  "cache_free": "$CACHE_FREE",
  "cache_percent": "$CACHE_PCT"
}
EOF
