Skip to content

Commit 20d3b33

Browse files
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 de7fb88 commit 20d3b33

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
@@ -217,6 +217,44 @@ function do_clear_apt_caches() {
217217
rm -rf /var/lib/apt/lists/*
218218
}
219219

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

0 commit comments

Comments
 (0)