Hey Atle,
I'm not even gonna touch your question because from a quick look, it's too confusing what you're trying to do.
Here's some suggestions, please pick on that suits to you:
Option 1 will install
system wide. If that's not what you want, then options 2 and 3 will install in
ANY folder you specify under
${HOME} with source code cloned from GitLab.
EDIT:
If you use
fpcupdeluxe and have installed
trunk, updating to the most recent state of
trunk is a button away.
If you want to install previous stable versions: Yeap, 1 button away and tucked in it's self contained folder. I have like 7 previous stable versions installed in my Ubuntu system

If you want to install cross-compilers, under
fpcupdeluxe, it's 2 radio buttons plus a button away.
This will make it so you don't have to roll out your own install scripts. Someone else has already done it for you

Hope this helps !!
Cheers,
Gus