#!/bin/bash
# Copyright (c)2021 SUSE LLC
# MIT license
set -e -x

id
echo "HOME is $HOME"

# This is supposed to run in a container, making sure we're not root
: ${MYUSER=myuser}
if [ $(id -u -n) != "$MYUSER" ]; then
    useradd -m "$MYUSER"
    chown -R "$MYUSER": .
    exec su "$MYUSER" "$0" "$@"
fi

# Test that installing as non-root works
# $1 subdir containing CMakeLists.txt
build_and_install() {
    pushd "$1"

    mkdir -p build
    cd build
    cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=$HOME/pfx ../
    make -j$(nproc)
    make install

    popd
}

build_and_install "libyui"
build_and_install "libyui-qt"
build_and_install "libyui-qt-graph"
build_and_install "libyui-qt-pkg"
build_and_install "libyui-ncurses"
build_and_install "libyui-ncurses-pkg"
build_and_install "libyui-rest-api"
build_and_install "libyui-qt-rest-api"
build_and_install "libyui-ncurses-rest-api"
build_and_install "libyui-bindings"
