Made some changes to make this work on Debian (and Ubuntu).
Also, do not forget to install the "realpath" package.