i=1
for lines in `cat ./boot/mark`
do
  case ${i} in
  1) var1=${lines};;
  esac
  i=`expr ${i} + 1`
done
#echo "$var1"

if test "$var1" = "0";then
sudo mkdir /etc/X11/xorg.conf.d
echo "1" > ./boot/mark
fi

if test "$1" = "0" -o "$#" = "0";then
sudo cp -rf ./etc/X11/xorg.conf.d/99-calibration.conf-32  /etc/X11/xorg.conf.d/99-calibration.conf
sudo cp ./boot/config-32.txt /boot/config.txt
echo "LCD configrue 0"
elif test "$1" = "90";then
sudo cp -rf ./etc/X11/xorg.conf.d/99-calibration.conf-32-90  /etc/X11/xorg.conf.d/99-calibration.conf
sudo cp ./boot/config-32.txt-90 /boot/config.txt
echo "LCD configrue 90"
elif test "$1" = "180";then
sudo cp -rf ./etc/X11/xorg.conf.d/99-calibration.conf-32-180  /etc/X11/xorg.conf.d/99-calibration.conf
sudo cp ./boot/config-32.txt-180 /boot/config.txt
echo "LCD configrue 180"
elif test "$1" = "270"; then
sudo cp -rf ./etc/X11/xorg.conf.d/99-calibration.conf-32-270  /etc/X11/xorg.conf.d/99-calibration.conf
sudo cp ./boot/config-32.txt-270 /boot/config.txt
echo "LCD configrue 270"
fi

sudo cp ./waveshare32b-overlay.dtb /boot/overlays/waveshare32b.dtbo
sudo cp ./waveshare32b-overlay.dtb /boot/overlays/
sudo cp -rf ./usr/share/X11/xorg.conf.d/99-fbturbo.conf  /usr/share/X11/xorg.conf.d/
sudo cp ./cmdline.txt /boot/
sudo cp ./inittab /etc/


if test "$#" = "0" -o "$1" = "0" -o "$1" = "90"  -o "$1" = "180" -o "$1" = "270"; then
sudo reboot
echo "reboot now"
else
echo "Invalid parameter,Usage:LCD32-show [0] [90] [180] [270]"
fi
