#!/bin/bash

# update/upgrade
echo "-------------------------------------------------------------"
echo "UPDATE"
echo "-------------------------------------------------------------"
apt-get update

echo "-------------------------------------------------------------"
echo "UPGRADE"
echo "-------------------------------------------------------------"
apt-get -y upgrade

sync

# install required libraries and tools
echo "-------------------------------------------------------------"
echo "INSTALL: openssl libgnutls28-dev libgnutlsxx28 libssl1.1 libssl1.0-dev libcurl3 libcurl3-gnutls libcurl4-gnutls-dev libcrypto++-dev libcrypto++-utils libcrypto++6 libgpg-error-dev automake texinfo g++ libjson-c-dev libjsoncpp-dev git"
echo "-------------------------------------------------------------"
apt-get -y install openssl libgnutls28-dev libgnutlsxx28 libssl1.1 libssl1.0-dev \
                        libcurl3 libcurl3-gnutls libcurl4-gnutls-dev libcrypto++-dev \
                        libcrypto++-utils libcrypto++6 libgpg-error-dev automake texinfo g++ \
                        libjson-c-dev libjsoncpp-dev git

sync

# instal libmicrohttpd-0.9.59
echo "-------------------------------------------------------------"
echo "INSTALL: libmicrohttpd-0.9.59"
echo "-------------------------------------------------------------"

# get the package
if [ -f libmicrohttpd-0.9.59.tar.gz ]; then
  rm libmicrohttpd-0.9.59.tar.gz
  sync
fi
wget https://ftp.gnu.org/gnu/libmicrohttpd/libmicrohttpd-0.9.59.tar.gz
sync

# remove previous
if [ -d libmicrohttpd-0.9.59 ]; then
  rm -rf libmicrohttpd-0.9.59
  sync
fi

# unpack
tar -xvzf libmicrohttpd-0.9.59.tar.gz
sync

START_DIR=`pwd`

# configure
cd libmicrohttpd-0.9.59
./configure --with-gnutls
sync

# make
make
sync
make install
sync

# set link
cd /usr/lib
echo "ln -sf /usr/local/lib/libmicrohttpd.so.12.46.0 libmicrohttpd.so.12"
ln -sf /usr/local/lib/libmicrohttpd.so.12.46.0 libmicrohttpd.so.12
sync
cd $START_DIR

