script breaks my ability to run psql
PG_HBA=$(su postgres -c "psql -t -P format=unaligned -c 'SHOW hba_file'")


That seems potentially problematic.


That line above shows createdb ultimaterehab. That line doesn't however connect to the ultimaterehab database. It connects to the default database. 
Debian/Ubuntu already does the setting up for the right pg_hba. You don't have to do anything whatsoever. If you absolutely need the location of the pg_hba file, which you do not need, you'd be better of working with the system utility pg_conftool to get that location: pg_conftool show hba_file.


Moreover, ubuntu doesn't use su, it uses sudo.

sudo -u postgres createuser app
sudo -u postgres createdb ultimaterehab


And you're done.