#!/bin/bash

#
# Set rights on target directory
#
# AM 2019.12
#

# Ensure path to directory is passed and exists


if [ -z "$1" ] || [ ! -d "$1" ]; then
 echo ""
 echo "Usage: ri <path_to_dir>"
 echo "example: ri /srv/www/staging"
 echo ""
 exit 1
fi

tarpath=${1}
htuser='www-data'
htgroup='www-data'
rootuser='root'

find ${tarpath}/ -type f -print0 | xargs -0 -r chmod 0664
find ${tarpath}/ -type d -print0 | xargs -0 chmod 0770

chown -R ${htuser}:${htgroup} ${tarpath}/

