#!/usr/bin/env bash

if [ $EUID == 0 ]; then
    echo "This script must not be run as root"
    exit
fi

#
# Install base Dependencies
#
if [ -x "$(command -v pacman)" ]; then
    sudo pacman -S --needed --noconfirm boost cmake make gcc gdb lib32-sdl2 lib32-glew lib32-freetype2 rsync lib32-libglvnd
else
    sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y
    sudo apt update
    sudo apt install build-essential git gcc-multilib g++-multilib software-properties-common gcc-snapshot g++-7-multilib gcc-7 g++-7 libboost-all-dev libc6-dev:i386 gdb libsdl2-dev libglew-dev:i386 libglew-dev libfreetype6-dev libfreetype6-dev:i386 cmake gcc-multilib g++-multilib -y
fi
#
# Update cathook
#

git fetch --depth 1 origin && git reset --hard latest # pull changes from github
git submodule update --depth 1 --init --recursive # update/init submodules

#
# Build cathook
#

mkdir build;cd build #create a directory for building cathook
cmake ..;make -j$(grep -c '^processor' /proc/cpuinfo) # create makefile and build using all available threads
sudo make data # create /opt/cathook/data
cd ..; cd ..
