With an eye towards the eventual removal of this code, we call the
divert and undivert functions with the canonicalized paths and derive
the aliased path from the canonicalized one instead of doing the
reverse. This isolates the code to be removed to two functions and can
be performed by the janitor.
Remove upstart-specific diversions, because upstart has been removed
since at least bullseye.
Document why we are doing this and add a reference to DEP17.
start-stop-daemon and initctl have recently moved to /usr. As
chroot-setup.sh diverts the original locations, the diversion does not
match and thus the rename is skipped. Then the affected files are
overwritten and when they are undiverted, nothing can be moved back.
Therefore, these files may go missing. This has been observed in Kali
recently, but it also affects Debian.
This now unmounts /media if it was mounted, before returning, and it
only tries to mount something when the file path starts with '/media/' which
will ensure that it doesn't bother for '/preseed.cfg'.
Perhaps that test should instead look for '/preseed.cfg' and attempt
mountmedia for anything else.