#!/bin/bash

find -type d | sort | while read folder ; do

    echo "${folder}"
    echo ""

    all=$(grep -rl "on /lib/live/mount/medium type" ${folder})
    total=$(grep -rl "on /lib/live/mount/medium type" ${folder} | wc -l)
    iso9960=$(grep -rl "^/dev/sr. on /lib/live/mount/medium type iso9660" ${all} | wc -l)
    qemu=$(grep -rl "^QEMU$" ${all} | wc -l)
    vbox=$(grep -rl "^VirtualBox$" ${all} | wc -l)
    vmware=$(grep -rl "^VMware Virtual Platform$" ${all} | wc -l)
    dvd=$(($iso9960-${qemu}-${vbox}-${vmware}))
    dd=$(grep -rl "^/dev/sd.. on /lib/live/mount/medium type iso9660" ${all} | wc -l)
    fat=$(grep -rl "^/dev/sd.. on /lib/live/mount/medium type vfat" ${all} | wc -l)
    ntfs=$(grep -rl "^/dev/sd.. on /lib/live/mount/medium type ntfs" ${all} | wc -l)
    persistence=$(grep -rl "^/dev/mapper/TailsData_unlocked on /live/persistence/TailsData_unlocked" ${all} | wc -l)
    fat=$((${fat}-${persistence}))
    toram=$(grep -rl "^/dev/shm on /lib/live/mount/medium type tmpfs" ${all} | wc -l)

    [ ${total} != '0' ] || continue

    echo "| dvd | ${dvd} | $((${dvd}*100/${total}))% |"
    echo "| dd  | ${dd} | $((${dd}*100/${total}))% |"
    echo "| usb+persist | ${persistence} | $((${persistence}*100/${total}))% |"
    echo "| usb-persist+fat | ${fat} | $((${fat}*100/${total}))% |"
    echo "| usb-persist+ntfs | ${ntfs} | $((${ntfs}*100/${total}))% |"
    echo "| toram | ${toram} | $((${toram}*100/${total}))% |"
    echo "| qemu | ${qemu} | $((${qemu}*100/${total}))% |"
    echo "| vbox | ${vbox} | $((${vbox}*100/${total}))% |"
    echo "| vmware | ${vmware} | $((${vmware}*100/${total}))% |"
    echo "| total | ${total} | |"

done
