Skip to content
Merged
Show file tree
Hide file tree
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
42 changes: 42 additions & 0 deletions .scripts/set_permissions.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/usr/bin/env bash
set -Eeuo pipefail
IFS=$'\n\t'

set_permissions() {
local CH_PATH=${1:-$SCRIPTPATH}
case "${CH_PATH}" in
# https://en.wikipedia.org/wiki/Unix_filesystem
# Split into two in order to keep the lines shorter
"/" | "/bin" | "/boot" | "/dev" | "/etc" | "/home" | "/lib" | "/media") ;&
"/mnt" | "/opt" | "/proc" | "/root" | "/sbin" | "/srv" | "/sys" | "/tmp" | "/unix") ;&
"/usr" | "/usr/include" | "/usr/lib" | "/usr/libexec" | "/usr/local" | "/usr/share") ;&
"/var" | "/var/log" | "/var/mail" | "/var/spool" | "/var/tmp")
error "Skipping permissions on '${C["Folder"]}${CH_PATH}${NC}' because it is a system path."
return
;;
${DETECTED_HOMEDIR}/*)
info "Setting permissions for '${C["Folder"]}${CH_PATH}${NC}'"
;;
*)
# TODO: Consider adding a prompt to confirm setting permissions
warn "Setting permissions for '${C["Folder"]}${CH_PATH}${NC}' outside of '${C["Folder"]}${DETECTED_HOMEDIR}${NC}' may be unsafe."
;;
esac
local CH_PUID=${2:-$DETECTED_PUID}
local CH_PGID=${3:-$DETECTED_PGID}
if [[ ${CH_PUID} -ne 0 ]] && [[ ${CH_PGID} -ne 0 ]]; then
info "Taking ownership of '${C["Folder"]}${CH_PATH}${NC}' for user '${C["User"]}${CH_PUID}${NC}' and group '${C["User"]}${CH_PGID}${NC}'"
sudo chown -R "${CH_PUID}":"${CH_PGID}" "${CH_PATH}" &> /dev/null || true
info "Setting file and folder permissions in '${C["Folder"]}${CH_PATH}${NC}'"
sudo chmod -R a=,a+rX,u+w,g+w "${CH_PATH}" &> /dev/null || true
fi
info "Setting executable permission on '${C["File"]}${SCRIPTNAME}${NC}'"
sudo chmod +x "${SCRIPTNAME}" &> /dev/null ||
fatal \
"'${C["UserCommand"]}${APPLICATION_COMMAND}${NC}' must be executable." \
"Failing command: ${C["FailingCommand"]}sudo chmod +x \"${SCRIPTNAME}\""
}

test_set_permissions() {
run_script 'set_permissions'
}
1 change: 0 additions & 1 deletion includes/run_script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ run_script() {
shift

local script_file="${SCRIPTPATH}/scripts/${script_name}.sh"

[[ -f ${script_file} ]] ||
fatal \
"Script file '${C["File"]}${script_file}${NC}' not found."
Expand Down