I often run into the situation where I would like to provide some kind of 'setup' or 'install' script, for something like a git repository, although it could also be used in other situations.
Just to be clear: with 'setup script' I mean a script which places some files, checks some things, creates certain dependencies and so on.
The problem is that if I want to use resources relative to the script or want to create links that target files in the repository I somehow need to be able to reference resources relative to the repository root or build absolute paths.
Currently I always go with this:
SCRIPT_DIR=$(cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd)
ROOT=$(realpath "$SCRIPT_DIR/..")
But this seems really bad, as it hard to understand and basically replicated in every repo or even file.
Is there a better way to do this? Are scripts like this unwanted?