#!/bin/bash
if ! cat /proc/cpuinfo | grep Model | sed 's/Model.*: //g' | grep -q 'Raspberry Pi' ;then
  error "User error: CommanderPi can only be installed on Raspberry Pi devices. Your device is: $(cat /proc/cpuinfo | grep Model | sed 's/Model.*: //g')"
fi

rm -rf ~/CommanderPi &>/dev/null || sudo rm -rf ~/CommanderPi || error "Failed to remove CommanderPi folder!"

# Get dependencies
install_packages python3 python3-psutil python3-tk python3-pil python3-pil.imagetk || exit 1
git_clone https://github.com/Jack477/CommanderPi || error "failed to download repository!"
cd CommanderPi || error "failed to enter repository!"
# make sure start.sh is executable
chmod +x src/start.sh

#make desktop file
mkdir -p ~/Desktop
sudo python3 c_desktop.py $USER || error "Could not install commanderpi!"
sudo chown $USER:$USER ~/Desktop/commanderpi.desktop
chmod +x ~/Desktop/commanderpi.desktop
