#!/bin/sh
#
# chkfixed - look for legitimate parititions and build mount points
# and populate /etc/proc
#

rm /tmp/partitions 2> /dev/null


[ -d /etc/proc ] || mkdir /etc/proc

if [ -f /etc/tux/config/fstab ] 
then
	echo "fstab found, exiting..."
	exit 1
fi

for i in `grep -v nodev /proc/filesystems`
do
	echo "$i"
done > /etc/proc/availfs

echo "The following filesystems are supported:"
cat /etc/proc/availfs
echo

cdpart=`dmesg | grep D-ROM | grep hd | cut -d: -f1`

if [ "$cdpart" ] 
then
	echo "A CD-ROM was found at $cdpart"
	echo "$cdpart" > /tmp/partitions
fi

partitions=`dmesg | grep ' hd' | cut -d':' -f2`


for i in $partitions
do

	if  echo "$partitions"  | grep unknown > /dev/null
	then
		echo "Unkown partition"
	else
		echo $i >> /tmp/partitions 
	fi
done

sort /tmp/partitions | uniq > /etc/proc/partitions

 echo "The following partitions were found: "
cat /etc/proc/partitions
echo

##echo "The following filesystems were found: "
for i in `cat /etc/proc/partitions`
do
	mkdir /$i 2> /dev/null

	for j in `cat /etc/proc/availfs`
	do
		echo -n Checking $i:
		if mount -o ro -t $j /dev/$i /$i  2> /dev/null > /dev/null
		then
			echo " found $j"
			echo "$i:$j" >> /etc/tux/config/fstab
			umount /dev/$i 2> /dev/null > /dev/null
		else
			echo
		fi
	done
done
