-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·152 lines (133 loc) · 3.91 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·152 lines (133 loc) · 3.91 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
#!/bin/bash
### BEGIN COPYRIGHT NOTICE
# Copyright 2019 Stephen Fedele <stephen.m.fedele@wmich.edu>, Daniel Darcy, Timothy Curry
#
# 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
echo "WARNING: THIS PROGRAM SHOULD ONLY BE RUN ON UBUNTU!!!"
# NOTE: THE DEFAULT WORKING DIRECTORY FOR THE REST OF THIS PROGRAM IS THE DIRECTORY THAT THIS PROGRAM WAS INVOKED IN (usually, '/var/www/html/CodeTutorials/'; you can get around this with 'pushd' and 'popd')
if [ "$1" = "-v" ]
then
exec 3>&1
else
exec 3>/dev/null
fi
# Exit on errors
set -e
set -o pipefail
# Initialize project settings
echo 1>&3
echo "Initializing project settings..."
rm ./.settings.sh &>/dev/null || true
source ./devtools.sh --installation
# Change project permissions as appropriate
echo 1>&3
echo "Updating project permissions..."
openproj
if $DEVELOPMENT && $DEPLOYMENT
then
function fixperms {
devdeploy "$@"
openaccess "$@"
}
elif $DEVELOPMENT
then
function fixperms {
developer "$@"
openaccess "$@"
}
elif $DEPLOYMENT
then
function fixperms {
deployment "$@"
openaccess "$@"
}
fi
fixperms .
# Set up and activate virtual environment
echo 1>&3
echo "Creating virtual environment for python..."
virtualenv -p python3 ./djangobox/ 1>&3
pushd ./djangobox/ &>/dev/null
source ./bin/activate
popd &>/dev/null
# Install python packages
echo 1>&3
echo "Installing Django and useful packages in virtual environment..."
pip3 install Django==2.1.7 djangocodemirror==2.1.0 django-bootstrap3==11.1.0 django-generate-secret-key==1.0.2 1>&3
# Add relevant users to group 'docker'
echo 1>&3
if $DEVELOPMENT
then
echo "Adding '$DEV_USER' to group 'docker'..."
sudo usermod -aG docker $DEV_USER
fi
if $DEPLOYMENT
then
echo "Adding '$SERVER_USER' to group 'docker'..."
sudo usermod -aG docker $SERVER_USER
fi
# Generate a secret key for Django
echo 1>&3
echo "Generating a secret key for Django..."
pushd ./djangobox/src/ &>/dev/null
./manage.py generate_secret_key --replace
fixperms $SRC_DIR/secretkey.txt
closeaccess $SRC_DIR/secretkey.txt
popd &>/dev/null
# Set up database
echo 1>&3
echo "Setting up database..."
pushd ./djangobox/src/ &>/dev/null
./manage.py makemigrations 1>&3
./manage.py migrate 1>&3
fixperms $SRC_DIR/db.sqlite3
popd &>/dev/null
# Collect static files
echo 1>&3
echo "Collecting static files..."
pushd ./djangobox/src/ &>/dev/null
./manage.py collectstatic <<<"yes" 1>&3
fixperms $SRC_DIR/static/
popd &>/dev/null
# Build Docker images
echo 1>&3
echo "Building docker images..."
pushd ./djangobox/src/docker/docker_wrapper/ &>/dev/null
sudo systemctl start containerd.service docker.service docker.socket
./buildimages.sh 1>&3 # This script uses 'sudo' on its own, but this simplifies things a bit
sudo systemctl stop containerd.service docker.service docker.socket
popd &>/dev/null
# Potentially, symlink the static directory for Apache
if $DEPLOYMENT
then
echo 1>&3
echo "Symlinking static files directory for Apache..."
pushd /var/www/html/ &>/dev/null
sudo ln -s -T $OLDPWD/djangobox/src/static/ ./static
popd &>/dev/null
fi
# Move the WSGI configuration file so that Apache can find it
if $DEPLOYMENT
then
echo 1>&3
echo "Copying WSGI configuration file..."
cat ./mods-enabled/wsgi.conf | sudo tee -a /etc/apache2/mods-enabled/wsgi.conf &>/dev/null
fi
# Cleanup
unset -f fixperms
undevtools
deactivate