quickstart.sh 2.22 KB
Newer Older
1 2
#!/bin/bash

Gilles Quenot's avatar
Gilles Quenot committed
3
# 
4
# Quick-start script for new developers
Gilles Quenot's avatar
Gilles Quenot committed
5
# Usage: from repo root as current user, `bin/quickstart.sh`
6 7
#

Gilles Quenot's avatar
Gilles Quenot committed
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
# stop execution if there's an error
set -e

if ((UID==0)); then
    echo >&2 "Thanks to use your current user to run this script, not root"
    exit 1
fi

missing_deps=()
for x in psql virtualenv pip sudo; do
    if ! type -p $x &>/dev/null; then
        missing_deps+=($x)
    fi
done

if ((${#missing_deps[@]} > 0)); then
    echo -e >&2 "You need to install these dependencies with your package manager:\n${missing_deps[@]}"
    exit 1
fi

28 29 30 31 32 33 34 35 36 37
REPOROOT=$(dirname $(dirname $0))

# Ensure we're at the root of the memopol repository
pushd $REPOROOT >/dev/null

# Create & activate python virtual environment
virtualenv memopol_env
source memopol_env/bin/activate

# Install python dependencies
38
pip install -U pip setuptools
39 40 41
pip install -e .[testing]

# Install client dependencies
42
src/memopol/bin/install_client_deps.sh
43

44
# Create pg user and database
45 46
if [ $(sudo -u postgres psql -c "select 'CNT=' || count(1) from pg_catalog.pg_user where usename='memopol';" -U postgres | grep CNT=1 | wc -l) -lt 1 ]; then
	sudo -u postgres psql -c "create user memopol with password 'memopol';" -U postgres
47
fi
48 49 50
sudo -u postgres psql -c "alter role memopol with createdb;" -U postgres
if [ $(sudo -u postgres psql -l -U postgres | egrep "^ memopol\W" | wc -l) -lt 1 ]; then
	sudo -u postgres psql -c "create database memopol with owner memopol;" -U postgres
51 52
fi

53 54 55 56 57
# Setup environment
export DJANGO_DEBUG=True
export DJANGO_SETTINGS_MODULE=memopol.settings

# Run django migration to create database
Jamesie Pic's avatar
Jamesie Pic committed
58
memopol migrate
59 60

# Import sample data
Jamesie Pic's avatar
Jamesie Pic committed
61
memopol loaddata data_sample.json
62
memopol refresh_scores
63

64 65 66
# Build index for Whoosh
memopol rebuild_index

67 68 69 70 71
echo
echo "You're all set!"
echo "To start the application run the following from the repository root ($REPOROOT):"
echo "  source memopol_env/bin/activate"
echo "  export DJANGO_DEBUG=True DJANGO_SETTINGS_MODULE=memopol.settings"
Jamesie Pic's avatar
Jamesie Pic committed
72
echo "  memopol runserver"
73 74 75 76 77 78 79 80 81
echo
echo "If you make changes, don't forget to run tests using:"
echo "  flake8 . --exclude '*/migrations,docs,static' --ignore E128"
echo "  py.test memopol representatives_positions representatives_recommendations"
echo
echo "Happy hacking ;)"
echo

popd >/dev/null