Skip to content

Commit 10b15ba

Browse files
andytson-inviqakierenevans
authored andcommitted
A possible alternative abstraction for permissions
Assumes for facl/stickybit that all users are umask 0002 It doesn't have the performance improvements of #332 yet, though I'm unsure if that's possible with setfacl
1 parent 2618274 commit 10b15ba

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

ubuntu/16.04/usr/local/share/bootstrap/common_functions.sh

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,44 @@ function do_clear_apt_caches() {
216216
rm -rf /var/lib/apt/lists/*
217217
}
218218

219+
function set_path_permissions() {
220+
local -r READABLE_USERS=($1)
221+
local -r WRITEABLE_USERS=($2)
222+
local -r PATHS=("${@:3}")
223+
224+
case "$PERMISSION_MODE" in
225+
facl)
226+
setfacl -R $(printf '-m user:%s:rwX ' "${WRITEABLE_USERS[@]}") \
227+
$(printf '-m default:user:%s:rwX ' "${WRITEABLE_USERS[@]}") \
228+
$(printf '-m user:%s:rX ' "${READABLE_USERS[@]}") \
229+
$(printf '-m default:user:%s:rX ' "${READABLE_USERS[@]}") \
230+
"${PATHS[@]}"
231+
chmod -R ug+rw,o-rwx "${PATHS[@]}"
232+
;;
233+
stickybit)
234+
GROUP="$(printf '%s' "${WRITEABLE_USERS[@]}")"
235+
236+
if ! getent group "$GROUP" >/dev/null; then
237+
groupadd "$GROUP"
238+
fi
239+
240+
for USER in "${WRITEABLE_USERS[@]}"; do
241+
usermod -a -G "$GROUP" "$USER"
242+
done
243+
244+
chgrp -R "$GROUP" "${PATHS[@]}"
245+
find "${PATHS[@]}" -type d -exec chmod g+ws \;
246+
find "${PATHS[@]}" -type f -exec chmod g+w \;
247+
;;
248+
chmod)
249+
chmod -R a+rw "${PATHS[@]}"
250+
;;
251+
*)
252+
echo "unsupported permission mode '$PERMISSION_MODE'" >&2
253+
;;
254+
esac
255+
}
256+
219257
function canonical_port() {
220258
local PORT="$1"
221259
if [[ $PORT =~ tcp://[^:]+:([0-9]+) ]]; then

0 commit comments

Comments
 (0)