... The problem has never been editing bootsync.sh through an editor such as nano, it's just that using echo to 'inject' lines of text into it doesn't work, even when run as root. ...
nickjf20: The reason that
sudo echo SOME_TEXT > FILE_OWNED_BY_ROOT fails when run in a shell of a non-root user is that the 'echo SOME_TEXT' gets executed as 'root' but the output redirection is handled by the shell (of the non-root user), which causes the "problem" you've observed.
If you still wonder how to solve this little problem in the future I'd like to suggest the following:
echo SOME_TEXT | sudo tee FILE_OWNED_BY_ROOT > /dev/nulland when you want to append instead of overwriting just add the '-a' option to the 'tee' command. If you don't care about that 'SOME_TEXT' showing up as output somewhere you could also drop the output redirection (to '/dev/null').
An alternative suggestion would be to use
sudo sh -c "echo SOME_TEXT > FILE_OWNED_BY_ROOT", but that can become tricky if your command would be more complicated than a simple 'echo' and you need quoting inside the double quotes. Not a "biggie" if one pays attention to it, but I at least have now developed a preference for the solution with the 'tee'.