#!/bin/bash

arch=$1
toolchain=$2

export DEBIAN_FRONTEND=noninteractive

find "/etc/apt/sources.list.d/" -type f -exec sed -i "s|http://[a-zA-Z0-9_.]\+/|http://mirror.yandex.ru/|g" {} \;

dpkg --add-architecture $arch
apt-get update

# locales
apt-get install -y locales apt-utils
localedef -i en_US -c -f UTF-8 -A /usr/share/locale/locale.alias en_US.UTF-8

TZ=Europe/Moscow
ln -snf /usr/share/zoneinfo/$TZ /etc/localtime
echo $TZ > /etc/timezone

# base soft
apt-get install -y \
"^libxcb.*" \
bison \
ccache \
cpio \
curl \
debconf \
debhelper \
default-libmysqlclient-dev \
doxygen \
dpkg \
flex \
g++ \
git \
gperf \
graphviz \
htop \
iputils-ping \
libbz2-dev \
libffi-dev \
libfontconfig1-dev \
libfreetype6-dev \
libgl1-mesa-dev \
libglew-dev \
libglu1-mesa-dev \
libgmp-dev \
libicu-dev \
liblzma-dev \
libmpc-dev \
libmpfr-dev \
libncurses-dev \
libpkgconfig-perl \
libpq-dev \
libreadline-dev \
libssl-dev \
libusb-1.0-0-dev \
libwayland-dev \
libx11-dev \
libx11-xcb-dev \
libxkbcommon-dev \
libxkbcommon-x11-dev \
libxml2-dev \
libxrender-dev \
lsb-release \
mc \
md5deep \
nano \
net-tools \
ninja-build \
ocl-icd-opencl-dev \
p7zip-full \
patchelf \
python3 \
screen \
subversion \
unzip \
wget \
zip \
zlib1g-dev \


apt-get install -y \
qtmultimedia5-dev:$arch \
qtbase5-private-dev:$arch \
qttools5-private-dev:$arch \
qtbase5-dev-tools \


apt-get install -y \
$toolchain \
libbz2-dev:$arch \
libffi-dev:$arch \
libfontconfig1-dev:$arch \
libfreetype6-dev:$arch \
libfftw3-dev:$arch \
libgl1-mesa-dev:$arch \
libglew-dev:$arch \
libglu1-mesa-dev:$arch \
libgmp-dev:$arch \
libicu-dev:$arch \
liblzma-dev:$arch \
libmpc-dev:$arch \
libmpfr-dev:$arch \
libncurses-dev:$arch \
libpq-dev:$arch \
libreadline-dev:$arch \
libssl-dev:$arch \
libusb-1.0-0-dev:$arch \
libwayland-dev:$arch \
libx11-dev:$arch \
libx11-xcb-dev:$arch \
libxkbcommon-dev:$arch \
libxkbcommon-x11-dev:$arch \
libxml2-dev:$arch \
libxrender-dev:$arch \
ocl-icd-opencl-dev:$arch \
libsodium-dev:$arch \
libassimp-dev:$arch \
libmicrohttpd-dev:$arch \
libhdf5-dev:$arch \
libcurl4-openssl-dev:$arch \
libpcsclite-dev:$arch \
qtconnectivity5-dev:$arch \
qtbase5-dev:$arch \
qttools5-dev:$arch \
qtscript5-dev:$arch \
qtdeclarative5-dev:$arch \
qtpositioning5-dev:$arch \
libqt5datavisualization5-dev:$arch \
libqt5networkauth5-dev:$arch \
libqt5opengl5-dev:$arch \
qtscript5-dev:$arch \
libqt5serialport5-dev:$arch \
libqt5serialbus5-dev:$arch \
libqt5sensors5-dev:$arch \
libqt5svg5-dev:$arch \
libqt5websockets5-dev:$arch \
libqt5x11extras5-dev:$arch \
libqt5xmlpatterns5-dev:$arch \
libqt5charts5-dev:$arch \


apt-get install -y lzma-dev || true
apt-get install -y python3-future || true
apt-get install -y python3-click || true
apt-get install -y python3-cryptography || true
apt-get install -y python3-pip || true
apt-get install -y python3-pyelftools || true
apt-get install -y python3-pyparsing || true
apt-get install -y python3-serial || true
apt-get install -y python3-setuptools || true

apt-get install -y libopencv-dev:$arch

# cleanup
rm -rf /var/cache/apt/archives/*
