It's very much trial-and-error. Yes, probably somebody has been down this path, and yes they may even have packaged it in a docker or git repo somehow but you said you wanted to
learn so I suggest that hunting for a wrapped solution to the problems is maybe less helpful than constructing your own model of how to fix them and
documenting it for others.
TL;DR -keep going. You're doing fine. Keep a diary (dated, sequenced - a lab book, a jupyter, a GIT repo of the constantly evolving install script) and write something as a final state (the README.md for the git?) which is less about time and more about the problems of significance and leave a trail or markers to how you fixed things.