I have updated script to compile BETA version of domoticz.
All credits to Barmalej2 nevertheless. I have changes source to BETA by performing git pull and removing downloading stable version and added lines with missing linking.
Prerequisites:
- Installation of old version of domoticz via slapt-get to get all dependencies.
- Installation of git repository.

Well, first thing that draw my attention looking at your script is the complete mess with indents. As of consequence of this, some commands including heredoc might fail. It would better to drop it and re-edit old mine script, just changing source lines to git and leaving other script code as it is.

script is based on your latest script
But I had a copy of older script which I was able to execute properly and I use it as a base. When it will finish I will share result.
AND great success:
this is link to compiled beta domoticz on nas 542:https://drive.google.com/open?id=10L2Hb ... N5lkJY1J4f