-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdevtools.sh
More file actions
167 lines (132 loc) · 4.03 KB
/
Copy pathdevtools.sh
File metadata and controls
167 lines (132 loc) · 4.03 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
#!/bin/sed -e 3q;d;
### BEGIN COPYRIGHT NOTICE
# Copyright 2019 Stephen Fedele <stephen.m.fedele@wmich.edu>
#
# This file is part of CodeTutorials.
#
# CodeTutorials is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# CodeTutorials is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with CodeTutorials. If not, see <https://www.gnu.org/licenses/>.
### END COPYRIGHT NOTICE
# Do not run this file directly - source it instead
### Startup
# Clear everything from a previous session
undevtools &>/dev/null || true
# Global and static variables
source ./makesettings.sh || return 1
TOOLS_PROMPT="(devtools) "
SRC_DIR=$PROJECT_ROOT/djangobox/src
MANAGE_PY=$SRC_DIR/manage.py
if [ ! "$1" == "--installation" ]
then
echo "Some commands in this suite invoke 'sudo'. Use them at your own risk!"
echo "You can deactivate this suite at any time by running 'undevtools'."
fi
PS1=$TOOLS_PROMPT$PS1
### Internal components - DO NOT TOUCH (please)
function changeperms {
local TO_WHOM=$1
shift
if [ -n "$*" ]
then
local INDEX
for INDEX in "$@"
do
find $INDEX \( -type d -o -type f \) -execdir sudo chown --no-dereference $TO_WHOM \{\} +
find $INDEX -type d -execdir sudo chmod u+rwx,g+rwx \{\} +
find $INDEX -type f -execdir sudo chmod u+rw,g+rw \{\} +
done
else
echo "Error: Missing parameter."
fi
}
### User-end functions
# Removes any functionality of this script from your terminal
function undevtools {
PS1=${PS1#$TOOLS_PROMPT}
unset -v TOOLS_PROMPT SRC_DIR MANAGE_PY 1>/dev/null
unset -f undevtools redevtools changeperms developer devdeploy deployment openaccess openproj closeaccess closeproj startserver stopserver 1>/dev/null
unalias collectstatic
unsettings
}
# Re-initializes development tools
function redevtools {
local PROJECT_ROOT_BKP=$PROJECT_ROOT
undevtools
source $PROJECT_ROOT_BKP/devtools.sh
}
# Ownership tools
# Changes ownership and group of the given directories to the developer
function developer {
changeperms $DEV_USER:$DEV_GROUP "$@"
}
# Changes ownership of the given directories to the developer and group to the server
function devdeploy {
changeperms $DEV_USER:$SERVER_GROUP "$@"
}
# Changes ownership and group of the given directories to the server
function deployment {
changeperms $SERVER_USER:$SERVER_GROUP "$@"
}
# Permission tools
# Recursively adds reading permission for everyone upon the given directories
function openaccess {
if [ -n "$*" ]
then
local INDEX
for INDEX in "$@"
do
find $INDEX -type d -execdir sudo chmod a+rx,ug+w \{\} +
find $INDEX -type f -execdir sudo chmod a+r,ug+w \{\} +
done
else
echo "Error: Missing parameter."
fi
}
# Recursively revokes all permissions for everyone except the owner upon the given directories
function closeaccess {
if [ -n "$*" ]
then
local INDEX
for INDEX in "$@"
do
find $INDEX \( -type f -o -type d \) -execdir sudo chmod o-rwx \{\} +
done
else
echo "Error: Missing parameter."
fi
}
# Makes the project's files accessible to everyone
function openproj {
openaccess $SRC_DIR/
closeaccess $SRC_DIR/secretkey.txt
sudo chmod ug+x $SRC_DIR/docker/docker_wrapper/runContainer.sh
sudo chmod u+x $SRC_DIR/docker/docker_wrapper/buildimages.sh
}
# Makes the project's files inaccessible to everyone except the owner
function closeproj {
sudo chmod g-x $SRC_DIR/docker/docker_wrapper/runContainer.sh
closeaccess $SRC_DIR/
}
# Server tools
eval "
# Starts the deployment server
function startserver {
$SERVER_START ;
}
# Stops the deployment server
function stopserver {
$SERVER_STOP ;
}
"
# Convenience for updating static files
alias collectstatic="$MANAGE_PY collectstatic <<<'yes' 1>/dev/null"