tiny-pilot / tinypilot

Use your Raspberry Pi as a browser-based KVM.
https://tinypilotkvm.com
MIT License
3.05k stars 255 forks source link

Resolve tinypilot home dir independent from $HOME #1572

Closed jotaen4tinypilot closed 1 year ago

jotaen4tinypilot commented 1 year ago

Resolves https://github.com/tiny-pilot/tinypilot/issues/1571.

There are several places in the app where we rely on the ~ path shortcut, or the $HOME environment variable respectively. (For example when processing the settings.yml file.) However, there are scenarios where the app (or parts of it) are run under a different user, e.g. root, or with sudo, in which case ~ would erroneously resolve to /root instead of /home/tinypilot.

This PR makes sure that the app always uses /home/tinypilot for accessing TinyPilot-specific objects, independent of what the $HOME environment variable contains. TinyPilot-specific objects are:

I suggest that we don’t just hard-code the /home/tinypilot path as is, because that would make local development more inconvenient – you always would need to initialize and switch to a tinypilot user before being able to start developing. Therefore, I introduced a new environment variable (TINYPILOT_HOME_DIR), that lets us overrride the /home/tinypilot default. Unfortunately, we cannot put this variable into dev_app_settings.cfg, since the app config can only be read during a Flask request execution context, but not at initialization time (at least not in a “clean” way). To me, the env.abs_path_in_home_dir helper function (as proposed here) wouldn’t be too bad either, though. Review on CodeApprove