Skip to content

Commit

Permalink
Added more configuration/setup files
Browse files Browse the repository at this point in the history
  • Loading branch information
dlareau committed Apr 3, 2018
1 parent 064c306 commit 9631c25
Show file tree
Hide file tree
Showing 4 changed files with 223 additions and 0 deletions.
92 changes: 92 additions & 0 deletions config/easy_setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
#!/bin/bash

# Setup script. Debian (and variant) specific
# Meant for dead simple setup on debian based systems.
# You should probably change the MYSQL_ROOT_PASSWORD variable...

# Variables
MYSQL_ROOT_PASSWORD=wrongbaa
MYSQL_NORMAL_USER=hunt
MYSQL_NORMAL_PASSWORD=$(head /dev/urandom | LC_ALL=C tr -dc 'A-Za-z0-9!@#$%^&*(\-_=+)' | head -c 16)
MYSQL_PUZZLEHUNT_DB=puzzlehunt_db

# Helper functions
yell() { echo "$0: $*" >&2; }
die() { yell "$*"; cd ~puzzlehunt; rm -rf puzzlehunt_server; exit 111; }
try() { "$@" || die "cannot $*"; }

# Create puzzlehunt user

getent passwd puzzlehunt > /dev/null 2&>1
if [ $? -eq 0 ]; then
echo "Puzzlehunt User already exists"
else
try adduser --gecos "" --disabled-password puzzlehunt
fi

# Need git to kick off the process
try apt-get update
try apt-get install -y git

# Get the git repository
try cd ~puzzlehunt
try git clone https://github.com/dlareau/puzzlehunt_server.git
try cd puzzlehunt_server

# Make sure we don't get prompted for anything
try export DEBIAN_FRONTEND="noninteractive"
try debconf-set-selections <<< "mysql-server mysql-server/root_password password $MYSQL_ROOT_PASSWORD"
try debconf-set-selections <<< "mysql-server mysql-server/root_password_again password $MYSQL_ROOT_PASSWORD"

# Get all basic system packages
try apt-get install -y mysql-client mysql-server libmysqlclient-dev python-dev python-mysqldb python-pip apache2 libapache2-mod-xsendfile libapache2-mod-wsgi

apt-get install -y libapache2-mod-proxy-html || true

# Set up MYSQL user and database
try mysql -uroot -p$MYSQL_ROOT_PASSWORD -e "CREATE DATABASE IF NOT EXISTS $MYSQL_PUZZLEHUNT_DB"
try mysql -uroot -p$MYSQL_ROOT_PASSWORD -e "grant all privileges on $MYSQL_PUZZLEHUNT_DB.* to '$MYSQL_NORMAL_USER'@'localhost' identified by '$MYSQL_NORMAL_PASSWORD'"

# Configure application (Consider this the same as modifying secret_settings.py.template)
try cat > puzzlehunt_server/secret_settings.py <<EOF
SECRET_KEY = '$(head /dev/urandom | LC_ALL=C tr -dc 'A-Za-z0-9!@#$%^&*(\-_=+)' | head -c 50)'
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': '$MYSQL_PUZZLEHUNT_DB',
'HOST': 'localhost',
'PORT': '3306',
'USER': '$MYSQL_NORMAL_USER',
'PASSWORD': '$MYSQL_NORMAL_PASSWORD',
}
}
INTERNAL_IPS = ''
EMAIL_HOST_USER = ''
EMAIL_HOST_PASSWORD = ''
EOF

# Get all python dependencies and setup virtual environment
try pip install virtualenv
try virtualenv venv
try source venv/bin/activate
try pip install -r requirements.txt

# Run application setup commands
try python manage.py migrate
try python manage.py collectstatic --noinput
try git checkout development # Only needed until test branch is merged
#try python manage.py loaddata initial_hunt.json
try deactivate

# We are root until this point, pass off ownership of all we have created
try chown -R puzzlehunt .

# Apache hosting setup
try a2enmod proxy
try a2enmod proxy_http
try a2enmod proxy_html
try a2enmod xsendfile
try a2enmod wsgi
rm /etc/apache2/sites-enabled/*
try cp config/puzzlehunt.conf /etc/apache2/sites-enabled/
try service apache2 restart
46 changes: 46 additions & 0 deletions config/initial_hunt.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
[
{
"fields": {
"username": "hunt",
"first_name": "Root",
"last_name": "User",
"is_active": true,
"is_superuser": true,
"is_staff": true,
"last_login": "2017-12-29T16:25:54Z",
"groups": [],
"user_permissions": [],
"password": "pbkdf2_sha256$20000$GLdG9P4Fdk25$/MUEQESmazezJ8xe6A87Jm5sBl/JIhk3skYQD20Dnn8=",
"email": "example@example.com",
"date_joined": "2017-12-27T18:39:26Z"
},
"model": "auth.user",
"pk": 1
},
{
"fields": {
"is_shib_acct": false,
"allergies": "",
"comments": "",
"teams": [],
"phone": "000-000-0000",
"user": 1
},
"model": "huntserver.person",
"pk": 1
},
{
"fields": {
"team_size": 5,
"end_date": "2000-01-02T05:00:00Z",
"hunt_name": "Example Hunt 1",
"is_current_hunt": true,
"location": "Example Location 1",
"template": "{% extends \"hunt_base.html\" %}\r\n{% block title %}Puzzles 1{% endblock title %}\r\n\r\n{% block content %}\r\nExample Template 1\r\n{% endblock content %}",
"hunt_number": 1,
"start_date": "2000-01-01T05:00:00Z"
},
"model": "huntserver.hunt",
"pk": 1
}
]
3 changes: 3 additions & 0 deletions config/puzzlehunt.conf
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# CMU specific configuration file for apache
# contains configuration for SSL and shibboleth

NameVirtualHost *:80
<VirtualHost *:80>
ServerName puzzlehunt.club.cc.cmu.edu
Expand Down
82 changes: 82 additions & 0 deletions config/puzzlehunt_setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
#!/bin/bash

# A setup file for rapid setup of a development environment in
# conjunction with vagrant. Debian specific.

# Variables
MYSQL_ROOT_PASSWORD=wrongbaa
MYSQL_NORMAL_USER=hunt
MYSQL_NORMAL_PASSWORD=puzzlehunt
MYSQL_PUZZLEHUNT_DB=puzzlehunt_db

# Make sure we don't get prompted for anything
export DEBIAN_FRONTEND="noninteractive"
debconf-set-selections <<< "mysql-server mysql-server/root_password password $MYSQL_ROOT_PASSWORD"
debconf-set-selections <<< "mysql-server mysql-server/root_password_again password $MYSQL_ROOT_PASSWORD"

# Get all basic system packages
apt-get update
apt-get install -y git
apt-get install -y mysql-client
apt-get install -y mysql-server
apt-get install -y libmysqlclient-dev
apt-get install -y python-dev
apt-get install -y python-mysqldb
apt-get install -y python-pip

# Get the git repository and link it for external access
cd /vagrant
rm -rf puzzlehunt_server
git clone https://github.com/dlareau/puzzlehunt_server.git
ln -s /vagrant/puzzlehunt_server /home/vagrant/puzzlehunt_server
cd /home/vagrant/puzzlehunt_server

# Get all python dependencies and setup virtual environment
pip install virtualenv
virtualenv venv
source venv/bin/activate
pip install -r requirements.txt

# Set up MYSQL user and database
mysql -uroot -p$MYSQL_ROOT_PASSWORD -e "CREATE DATABASE $MYSQL_PUZZLEHUNT_DB"
mysql -uroot -p$MYSQL_ROOT_PASSWORD -e "grant all privileges on $MYSQL_PUZZLEHUNT_DB.* to '$MYSQL_NORMAL_USER'@'localhost' identified by '$MYSQL_NORMAL_PASSWORD'"

# Configure application (Consider this the same as modifying secret_settings.py.template)
cat > puzzlehunt_server/secret_settings.py <<EOF
SECRET_KEY = 'this is not the secret key, use your own'
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': '$MYSQL_PUZZLEHUNT_DB',
'HOST': 'localhost',
'PORT': '3306',
'USER': '$MYSQL_NORMAL_USER',
'PASSWORD': '$MYSQL_NORMAL_PASSWORD',
}
}
INTERNAL_IPS = ''
EMAIL_HOST_USER = ''
EMAIL_HOST_PASSWORD = ''
EOF

# Run application setup commands
python manage.py migrate
python manage.py collectstatic --noinput
git checkout development # Only needed until test branch is merged
python manage.py loaddata /vagrant/initial_hunt.json

# We are root until this point, pass off ownership of all we have created
chown -R vagrant .

# Apache hosting setup
apt-get install -y apache2
apt-get install -y libapache2-mod-xsendfile
apt-get install -y libapache2-mod-proxy-html
apt-get install -y libapache2-mod-wsgi
a2enmod proxy
a2enmod proxy_http
a2enmod proxy_html
a2enmod xsendfile
a2enmod wsgi
cp /vagrant/puzzlehunt.conf /etc/apache2/sites-enabled/
service apache2 restart

0 comments on commit 9631c25

Please sign in to comment.