Skip to content

Instantly share code, notes, and snippets.

@jbrucker
Created November 3, 2022 14:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jbrucker/8a650cbf643231a3478100bbab7edcf9 to your computer and use it in GitHub Desktop.
Save jbrucker/8a650cbf643231a3478100bbab7edcf9 to your computer and use it in GitHub Desktop.
Bash script to configure a typical student KU Polls project
# Source (don't execute) this script in bash
# to configure a ku-polls application.
# name of your python and pip commands
PYTHON=python
PIP=pip
# preferred editor to edit .env file
EDIT=edit
# where to create the virtual environment
ENVDIR="env"
pause() {
# print a prompt message and wait for user to press ENTER
prompt="${1:-Press Enter }"
echo -n $prompt
read input
}
makesecretkey() {
# print a SECRET_KEY on the console
$PYTHON -c "from django.core.management import utils; print('SECRET_KEY =', utils.get_random_secret_key())"
}
pause "Create virtual env in $ENVDIR "
if [ ! -d $ENVDIR ]; then
$PYTHON -m venv $ENVDIR
else
echo "$ENVDIR already exists"
fi
# activate the virtual env
source $ENVDIR/bin/activate
# install dependencies
pause "Install dependencies "
if [ -f requirements.txt ]; then
$PIP install -r requirements.txt
else
echo "No requirements.txt file!"
fi
# if there is a sample.env file, then use it
if [ -f sample.env ]; then
pause "Use sample.env as .env for external settings. "
if [ -f .env ]; then
echo ".env already exists"
else
cp sample.env .env
fi
# make a secret key
echo "If you need a SECRET_KEY use this one:"
makesecretkey
pause "Edit the .env file "
$EDIT .env
fi
# run migrations
pause "Run migrations"
$PYTHON manage.py migrate
# install data fixtures
pause "Install data fixtures "
if [ -d data ]; then
$PYTHON manage.py loaddata data/*.json
else
echo "No data/ directory. The data fixtures (*.json) may be someplace else."
echo "See the project's README.md file."
fi
# run server
pause "Start server on default port (8000) "
$PYTHON manage.py runserver
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment