Skip to content

Commit 92684f4

Browse files
authored
Re-arrange folder structure (#2424)
1 parent 04719e2 commit 92684f4

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

.scripts/set_permissions.sh

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/usr/bin/env bash
2+
set -Eeuo pipefail
3+
IFS=$'\n\t'
4+
5+
set_permissions() {
6+
local CH_PATH=${1:-$SCRIPTPATH}
7+
case "${CH_PATH}" in
8+
# https://en.wikipedia.org/wiki/Unix_filesystem
9+
# Split into two in order to keep the lines shorter
10+
"/" | "/bin" | "/boot" | "/dev" | "/etc" | "/home" | "/lib" | "/media") ;&
11+
"/mnt" | "/opt" | "/proc" | "/root" | "/sbin" | "/srv" | "/sys" | "/tmp" | "/unix") ;&
12+
"/usr" | "/usr/include" | "/usr/lib" | "/usr/libexec" | "/usr/local" | "/usr/share") ;&
13+
"/var" | "/var/log" | "/var/mail" | "/var/spool" | "/var/tmp")
14+
error "Skipping permissions on '${C["Folder"]}${CH_PATH}${NC}' because it is a system path."
15+
return
16+
;;
17+
${DETECTED_HOMEDIR}/*)
18+
info "Setting permissions for '${C["Folder"]}${CH_PATH}${NC}'"
19+
;;
20+
*)
21+
# TODO: Consider adding a prompt to confirm setting permissions
22+
warn "Setting permissions for '${C["Folder"]}${CH_PATH}${NC}' outside of '${C["Folder"]}${DETECTED_HOMEDIR}${NC}' may be unsafe."
23+
;;
24+
esac
25+
local CH_PUID=${2:-$DETECTED_PUID}
26+
local CH_PGID=${3:-$DETECTED_PGID}
27+
if [[ ${CH_PUID} -ne 0 ]] && [[ ${CH_PGID} -ne 0 ]]; then
28+
info "Taking ownership of '${C["Folder"]}${CH_PATH}${NC}' for user '${C["User"]}${CH_PUID}${NC}' and group '${C["User"]}${CH_PGID}${NC}'"
29+
sudo chown -R "${CH_PUID}":"${CH_PGID}" "${CH_PATH}" &> /dev/null || true
30+
info "Setting file and folder permissions in '${C["Folder"]}${CH_PATH}${NC}'"
31+
sudo chmod -R a=,a+rX,u+w,g+w "${CH_PATH}" &> /dev/null || true
32+
fi
33+
info "Setting executable permission on '${C["File"]}${SCRIPTNAME}${NC}'"
34+
sudo chmod +x "${SCRIPTNAME}" &> /dev/null ||
35+
fatal \
36+
"'${C["UserCommand"]}${APPLICATION_COMMAND}${NC}' must be executable." \
37+
"Failing command: ${C["FailingCommand"]}sudo chmod +x \"${SCRIPTNAME}\""
38+
}
39+
40+
test_set_permissions() {
41+
run_script 'set_permissions'
42+
}

includes/run_script.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ run_script() {
3434
shift
3535

3636
local script_file="${SCRIPTPATH}/scripts/${script_name}.sh"
37-
3837
[[ -f ${script_file} ]] ||
3938
fatal \
4039
"Script file '${C["File"]}${script_file}${NC}' not found."

0 commit comments

Comments
 (0)