#!/bin/sh -e
###
# This script will install the dependencies for building Signet. It can be run
# as a normal user who has sudo or doas access, or as root.
###
arch="x86-64"
if [ "$1" != "" ]; then
	# pass in "i686" to build a 32-bit ELF
	arch="$1"
fi
os=`uname`
if [ "$os" = "Linux" ]; then
        me=`whoami`
        sudo=""
        if [ "$me" != "root" ]; then
                # We need to do a priv esc
                failed=0
                which sudo && sudo=`which sudo` || true
                which doas && sudo=`which doas` || true
                if [ -z "$sudo" ]; then
                        echo "Error: Not running as root and couldn't find sudo nor doas"
                        exit 1
                fi
        fi
        $sudo apt-get update
        $sudo apt-get install -y git build-essential qtbase5-dev qtchooser qt5-qmake libqt5websockets5-dev libqt5x11extras5 libqt5x11extras5-dev libgcrypt20-dev zlib1g-dev libx11-dev pkg-config libusb-1.0-0-dev libargon2-dev libbotan-2-dev libykpers-1-dev libpcsclite-dev cmake libqt5svg5-dev qttools5-dev libminizip-dev libkeyutils-dev libxtst-dev libqrencode-dev asciidoctor
	# To build the man page, we'll also need pandoc
	$sudo apt-get install -y pandoc

	if [ "$arch" = "i686" ]; then
		# If compiling for 32-bit Linux we need to do some more
		$sudo apt-get install -y gcc-multilib g++-multilib
		$sudo dpkg --add-architecture i386
		$sudo apt-get update
		$sudo apt-get install -y libgpg-error-dev:i386 libgcrypt20-dev:i386 libx11-dev:i386 qtbase5-dev:i386 libqt5x11extras5-dev:i386 libqt5x11extras5:i386 libqt5websockets5-dev:i386 libusb-1.0-0-dev:i386 zlib1g-dev:i386 libbotan-2-dev:i386 libargon2-dev:i386
	fi
else
        echo "Platform not yet implemented"
fi
