-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmakesettings.sh
More file actions
177 lines (153 loc) · 3.95 KB
/
Copy pathmakesettings.sh
File metadata and controls
177 lines (153 loc) · 3.95 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
168
169
170
171
172
173
174
175
176
177
#!/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
unsettings &>/dev/null || true
# Global variables
PROJECT_ROOT=$(realpath -m $(dirname "$PWD/$0"))
SETTINGS_FILE=$PROJECT_ROOT/.settings.sh
# Initialize or load configuration file
if [ -f $SETTINGS_FILE ]
then
source $SETTINGS_FILE
echo "Settings loaded from file '$SETTINGS_FILE' (delete it to reset this dialog)."
else
# Ask about project mode
echo -n "Will this project be used for 1) development only, 2) development of the deployment version, or 3) deployment only? "
read
case "$REPLY" in
"1")
DEVELOPMENT="true"
DEPLOYMENT="false"
;;
"2")
DEVELOPMENT="true"
DEPLOYMENT="true"
;;
"3")
DEVELOPMENT="false"
DEPLOYMENT="true"
;;
*)
echo "Error: Invalid question response..."
return 1
;;
esac
# Configure developer user and group
DEV_USER="$(id -un)"
cat <<- EOF
Input developer username (login name)
(default if empty: '$DEV_USER'):
EOF
read
if [ -n "$REPLY" ]
then
DEV_USER=$REPLY
fi
echo
DEV_GROUP="$(id -gn)"
cat <<- EOF
Input developer groupname
(default if empty: '$DEV_GROUP'):
EOF
read
if [ -n "$REPLY" ]
then
DEV_GROUP=$REPLY
fi
echo
# Configure server user and group
SERVER_USER="www-data"
cat <<- EOF
Input server username
(if not applicable, input: 'nobody')
(default if empty (uses Apache): '$SERVER_USER'):
EOF
read
if [ -n "$REPLY" ]
then
SERVER_USER=$REPLY
fi
echo
SERVER_GROUP="www-data"
cat <<- EOF
Input server groupname
(if not applicable, input: 'nogroup')
(default if empty (uses Apache): '$SERVER_GROUP'):
EOF
read
if [ -n "$REPLY" ]
then
SERVER_GROUP=$REPLY
fi
echo
# Configure deployment server commands
if $DEPLOYMENT
then
SERVER_START="sudo systemctl start apache2.service containerd.service docker.service docker.socket"
else
SERVER_START="sudo systemctl start containerd.service docker.service docker.socket && $PROJECT_ROOT/djangobox/src/manage.py runserver"
fi
cat <<- EOF
Input server startup command
(default if empty: '$SERVER_START'):
EOF
read
if [ -n "$REPLY" ]
then
SERVER_START=$REPLY
fi
echo
if $DEPLOYMENT
then
SERVER_STOP="sudo systemctl stop apache2.service containerd.service docker.service docker.socket"
else
SERVER_STOP="sudo systemctl stop containerd.service docker.service docker.socket && echo 'Please remember to kill the Django process if it is running in the background!'"
fi
cat <<- EOF
Input server shutdown command
(default if empty: '$SERVER_STOP'):
EOF
read
if [ -n "$REPLY" ]
then
SERVER_STOP=$REPLY
fi
echo
# Save settings
cat >$SETTINGS_FILE <<- EOF
#!/bin/false
DEVELOPMENT="$DEVELOPMENT"
DEPLOYMENT="$DEPLOYMENT"
DEV_USER="$DEV_USER"
DEV_GROUP="$DEV_GROUP"
SERVER_USER="$SERVER_USER"
SERVER_GROUP="$SERVER_GROUP"
SERVER_START="$SERVER_START"
SERVER_STOP="$SERVER_STOP"
EOF
echo "Settings saved to file '$SETTINGS_FILE' (delete it to reset this dialog)."
fi
### Cleanup
function unsettings {
unset -v PROJECT_ROOT SETTINGS_FILE DEVELOPMENT DEPLOYMENT DEV_USER DEV_GROUP SERVER_USER SERVER_GROUP SERVER_START SERVER_STOP 1>/dev/null
unset -f unsettings 1>/dev/null
}