-
Notifications
You must be signed in to change notification settings - Fork 11
/
setup
executable file
·64 lines (49 loc) · 1.59 KB
/
setup
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
#!/bin/bash
#
# EDIT THE FOLLOWING VARIABLES
#
# Your database username
DBUSER=dbuser
# Your database password
DBPASS=dbpass
# Database name
DBNAME=onj
# Contest start time (by default set to 1 minute after you run setup)
# Format YYYY-MM-DD HH:MM:SS
STARTTIME=`date -d '1 minute' +"%F %H:%M:%S"`
# Contest end time (by default set to 1 hour after you run setup)
# Format YYYY-MM-DD HH:MM:SS
ENDTIME=`date -d '1 hour' +"%F %H:%M:%S"`
#
# DO NOT EDIT BELOW THIS UNLESS YOU REALLY KNOW WHAT YOU ARE DOING
#
# This sets correct permissions
chmod 777 code*
chmod 666 problems*/*/statement
chmod 755 onj
# This replaces constants in settings.php and dbinit.sql
sed -i "s/dbuser/$DBUSER/g" settings.php
sed -i "s/dbpass/$DBPASS/g" settings.php
sed -i "s/dbname/$DBNAME/g" settings.php dbinit.sql
sed -i "s/STARTTIME/$STARTTIME/g" settings.php
sed -i "s/ENDTIME/$ENDTIME/g" settings.php
# This initializes the database
if [ $DBPASS ]; then
echo "drop database $DBNAME" | mysql -u"$DBUSER" -p"$DBPASS" 2> /dev/null
mysql -u"$DBUSER" -p"$DBPASS" < dbinit.sql
else
echo "drop database $DBNAME" | mysql -u"$DBUSER" 2> /dev/null
mysql -u"$DBUSER" < dbinit.sql
fi
# This generates random strings for the code and problem directories
JUNK=$(date | md5sum | md5sum)
APPEND=${JUNK:0:20}
# Uncomment these when you want to use random strings for code and problem directories
#CODEDIR=code_$APPEND
#PROBLEMDIR=problems_$APPEND
CODEDIR=code
PROBLEMDIR=problems
sed -i "s/codedir/$CODEDIR/g" settings.php
sed -i "s/problemdir/$PROBLEMDIR/g" settings.php onj
mv code* $CODEDIR 2> /dev/null
mv problems* $PROBLEMDIR 2> /dev/null