#!/bin/sh
#
# enforce_perm
#
# Enforces given unix file permissions for all files beyond a given directory
# 
# Usage:
#          enforce_perm FILEOWNER FILEGROUP DIRPERMISSIONS FILEPERMISSIONS STARTDIR
#
# Example:
#          enforce_perm root staff 2775 0664 /root/files/
#
# Autor Thorsten Gunkel <tgunkel@gmx.de>
#
# --- 04.06.2004 Thorsten Gunkel <tgunkel@gmx.de> ---
# * Initial Release
# --- No older changelog available ---
#

# user.group dirmode filemode startdir
do_fix()
{
  find "$5" \( ! -user "$1" -o ! -group "$2" \) -exec chown -c "$1"."$2" '{}' ';'
  find "$5" -type d ! -perm "$3" -exec chmod -c "$3" '{}' ';'
  find "$5" -type f ! -perm "$4" -exec chmod -c "$4" '{}' ';'
}

#echo "User Group DirPerm FilePerm StartDir"
do_fix "$1" "$2" "$3" "$4" "$5"

