Okay so I found a solution with the startup task mentioned by vanadium.
But I thought I would make it a bit more explicit.
I use 3 Files:
Two are located int the /home/ubuntu/
folder
/home/ubuntu/init.sh
And which contains
#!/bin/bash
gnome-terminal -- sudo '/home/ubuntu/script.sh'
/home/ubuntu/script.sh
which contains the actual code I want to execute
#!/bin/bash
sudo add-apt-repository -y ppa:maas/3.0-next
sudo apt update
sudo apt install -y maas jq markdown nmap traceroute git curl wget zfsutils-linux cloud-image-utils virtinst qemu-kvm libvirt-daemon-system libvirt-clients bridge-utils whois
sudo maas createadmin --username ubuntu --password password --email [email protected] --ssh-import gh:wt-b
...
And then We need to enable a startup application by putting a config file in the /etc/xdg/autostart
folder
3) /etc/xdg/autostart/conf.desktop
Which contains following infos:
[Desktop Entry]
Version=1.0
Name=LordofSpaghettis
Comment=Spaghettis are good
Exec=/home/ubuntu/init.sh
Path=/home/ubuntu/
Terminal=true
Type=Application
X-GNOME-Autostart-enabled=true
Categories=Utility;Development
Then when I restart the machineof logoff and login again, I get a prompt to ask the sudo password. And then everything works fine.
Thanks to vanadium for the help.