#!/usr/bin/bash
#####################################################################################
# Copyright 2018 Normation SAS
#####################################################################################
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, Version 3.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
#####################################################################################

# Rudder script to fix permissions in /var/rudder/configuration-repository

echo -n "INFO: Correcting permissions on /var/rudder/configuration-repository..."
# Adjust permissions on /var/rudder/configuration-repository
chgrp -R rudder /var/rudder/configuration-repository

## Add execution permission for ncf-api only on directories and files with user execution permission
chmod -R u+rwX,g+rwX /var/rudder/configuration-repository/.git
chmod -R u+rwX,g+rwX /var/rudder/configuration-repository/techniques

## Add setgid to directories so that all files created here belong to the rudder group
find /var/rudder/configuration-repository/.git /var/rudder/configuration-repository/techniques -type d -exec chmod g+s "{}" \;

echo " Done"

