#!/bin/bash
cat /dev/location > /dev/null &
    apk add --update --no-cache \
        bash \
        libsodium \
        protobuf-dev \
        boost-dev \
        build-base \
        cmake \
        git \
        gflags-dev \
        libexecinfo \
        libsodium-dev \
        libutempter-dev \
        m4 \
        perl \
        protobuf-dev
    git clone --recurse-submodules https://github.com/MisterTea/EternalTerminal.git /tmp/EternalTerminal

    # Patches to make it work for alpine
    sed -i 's/-DELPP_FEATURE_CRASH_LOG//g' /tmp/EternalTerminal/CMakeLists.txt
    sed -i '/UniversalStacktrace/d' /tmp/EternalTerminal/CMakeLists.txt
    sed -i '/#include "ust.hpp"/d' /tmp/EternalTerminal/src/base/Headers.hpp
    sed -i 's/<< "Stack Trace: " << endl << ust::generate()//g' /tmp/EternalTerminal/src/base/Headers.hpp
    sed -i 's/NULL))/(char *)0))/g' /tmp/EternalTerminal/src/terminal/PsuedoUserTerminal.hpp
    sed -i 's/--login", NULL/--login", (char *)0/g' /tmp/EternalTerminal/src/htm/TerminalHandler.cpp
    # Build
    cd /tmp/EternalTerminal
    mkdir build
    cd build
    cmake ../
    make
    make install
