# Script that installs Qt runtime on ARM
# Daniel NG, maximatecc

#!/bin/bash
VERSION=5.6.3
INSTALLATION_SUCCESS=0
NR_FILES=889

echo "Installing Qt5 for ARM runtime $VERSION on CCpilot"
echo -ne "Extracting archive... "
sudo tar -xf "Qt-${VERSION}_ARM_VA.tar.gz" -C / &
pid=$! # Process Id of the previous running command

spin='-\|/'

i=0
while kill -0 $pid 2>/dev/null
do
  i=$(( (i+1) %4 ))
  printf "\rExtracting archive... ${spin:$i:1}"
  sleep .1
done

printf "\rExtracting archive...  \n"

# Check that installation is succesful

nr_installed_files=$(ls -R1 /opt/Qt-"$VERSION" | wc -l)
if [ "$nr_installed_files" -lt "$NR_FILES" ]; then
	echo "Found $nr_installed_files nr of files, expected $NR_FILES"
	echo "Installation aborted"
        INSTALLATION_SUCCESS=1
	exit $INSTALLATION_SUCCESS
fi

ldconfig -C /opt/etc/ld.so.cache

# Create a stamp to indicate installed package
if [ ! -d /opt/packages ]; then
	mkdir /opt/packages
fi
touch /opt/packages/Qt5_ARM_VA_runtime_5.6.3_#14

echo "Installation of Qt5 for ARM runtime $VERSION on CCpilot successful."

exit $INSTALLATION_SUCCESS
