#!/usr/bin/env bash
AS_USER=username
FROM=/path/to/source/*
TO=/path/to/destination
sudo -u $AS_USER rsync -av $FROM $TO
# NOTE: for copy-as-user.sh to work without password you need to add /etc/sudoers.d/repositoryname file with something like this
# `gituser ALL=(www-data) NOPASSWD: /path/to/copy-as-user.sh`
# where gituser is the user preforming the push
# use this as a part of post-recieve hook if you need to retain some permissions eg. copying to webroot
# 1. Force checkout working tree from a bare repository
# `git --work-tree=/web/root/src --git-dir=/bare/repository.git checkout -f`
# 2. Build/generate/compile/pack files into a static site & copy theme to the web root
# `cd /web/root/src && npm install && npm run generate && /path/to/copy-as-user.sh`