#! /usr/bin/bash

set -e

apt-get install -y dotnet-sdk-8.0
apt-get install -y dotnet-runtime-8.0
apt-get install -y aspnetcore-runtime-8.0

#----------------------------------------------------------------------------
# Symlink to dotnet
#----------------------------------------------------------------------------
if [ -f /usr/share/dotnet/dotnet ]; then
    DOTNET_PATH=/usr/share/dotnet/dotnet
elif [ -f /usr/lib/dotnet/dotnet ]; then
    DOTNET_PATH=/usr/lib/dotnet/dotnet
else
    # Try environment PATH (Docker-friendly)
    DOTNET_PATH=$(command -v dotnet 2>/dev/null || true)
fi

# Create symlink if found
if [ -n "$DOTNET_PATH" ]; then
    ln -sf "$DOTNET_PATH" /usr/bin/dotnet
else
    echo "Dotnet executable not found. Symlink creation skipped."
fi

# Create a link to machine-id in case it does not exist
ln -sf /etc/machine-id /var/lib/dbus/machine-id

