#!/bin/sh

config="/var/etc/PlugLoad.cfg"

if [ "$1" == "py" ]; then
 while read i; do
  l=${#i}
  if [ $l -eq 0 ]; then continue; fi
  status=${i:$(($l-1)):1}
  if [ "$status" = "2" ]; then
   plug=${i:0:$(($l-2))}
   if [ -d "$plug" ]; then /bin/umount -lf $plug 2>/dev/null; fi
  fi
 done < $config
fi

if [ "$1" != "py" ]; then
 while read i; do
  l=${#i}
  if [ $l -eq 0 ]; then continue; fi
  status=${i:$(($l-1)):1}
  if [ "$status" = "0" -o "$status" = "2" ]; then
   plug=${i:0:$(($l-2))}
   if [ -d "$plug" ]; then /bin/mount -t tmpfs -o size=1K tmpfs "$plug" 2>/dev/null; fi
  fi
 done < $config
fi
