#!/bin/bash -e

echo "Setting Attributes for script"
chmod +x apps/pong.py
chmod +x apps/strobo.py
chmod +x apps/example.py
chmod +x apps/youtubedl.sh
chmod +x apps/lines.py


echo "Building c/c++ apps"
mkdir -p build/c
pushd build/c
cmake ../../apps/c-src
make
popd
mv -f build/c/fbcp apps/
mv -f  build/c/flicker apps/
mv -f  build/c/pixelflut apps/

if hash cargo 2>/dev/null; then
    echo "Building juergen/pixelfoo"
    # get juergens apps
    mkdir -p external
    pushd external
    if [ ! -d "pixelfoo-apps" ]; then
        git clone https://git.chaospott.de/starblue/pixelfoo-apps
    fi
    pushd pixelfoo-apps
    git pull
    cargo build --release
    popd
    popd

    apps="\
        alien-message \
        bimood \
        bitart \
        cnoise \
        colorcode \
        dualmaze \
        life \
        lorenz \
        matrix-code \
        maze \
        phase-change \
        phase-change2 \
        predprey \
        primes \
        thiele \
        "
    for app in ${apps}
    do
        cp -vf external/pixelfoo-apps/target/release/${app} apps/
    done
fi

#echo "Getting mathpixel"
#mkdir -p external
#pushd external
#if [ ! -d "mathpixel" ]; then
#    git clone https://git.chaospott.de/andreas/mathpixel.git
#fi
#pushd mathpixel
#git pull
#bash setup.sh
#popd
#popd

echo "Getting pixelthud"
mkdir -p external
pushd external
if [ ! -d "pixelthud" ]; then
    git clone https://git.chaospott.de/m11/pixelthud.git
fi
pushd pixelthud
git pull
bash setup.sh
popd
popd

echo "Setup done"
