spacepaste

  1.  
  2. set -e
  3. # make sure directory $1 doesn't exist
  4. if [[ -d $1 ]]; then
  5. echo "Directory $1 exits already. Use a different name"
  6. exit 1
  7. fi
  8. # make sure database $1 doesn't exist
  9. if sudo -i -u postgres psql -lqt | cut -d \| -f 1 | grep -qw $1; then
  10. echo "Database $1 exits already. Use a different name"
  11. exit 1
  12. fi
  13. VENV=venv
  14. virtualenv $VENV
  15. $VENV/bin/pip install "Django>=1.8,<1.9"
  16. DB_USER=$1
  17. DB_PASS=$1
  18. DB_NAME=$1
  19. sudo -i -u postgres psql -c "CREATE USER $DB_USER WITH PASSWORD '$DB_PASS';"
  20. sudo -i -u postgres psql -c "CREATE DATABASE $DB_NAME WITH OWNER $DB_USER;"
  21. sudo -i -u postgres psql -c "GRANT ALL PRIVILEGES ON DATABASE $DB_NAME TO $DB_USER;"
  22. sudo -i -u postgres psql -d $DB_NAME -c "CREATE EXTENSION postgis;"
  23. sudo -i -u postgres psql -d $DB_NAME -c "CREATE EXTENSION postgis_topology;"
  24. sudo -i -u postgres psql -d $DB_NAME -c "CREATE EXTENSION fuzzystrmatch;"
  25. sudo -i -u postgres psql -d $DB_NAME -c "CREATE EXTENSION postgis_tiger_geocoder;"
  26. $VENV/bin/django-admin.py startproject --template=https://github.com/tendenci/tendenci-project-template/archive/master.zip $1
  27. cd $1
  28. ../$VENV/bin/pip install -r requirements/dev.txt
  29. curl https://gist.githubusercontent.com/jennyq/45de71a93cff774c593d/raw/30ede14eb133de66cc839cc0458a1e915368534e/setup_keys.sh | bash
  30. sed -i "s/<DB_NAME>/$1/g" conf/local_settings.py
  31. sed -i "s/<DB_USER>/$1/g" conf/local_settings.py
  32. sed -i "s/<DB_PASS>/$1/g" conf/local_settings.py
  33. ../$VENV/bin/python manage.py migrate --noinput
  34. ../$VENV/bin/python manage.py collectstatic --noinput
  35. ../$VENV/bin/python manage.py update_settings
  36. ../$VENV/bin/python manage.py clear_theme_cache
  37. ../$VENV/bin/python manage.py populate_default_entity
  38. ../$VENV/bin/python manage.py populate_entity_and_auth_group_columns
  39. chmod -R -x+X media
  40. ../$VENV/bin/python manage.py createsuperuser --noinput --username=admin --email=admin@example.com
  41. echo "from django.contrib.auth.models import User; superuser = User.objects.get(username='admin'); superuser.set_password('admin'); superuser.save()" | ../$VENV/bin/python manage.py shell
  42. ../$VENV/bin/python manage.py runserver
  43.