#! /bin/sh

# Scan serial number
serial=$1
if [ x$1 = x"" ]; then
	echo -n "Please scan CERN serial number bar-code, then press [ENTER]: "
        read serial
fi

if [ x$serial = x"" ]; then
	echo -n "Serial numer cannot be empty!!"
        exit
fi

if [ -e ../serial.txt ]; then
    sudo rm -f ../serial.txt
fi

echo $serial >> ../serial.txt

# Load bitstream
sudo ./test00.py

# Read eeprom, dump to eeprom_content.out
sudo ./test26.py

# Backup eeprom content
cp eeprom_content.out ../eeprom_bkp/eeprom_$serial.bin

# Save calibration data
sudo sdb-read -e 0x200 eeprom_content.out calib > sdbfs/calib

# Re-write eeprom (new ipmi, saved calibration data)
sudo ./test46.py

# Check eeprom content validity
sudo ./test47.py

echo "--------------------------------------------------------------"
echo " "
echo -n "End of the test, do you want to switch the computer OFF? [y,n]"
read reply
if [ "$reply" = "y" ]
then
    sudo shutdown -h now
fi
