#!/bin/bash
# Get dependencies
install_packages build-essential qmlscene qt5-qmake qtbase5-dev qtchooser qtdeclarative5-dev qtquickcontrols2-5-dev \
  libqt5svg5 \
  qml-module-qtquick-controls qml-module-qtquick-controls2 qml-module-qt-labs-platform qml-module-qtgraphicaleffects \
  qml-module-qtquick-dialogs qml-module-qtquick-localstorage qml-module-qtquick-window2 qml-module-qt-labs-settings \
  qml-module-qt-labs-folderlistmodel || error "Failed to install dependencies"
# install qt5-default if its availabe in apt (necessary on debian/ubuntu versions prior to bullseye/hirsute)

if package_available qt5-default ; then
  install_packages qt5-default || error "Failed to install dependencies"
fi

# Get CRT version qt5 from github
git_clone --recursive -b qt5 https://github.com/Swordfish90/cool-retro-term || error "failed to clone repository!"
# Compile
cd cool-retro-term || error "failed on cd step!"
qmake || error "failed on qmake step!"
make -j8 || error "failed on make step!"
sudo make install || error "failed to sudo make install!"
cd ..
rm -rf ./cool-retro-term

#refresh icon caches
sudo update-icon-caches /usr/share/icons/*
sudo xdg-icon-resource forceupdate --mode system
