-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathwww-set-permissions
More file actions
executable file
·84 lines (71 loc) · 2.26 KB
/
www-set-permissions
File metadata and controls
executable file
·84 lines (71 loc) · 2.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/usr/bin/env bash
__SOURCE__="${BASH_SOURCE[0]}"
while [[ -h "${__SOURCE__}" ]]; do
__SOURCE__="$(find "${__SOURCE__}" -type l -ls | sed -n 's@^.* -> \(.*\)@\1@p')"
done
__DIR__="$(cd -P "$(dirname "${__SOURCE__}")" && pwd)"
__NAME__="${__SOURCE__##*/}"
__AUTHOR__='S0AndS0'
__DESCRIPTION__='Sets permissions for named repository site files under "~/www" directory'
## Provides: argument_parser <arg-array-reference> <acceptable-arg-reference>
source "${__DIR__}/shared_functions/modules/argument-parser/argument-parser.sh"
## Provides: '__license__ <description> <author>'
source "${__DIR__}/shared_functions/license"
usage(){
_message="${1}"
_repo_name="${_repo_name:-repository-name}"
cat <<EOF
## Usage
# ssh ${USER}@host-or-ip ${__NAME__} ${_git_args[@]:-$_repo_name}
#
# ${__DESCRIPTION__}
#
# ${_repo_name}
# Name of repository to run chown and chmod on files and directories
# under ~/www/${_repo_name}
#
# -l --license
# Shows script or project license then exits
#
# -h --help help
# Displays this message and exits
EOF
(("${#_message}")) && [[ "${_message}" != '0' ]] && {
printf >&2 'Error - %s\n' "${_message}"
}
}
_args=("${@:?# No arguments provided try: ${__NAME__} help}")
_valid_args=('--help|-h|help:bool'
'--license|-l|license:bool'
'--repo-name:posix-nil')
argument_parser '_args' '_valid_args'
_exit_status="$?"
if ((_help)) || ((_exit_status)); then
usage "${_exit_status}"
exit "$?"
elif ((_license)); then
__license__ "${__DESCRIPTION__}" "${__AUTHOR__}"
exit 0
fi
(("${#_repo_name}")) || {
usage 'missing repository name argument!'
exit "1"
}
_www="${HOME}/www"
_www_group="$(groups ${USER} | grep -oE 'www[-a-z]{0,29}')"
_srv_path="${_www}/${_repo_name}"
(("${#_www_group}")) || {
printf '# No www group found for %s\n' "${USER}"
exit 1
}
[[ -d "${_www}" ]] || {
printf '# No www directory at %s\n' "${_www}"
[[ -e "${HOME}/git-shell-commands/jekyll-build" ]] && {
printf '# try: ssh %s@host-or-ip jekyll-build %s\n' "${USER}" "${_repo_name}"
}
exit 1
}
chown --recursive "${USER}":"${_www_group}" "${_srv_path}"
find "${_srv_path}" -type d -exec chmod 750 {} \;
find "${_srv_path}" -type f -exec chmod 640 {} \;
printf '# %s finished\n' "${__NAME__}"