#!/usr/bin/with-contenv bash

source /etc/lsb-release

if [ -f "/powershell/powershell.tar.gz" ]; then
    echo "Installing PowerShell"
    if [ "${DISTRIB_CODENAME}" == "bionic" ]; then
        echo "\
            libicu60 \
            libunwind8" >> /mod-repo-packages-to-install.list
    elif [ "${DISTRIB_CODENAME}" == "focal" ]; then
        echo "\
            libicu66 \
            libunwind8" >> /mod-repo-packages-to-install.list
    elif [ "${DISTRIB_CODENAME}" == "jammy" ]; then
        echo "\
            libicu70 \
            libunwind8" >> /mod-repo-packages-to-install.list
    elif [ "${DISTRIB_CODENAME}" == "noble" ]; then
        echo "\
            libicu74 \
            libunwind8" >> /mod-repo-packages-to-install.list
    fi
    tar xf "/powershell/powershell.tar.gz" -C /powershell
    rm -rf \
        /powershell/powershell.tar.gz
    ln -s /powershell/pwsh /usr/bin/pwsh
    chmod +x /powershell/pwsh
else
    echo "PowerShell already installed, skipping"
fi
