#SD Route
printf "Running subsystem test 9: SD slot 2...\n"  | tee -a log.txt
printf "Please remove the previously inserted SD card and insert an SD card into the slot closest to the edge of the board and press ENTER...\n"
read
if [ ! -b $sd1 ]
then
    if [ ! -b $sd2 ]
    then
	printf "Error: Unable to access SD card\n" | tee -a log.txt
    else
	printf "Found SD card\n" | tee -a log.txt
	printf "Testing write and read...\n" | tee -a log.txt
	sleep 1
	mkdir sd-route 2>/dev/null
	mount $sd2 sd-route
	cp testfile sd-route/testfile
	sync
	rm newfile 2>/dev/null 
	sync
	cp sd-route/testfile newfile
	sync
	checksum1=$(md5sum newfile | awk '{print $1}')
	checksum2=$(md5sum testfile| awk '{print $1}')
	if [ $checksum1 = $checksum2 ]
	then 
	    printf "Test file CRC correct\n" | tee -a log.txt
	    printf "SD slot 2 test successful\n" | tee -a log.txt
	else 
	    printf "CRC failure\n" | tee -a log.txt
	fi
    fi
else
    printf "Found SD card\n" | tee -a log.txt
    printf "Testing write and read...\n" | tee -a log.txt
    sleep 1
    mkdir sd-route 2>/dev/null
    mount $sd1 sd-route
    cp testfile sd-route/testfile
    sync
    rm newfile 2>/dev/null 
    sync
    cp sd-route/testfile newfile
    sync
    checksum1=$(md5sum newfile | awk '{print $1}')
    checksum2=$(md5sum testfile| awk '{print $1}')
    
    if [ $checksum1 = $checksum2 ]
    then
	printf "Test file CRC correct\n" | tee -a log.txt
	printf "SD slot 2 test successful\n" | tee -a log.txt
    else 
	printf "CRC failure\n" | tee -a log.txt
    fi
fi
umount sd-route 2>/dev/null
rm -rf sd-route 2>/dev/null
sleep 1
printf "Press ENTER to continue..."
read
printf "\n\n" | tee -a log.txt

