What you did is very close the only things I’d fix first are the apt-key flow because it is deprecated and you need to add set -euo pipefail because right now the script can fail in the middle without giving you a useful stop point.

Also init scripts run as root so sudo is not needed

If this answer resolves your question, could you please mark it as “Accept as Solution”? It will help other users quickly find the correct fix.

Senior BI/Data Engineer | Microsoft MVP Data Platform | Microsoft MVP Power BI | Power BI Super User | C# Corner MVP