summaryrefslogtreecommitdiff
path: root/tools/devsetup/dev_setup.sh
blob: de104b95f35e11e5a589425fbf2fb4c2983b0d0f (plain)
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
#!/bin/bash

set -e

if [ "$#" -ne 4 ]; then
    echo "Usage: $0 <hostname> <port> <database> <user>"
    exit
fi

PGH=$1
PGP=$2
PGD=$3
PGU=$4

echo "Host/path to postgres: $PGH"
echo "                 Port: $PGP"
echo "             Database: $PGD"
echo "                 User: $PGU"

echo "Verifying postgres connection..."
psql -w "host=$PGH port=$PGP dbname=$PGD user=$PGU" -c "SELECT 1" >/dev/null

# Start from script directory to be safe!
cd "${0%/*}"

virtualenv --python=python3 venv_dev
# Newer virtualenvs can't handle symlinks, so create a tiny binary
rm -f python
cat >../../python <<EOF
#!/bin/sh
exec $(dirname $(realpath $0))/../../tools/devsetup/venv_dev/bin/python "\$@"
EOF
chmod +x ../../python
../../python -m pip install -r dev_requirements.txt

cd ../..
cat > postgresqleu/local_settings.py <<EOF
DEBUG=True
DISABLE_HTTPS_REDIRECTS=True
DATABASES={
 'default': {
   'ENGINE': 'django.db.backends.postgresql_psycopg2',
   'NAME': '$PGD',
   'HOST': '$PGH',
   'PORT': '$PGP',
   'USER': '$PGU',
 }
}
SECRET_KEY='reallysecretbutwhocares'
SERVER_EMAIL='root@localhost'
SESSION_COOKIE_SECURE=False
CSRF_COOKIE_SECURE=False
SITEBASE="http://localhost:8012/"
EOF

./python manage.py migrate

cat tools/devsetup/devserver-uwsgi.ini.tmpl | sed -e "s#%DJANGO%#$(pwd)/tools/devsetup/venv_dev#g" > devserver-uwsgi.ini

echo ""
echo "Creating a django superuser, and setting password!"
result=`psql -A -n -q -t -w -X -h $PGH -p $PGP -d $PGD -U $PGU -c "SELECT COUNT(*) FROM public.auth_user WHERE is_superuser IS true"`
echo ""
if [ $result -eq "0" ];
then
    echo "creating a Django superuser, and setting password!"
    ./python manage.py createsuperuser
else
    echo "superuser already exists, skipping"
fi


echo "All ready to go. To start the development server, go to"
pwd
echo "and run:"
echo "uwsgi --ini devserver-uwsgi.ini"
echo ""
echo "or for a slightly more limited version:"
echo "./python manage.py runserver"