Use "here doc" and drop chmod.

Based on feedback from @adamv and @mikemcquaid.