This creates and runs
/root/boot.sh on boot (as root) using a minimal service file:
cat > $bootscript <<EOF
echo "$bootscript ran at $(date)!" > /tmp/it-works
chmod +x $bootscript
cat > /etc/systemd/system/$servicename.service <<EOF
systemctl enable $servicename
You can Ctrl+C this into a root terminal.
To modify the parameters, for example to use a different
$bootscript, set that variable manually and just skip that line when copying the commands.
After running the commands, you can edit the boot script using your favorite editor, and it will run on next boot. You can also immediately run it by using:
systemctl start $servicename
Every step could be done with sudo, but it is slightly more complicated, and some systems do not have sudo installed so some people would have to modify the example before use. Therefore I chose to not include sudo in the example.