Initial commit

This commit is contained in:
2021-10-16 15:06:07 -04:00
parent 9a839d6530
commit b2d495dadc
13 changed files with 663 additions and 0 deletions

View File

@@ -0,0 +1,53 @@
#!/usr/bin/env bash
# Smartly change permissions on selected directories
# Copyright 2021 Bryan C. Roessler
[[ -f functions ]] && . functions || exit 1
is_root
if [[ $# -eq 0 ]]; then
user=$(stat -c "%U" "$path")
group=$(stat -c "%G" "$path")
echo "No arguments provided, using autodetection"
if [[ "$group" != "smbgrp" ]]; then
echo "This file will not be world-accessible by the smbgrp group"
ask_ok "Change group $group to smbgrp?" && group="smbgrp"
fi
elif [[ $# -eq 1 ]]; then
user="$1"
group="$1"
paths=("$PWD")
elif [[ $# -eq 2 ]]; then
user="$1"
group="$2"
paths=("$PWD")
elif [[ $# -gt 2 ]]; then
user="$1"
group="$2"
paths=("${@:3}")
fi
for path in "${paths[@]}"; do
if [[ "$path" == "/" ]]; then
echo "You are trying to operate on the root partition!"
echo "This seems highly unusual!"
! ask_ok "Continue?" && exit $?
fi
done
ask_ok "Apply user: $user and group: $group to ${paths[*]} and all subdirs?" && \
chown -R "$user":"$group" "${paths[@]}"
[[ "$group" == "smbgrp" ]] && mode=6775 || mode=755
ask_ok "Apply chmod $mode to ${paths[*]} and all subdirs?" && \
chmod -R $mode "${paths[@]}"
# Let's do it in less steps (see above) for now unless it becomes a problem
# echo "Apply setuid/setgid bits to ${paths[*]} and all subdirs?"
# ask_ok "Files/dirs will inherit their " && \
# chmod -R g+s,u+s "${paths[@]}"
exit $?