#!/bin/bash
[ -f /etc/local/volumes ] || exit 1
. /etc/local/volumes
[ "x$SDIR" = "x" ] && exit 1
if [ $# -eq 0 ]; then
# echo "$0: directory name(s) required"
echo "Usage: $0 [create]"
exit 1
fi
if [ "x$1" = "x" ]; then
echo "$0: base directory missing"
exit 1
fi
VOL=$SDIR/$1
if [ "x$2" = "x" ]; then
echo "$0: read group missing"
exit 1
fi
ALL=$2
if [ "x$3" = "x" ]; then
echo "$0: write group missing"
exit 1
fi
GRP=$3
#GRPUSER="nobody"
GRPUSER="admin"
#if [ "x$4" != "x" ]; then
# GRPUSER=$4
#else
id $GRP >/dev/null && GRPUSER=$GRP
#fi
if [ "x$4" != "x" ]; then
if [ "x$4" == "xcreate" ]; then
mkdir -p $VOL/$ALL/$GRP || exit
else
echo "Usage: $0 [create]"
exit 1
fi
fi
test -d $VOL/$ALL/$GRP || exit
chown root.$ALL $VOL/$ALL
chown $GRPUSER.$ALL $VOL/$ALL/$GRP
chmod u=rwX,g=rX,o= $VOL/$ALL
chmod u=rwX,g=rX,o= $VOL/$ALL/$GRP
echo "People in group $GRP has read/write access through SMB networking"
test $GRP = $ALL || echo "People in group $ALL has read access through SMB networking"
echo "Others have no access"
echo -n "Checking permissions..."
chown -R $GRPUSER.$GRP $VOL/$ALL/$GRP \
&& chmod -R u=rwX,g=rwX,o=rX $VOL/$ALL/$GRP
echo "."