#!/bin/sh
# -*-mode: sh; tab-width: 8; coding: utf-8-unix -*-

# very dangerous
[ "$#" -gt 0 ] && ROOT=$1 || ROOT=/
[ -n "$ROOT" ] ||   exit 1
[ -d "$ROOT" ] ||   exit 2

ROLE=testforge

cd $ROOT || exit 2
GROUP=adm
[ -f /usr/local/etc/testforge/testforge.bash ] && . /usr/local/etc/testforge/testforge.bash
[ -n "$BOX_ALSO_GROUP" ] && GROUP=$BOX_ALSO_GROUP

if [ -d ${ROOT}$PREFIX ] ; then
    # allow
    chgrp -R $GROUP    ${ROOT}$PREFIX/{bin,data,lib64,src,net}
    chmod -R g+rw,o-w  ${ROOT}$PREFIX/{bin,data,lib64,src,net}
    chmod a+x          ${ROOT}$PREFIX/{bin,src,share/bash}/*sh
    # if [ -d ${ROOT}$PREFIX/src/lynis ] ; then

    chgrp -R $GROUP    ${ROOT}$PREFIX/{bin,data,lib64,src,net}
    # forbid /var
    chgrp -R root      ${ROOT}$PREFIX/{etc,var,share}
    chmod -R g-w,o-w   ${ROOT}$PREFIX/{etc,var,share}
  fi
if [ -d ${ROOT}/usr/local ] ; then
    # forbid /usr but lib/python* will be created and allowed on install
    chgrp -R root 	   ${ROOT}/usr/local/
    chmod -R g-w,o-rw  ${ROOT}/usr/local/
fi
exit 0
