shell-base/function/acl

52 lines
1.3 KiB
Bash

#!/bin/bash
acluserdir() {
module_load confirm
local uid
local usesudo
local del
local spec
local cmd="-R -m "
local cmdd="-dR -m"
if [[ $1 == "-d" ]]; then
shift
echo deleting an acl entries for $1
opts="-R -x"
optsd="-dR -x"
spec="u:$1 $2"
else
opts="-R -m "
optsd="-dR -m"
spec="u:$1:rwX $2"
fi
[[ ! $2 ]] && echo acluserdir: both user and direcotory must be passed && return 1
uid=$(id -u $1 2>/dev/null)
[[ $uid -lt 1000 ]] && echo no such regular user $1 && return 2
[[ ! -d $2 ]] && echo no such directory $2 && return 3
if [[ ! -w $2 ]];then
echo $2 not writable by current user $USER
if [[ ! $(sudo -l -U $USER 2>/dev/null) ]]; then
echo user does not have sudo privilges, aborting
return 4
else
confirm "do you want to elevate to root and continue?" || return 5
usesudo="sudo"
fi
fi
echo this are the commands that you will run
echo '******************'
echo $usesudo setfacl $opts $spec
echo $usesudo setfacl $optsd $spec
echo '******************'
confirm Double Check. Do you want to continue? || return 6
$usesudo setfacl $opts $spec
$usesudo setfacl $optsd $spec
echo '*** new acl entries ***'
$usesudo getfacl -p --omit-header $2 | grep $1
}