is_Raspberry=$(cat /proc/device-tree/model | awk  '{print $1}')
if [ "x${is_Raspberry}" != "xRaspberry" ] ; then
  echo "This script contains drivers for the Raspberry pi and will not work on the current platform."
  exit 1
fi

# sudo apt update
# sudo apt -y install git vim zsh mplayer
update_system() {
  echo "Updating system"
  sudo apt update
  sudo apt dist-upgrade
  sudo apt upgrade
}

install_volta() {
  echo "Installing node@latest via volta"
  sh -c "wget -qO- https://get.volta.sh | bash"
  exec $SHELL
  volta install node@latest
}

install_screen() {
  echo "Installing screen program"
  cd portal
  npm install
  npx prisma generate && npx prisma db push && npx prisma db seed
}

install_sound_card_drivers() {
  echo "Installing sound card drivers"
  git clone https://github.com/waveshare/WM8960-Audio-HAT
  cd WM8960-Audio-HAT
  sudo ./install.sh
}

setup_daemons() {
  echo "Setting up daemons"
  sudo cp ./screen.service /lib/systemd/system/
  sudo cp ./player.service /lib/systemd/system/
  systemctl daemon-reload
  systemctl enable player
  systemctl enable screen
  systemctl enable wm8960-soundcard.service
  systemctl start player
  systemctl start screen
  systemctl start wm8960-soundcard
}

install_ohmyzsh() {
  echo "Installing oh my zsh"
  sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
  echo TERM=xterm > ~/.zshrc
}


install_all() {
  update_system
  install_volta
  install_screen
 # install_sound_card_drivers
 # setup_daemons
 # install_ohmyzsh
 # sudo reboot
}

install_all

echo "------------------------------------------------------"
echo "The Black Portal listening device has been setup."
echo "This raspberry pi now rebooting in order to apply changes"
echo "------------------------------------------------------"