Skip to content

Add new functions for faster permissions setting #332

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions ubuntu/16.04/usr/local/share/bootstrap/common_functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -235,3 +235,38 @@ function test_remote_ports() {
timeout 1 bash -c "cat < /dev/null > /dev/tcp/${SERVICE_PARAMS[0]}/${SERVICE_PARAMS[1]}" 2>/dev/null || return 1
done
}

function do_ownership() {
local OWNERSHIP_PATH=($1)
local USER="$2"
local GROUP="$3"
local ALLOW_GROUP_WRITE="${4:-true}"
if [ "$IS_CHOWN_FORBIDDEN" != 'true' ]; then
find "${OWNERSHIP_PATH[@]}" \( ! -user "${USER}" -or ! -group "${GROUP}" \) -exec chown "${USER}:${GROUP}" {} +
fi
do_read_write_permissions "${OWNERSHIP_PATH[@]}" "${ALLOW_GROUP_WRITE}"
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't pass through the paths correctly to do_read_write_permissions, only the first one.

}

function do_read_write_permissions() {
local OWNERSHIP_PATH=($1)
local ALLOW_GROUP_WRITE="${2:-true}"
if [ "$IS_CHOWN_FORBIDDEN" != 'true' ]; then
if [ "$ALLOW_GROUP_WRITE" == 'true' ]; then
find "${OWNERSHIP_PATH[@]}" \( ! -perm /u=w -or ! -perm /g=w -or -perm /o=w \) -exec chmod ug+rw,o-w {} +
else
find "${OWNERSHIP_PATH[@]}" \( ! -perm /u=w -or -perm /g=w -or -perm /o=w \) -exec chmod u+rw,go-w {} +
fi
else
find "${OWNERSHIP_PATH[@]}" \( ! -perm /u=w -or ! -perm /g=w -or ! -perm /o=w \) -exec chmod a+rw {} +
fi
}

function do_read_permissions() {
local OWNERSHIP_PATH=($1)
find "${OWNERSHIP_PATH[@]}" \( ! -perm /u=r -or ! -perm /g=r -or ! -perm /o=r \) -exec chmod a+r {} +
}

function do_remove_other_permissions() {
local OWNERSHIP_PATH=($1)
find "${OWNERSHIP_PATH[@]}" \( -perm /o=r -or -perm /o=w -or -perm /o=x \) -exec chmod o-rwx {} +
}