forked from mgage/webwork2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocker-entrypoint.sh
More file actions
executable file
·89 lines (83 loc) · 4.12 KB
/
Copy pathdocker-entrypoint.sh
File metadata and controls
executable file
·89 lines (83 loc) · 4.12 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
#!/bin/bash
set -eo pipefail
# if command starts with an option, prepend apache2
if [ "${1:0:1}" = '-' ]; then
set -- apache2 "$@"
fi
if [ "$1" = 'apache2' ]; then
# generate conf files if not exist
for i in site.conf localOverrides.conf; do
if [ ! -f $APP_ROOT/webwork2/conf/$i ]; then
cp $APP_ROOT/webwork2/conf/$i.dist $APP_ROOT/webwork2/conf/$i
if [ $i == 'site.conf' ]; then
sed -i -e 's/webwork_url = '\''\/webwork2'\''/webwork_url = $ENV{"WEBWORK_URL"}/' \
-e 's/server_root_url = '\'''\''/server_root_url = $ENV{"WEBWORK_ROOT_URL"}/' \
-e 's/database_dsn ="dbi:mysql:webwork"/database_dsn =$ENV{"WEBWORK_DB_DSN"}/' \
-e 's/database_username ="webworkWrite"/database_username =$ENV{"WEBWORK_DB_USER"}/' \
-e 's/database_password ="passwordRW"/database_password =$ENV{"WEBWORK_DB_PASSWORD"}/' \
-e 's/mail{smtpServer} = '\'''\''/mail{smtpServer} = $ENV{"WEBWORK_SMTP_SERVER"}/' \
-e 's/mail{smtpSender} = '\'''\''/mail{smtpSender} = $ENV{"WEBWORK_SMTP_SENDER"}/' \
-e 's/siteDefaults{timezone} = "America\/New_York"/siteDefaults{timezone} = $ENV{"WEBWORK_TIMEZONE"}/' \
-e 's/$server_groupID = '\''wwdata'\''/$server_groupID = "root"/' \
$APP_ROOT/webwork2/conf/site.conf
fi
fi
done
# create admin course if not existing
if [ ! -d "$APP_ROOT/courses/admin" ]; then
# wait for db to start up
echo "Waiting for database to start..."
while ! timeout 1 bash -c "(cat < /dev/null > /dev/tcp/$WEBWORK_DB_HOST/$WEBWORK_DB_PORT) >/dev/null 2>&1"; do sleep 0.5; done
newgrp www-data
umask 2
cd $APP_ROOT/courses
WEBWORK_ROOT=$APP_ROOT/webwork2 $APP_ROOT/webwork2/bin/addcourse admin --db-layout=sql_single --users=$APP_ROOT/webwork2/courses.dist/adminClasslist.lst --professors=admin
chown www-data:root -R $APP_ROOT/courses
echo "Admin course is created."
fi
# modelCourses link if not existing
if [ ! -d "$APP_ROOT/courses/modelCourse" ]; then
echo "create modelCourse subdirectory"
rm -rf $APP_ROOT/courses/modelCourse
cd $APP_ROOT/webwork2/courses.dist
cp -R modelCourse $APP_ROOT/courses/
fi
# defaultClasslist.lst and adminClasslist.lst files if not existing
if [ ! -f "$APP_ROOT/courses/defaultClasslist.lst" ]; then
echo "defaultClasslist.lst is being created"
cd $APP_ROOT/webwork2/courses.dist
cp *.lst $APP_ROOT/courses/
fi
if [ ! -f "$APP_ROOT/courses/adminClasslist.lst" ]; then
echo "adminClasslist.lst is being created"
cd $APP_ROOT/webwork2/courses.dist
cp *.lst $APP_ROOT/courses/
fi
# run OPL-update if necessary
if [ ! -f "$APP_ROOT/webwork2/htdocs/DATA/tagging-taxonomy.json" ]; then
cd $APP_ROOT/webwork2/bin
./OPL-update
fi
# generate apache2 reload config if needed
if [ $DEV -eq 1 ]; then
echo "PerlModule Apache2::Reload" > /etc/apache2/conf-enabled/apache2-reload.conf
echo "PerlInitHandler Apache2::Reload" >> /etc/apache2/conf-enabled/apache2-reload.conf
echo "Running in DEV mode..."
else
rm -f /etc/apache2/conf-enabled/apache2-reload.conf
fi
# Fix possible permission issues
echo "Fixing ownership and permissions (just in case it is needed)"
cd $APP_ROOT/webwork2
rm -rf htdocs/tmp/* # pointers which which have no target shut down the rebuild process.
# the tmp directory is rebuilt automatically at the cost of some speed.
chown -R www-data logs tmp DATA
chmod -R u+w logs tmp DATA ../courses
cd $APP_ROOT
find courses -type f -exec chown www-data:root {} \;
find courses -type d -exec chown www-data:root {} \;
echo "end fixing ownership and permissions"
# OLD: chown www-data -R $APP_ROOT/courses
# but that sometimes caused errors in Docker on Mac OS X when there was a broken symbolic link somewhere in the directory tree being processed
fi
exec "$@"