#!/usr/bin/env bash HERE="$(cd "$(dirname "$0")" && pwd)" BASEDIR="$(cd "$(dirname "$1")" && pwd)" CHARS="abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(-_=+)" for ((i=0;i<${#CHARS};i++)); do ARRAY[$i]="${CHARS:i:1}"; done MSG_SUCCESS="DONE!" POETRY=0 PYTHON=0 key_gen() { for ((c=1; c<=50; c++)); do KEY="$KEY${ARRAY[$((RANDOM % 50))]}" done echo $KEY } make_env_file() { if [[ ! -f ".env" ]]; then ENV="SECRET_KEY='$(key_gen)'\n ALLOWED_HOSTS=localhost, 10.0.2.2, 127.0.0.1\n DEBUG=True\n\n #DATABASE_URL=postgres://postgres:postgres@127.0.0.1:5433/db\n\n ADMIN_USERNAME=\n ADMIN_EMAIL=\n ADMIN_PASSWORD=\n\n EMAIL_HOST=\n EMAIL_PORT=\n EMAIL_HOST_USER=\n EMAIL_HOST_PASSWORD=\n EMAIL_USE_TLS=True\n DEFAULT_FROM_EMAIL= " $(echo -e $ENV | sed -e 's/^[ \t]*//' > .env) echo "ENV FILE - $MSG_SUCCESS" fi } verify_poetry() { if command -v poetry &> /dev/null; then POETRY=1 fi } verify_python() { if command -v python3 &> /dev/null; then PYTHON=1 fi } venv_name() { if [[ -d "$BASEDIR/.venv" ]]; then echo ".venv" fi if [[ -d "$BASEDIR/venv" ]]; then echo "venv" fi } python_name() { if [[ PYTHON -eq 1 ]]; then echo "python3" else echo "python" fi } help() { awk 'BEGIN {FS="## @ "; print "Usage: make";} /^## @ / { printf "\033[31m\n" substr($1, 5) "\n";} {FS=" ## ";} /^[a-zA-Z_-]+:.*? ##/ { print "\033[33m -", $1 "\033[37m", $2}' $ARG } run() { $(venv_name)/bin/$(python_name) manage.py runserver 0.0.0.0:8000 } shell_plus() { $(venv_name)/bin/$(python_name) manage.py shell_plus } check() { $(venv_name)/bin/$(python_name) manage.py check IS_OK=$? } show_migrations() { $(venv_name)/bin/$(python_name) manage.py showmigrations } migrations() { $(venv_name)/bin/$(python_name) manage.py makemigrations } migrate() { $(venv_name)/bin/$(python_name) manage.py migrate } check() { $(venv_name)/bin/$(python_name) manage.py check } elements() { $(venv_name)/bin/$(python_name) manage.py elements } clear_migrations() { find $BASEDIR -path '*/migrations/*.py' -not -name '__init__.py' -not -path '*/.venv/*' -delete find $BASEDIR -path '*/migrations/*.pyc' -not -name '__init__.py' -not -path '*/.venv/*' -delete if [[ -f $BASEDIR/media/ ]]; then rm $BASEDIR/media/* fi if [[ -f db.sqlite3 ]];then rm db.sqlite3 fi podman pod rm -f cq_pod && podman volume prune } verify_python verify_poetry ARG=$2 $1