#!/bin/sh


############# Packages to install ########################################

macos_homebrew_essentials="python3 vim-nox tmux nano zsh git autossh mosh sshuttle lynx npm tidy mcfly ack ncdu"
macos_homebrew_other_apps="calibre"
raspberrypi_essentials="python3 python3-pip vim-nox python3-venv tmux nano zsh git htop ncdu autossh mosh sshuttle fail2ban avahi-daemon ufw lynx npm ssmtp apticron tidy nmon software-properties-common ack restic unrar"
raspberrypi_printer="cups printer-driver-gutenprint"
raspberrypi_camera="python3-opencv"


############# Packages install functions #################################


install_python_linters() {
    pip3 install requests bs4 prospector black isort --break-system-packages
}

install_npm_linters() {
  npm install -g jsonlint
  npm install -g fixjson
}

############# MacOS exclusive commands ###################################

# Install homebrew
system_type=$(uname -s)

if [ "$system_type" = "Darwin" ]; then

  # install homebrew if it's missing
  if ! command -v brew >/dev/null 2>&1; then
    echo "Do you want to install homebrew? (y/n)"
    read -r install_homebrew
    if [[ $install_homebrew == "y" ]]; then
        echo "Installing homebrew"
        /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
    fi


  fi
fi

############# Raspberrypi exclusive commands #############################

if [ "$system_type" = "Linux" ]; then
  install_this_now=""

  echo "Do you want to install the most important packages ($raspberrypi_essentials)? (y/n)"
  read -r install_raspberrypi_essentials
  if [[ $install_raspberrypi_essentials == "y" ]]; then
      install_this_now="$install_this_now $raspberrypi_essentials"
  fi

  echo "Do you want to install the packages for printing? (y/n)"
  read -r install_raspberrypi_printer
  if [[ $install_raspberrypi_printer == "y" ]]; then
      install_this_now="$install_this_now $raspberrypi_printer"
  fi


  echo "Do you want to install the packages for the camera? (y/n)"
  read -r install_raspberrypi_camera
  if [[ $install_raspberrypi_camera == "y" ]]; then
      install_this_now="$install_this_now $raspberrypi_camera"
  fi


  if [[ -n "${install_this_now}" ]]; then
      echo "Packages will be installed now!"
      sudo apt update && sudo apt install $install_this_now

  fi
fi


if command -v ufw >/dev/null 2>&1; then
  echo "Do you want to enable the firewall (ufw with ssh allowed)? (y/n)"
  read -r enable_ufw
  if [[ $enable_ufw == "y" ]]; then
    ufw allow ssh
    ufw enable

  fi
fi



############# Commands for both ##########################################

if command -v /bin/zsh >/dev/null 2>&1; then
  echo "Do you want to set zsh as default shell? (y/n)"
  read -r set_default_shell
  if [[ $set_default_shell == "y" ]]; then
      chsh -s /bin/zsh
  fi
fi

echo "Do you want to install all linters for vim? (y/n)"
read -r install_linters
if [[ $install_linters == "y" ]]; then
    install_npm_linters
    install_python_linters
fi

