-
Notifications
You must be signed in to change notification settings - Fork 0
/
init
88 lines (75 loc) · 2.15 KB
/
init
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
80
81
82
83
84
85
86
87
88
#!/usr/bin/env bash
[[ ! -d "venv" ]] && python3 -m venv venv
\. ./venv/bin/activate
function djsecret {
echo "DJANGO_SECRET=$(python -c 'from django.core.management.utils import get_random_secret_key;print(get_random_secret_key())')"
}
function dji {
pip install -r requirements.txt
}
function djii {
pip install -Ur requirements_list.txt
}
function djg {
python manage.py collectstatic
gunicorn -w 3 -b 0.0.0.0:8000 config.wsgi
}
function dje {
find ./accounts/migrations ! -name '__init__.py' -type f -exec rm -rf {} + 2>/dev/null
rm -rf ./config/db.sqlite3 ./assets ./media ./staticfiles 2>/dev/null
cp ./.env.example ./.env
djsecret >> ./.env
./manage.py makemigrations && \
./manage.py migrate && \
( ./manage.py loaddata user.json && \
echo -e "\x1B[33m===>\x1B[0m Username: \x1B[1;32madmin\x1B[0m" && \
echo -e "\x1B[33m===>\x1B[0m Password: \x1B[1;32madmin@123\x1B[0m" ) && \
./manage.py runserver
}
function djp {
./manage.py dumpdata --exclude auth.permission --exclude contenttypes > db.json
}
function djr {
./manage.py runserver
}
function djm {
./manage.py makemigrations && ./manage.py migrate
}
function djx {
deactivate 2>/dev/null
unset -f de dd dr dm dx 2>/dev/null
[ -x "$(command -v docker)" ] && unset -f pg 2>/dev/null
}
if [ -x "$(command -v docker)" ]; then
function pg {
case $1 in
start )
docker run \
--name postgres_12_4 \
-e POSTGRES_PASSWORD=postgres \
-p 5432:5432 \
-d postgres:12.4-alpine 2>/dev/null && \
echo "PostgreSQL Container started" || \
(docker restart postgres_12_4 && echo "PostgreSQL Container restarted")
;;
stop )
docker stop postgres_12_4 && \
echo "PostgreSQL Container stopped"
;;
kill )
docker stop postgres_12_4 && \
docker rm postgres_12_4 && \
echo "PostgreSQL Container killed"
;;
stats )
docker stats postgres_12_4
;;
* )
echo "Invalid option. Available options: start|stop|kill|stats"
;;
esac
}
complete -W 'start stop kill stats' pg 2>/dev/null || \
echo "pg option: start stop kill stats. Example: pg start"
echo 'helo'
fi