#!/usr/bin/env bash

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

rm ../install-all # remove install file

#
# Install base Dependencies
#
if [ -f "/etc/arch-release" ]; then
    sudo pacman -S --needed --noconfirm boost cmake make lib32-openssl lib32-libpng gcc gdb lib32-sdl2 lib32-glew freetype2 rsync
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 libssl-dev:i386 libboost-all-dev libc6-dev:i386 gdb libsdl2-dev libglew-dev:i386 libglew-dev libfreetype6-dev libfreetype6-dev:i386 cmake libpng-dev libssl-dev cmake gcc-multilib g++-multilib -y
fi
#
# Update cathook
#

git fetch # fetch github repo for udpates
git pull origin # pull changes from github
git submodule update --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 ..
