generated from quxdev/qjango
-
Notifications
You must be signed in to change notification settings - Fork 0
/
qjango.sh
83 lines (69 loc) · 1.83 KB
/
qjango.sh
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
account="quxdev"
repo="qjango"
function display_help {
echo "Usage: $0 [OPTIONS]"
echo "Options:"
echo " -a, --account ACCOUNT_NAME Specify account name"
echo " -r, --repo REPOSITORY_NAME Specify repository name"
echo " -h, --help Display this help message"
}
# Parse arguments
while [[ $# -gt 0 ]]; do
case "$1" in
-a|--account)
account="$2"
shift 2
;;
-r|--repo)
repo="$2"
shift 2
;;
-h|--help)
display_help
exit 0
;;
*)
echo "Unknown argument: $1"
display_help
exit 1
;;
esac
done
# Check if git is configured for use with ssh.
# ssh is our preferred method of authentication.
ssh -T git@github.com > /dev/null 2>&1
if [ $? -eq 1 ]; then
git clone git@github.com:${account}/${repo}.git
else
git clone https://github.com/${account}/${repo}.git
fi
cd ${repo}
# Update submodules
git submodule update --init
# Create virtual environment
python3.8 -m venv venv
if [[ $OSTYPE == darwin* ]]; then
sed -i '' 's/PS1=\"(venv)/PS1=\"(venv:$repo)/g' venv/bin/activate
else
sed -i 's/PS1=\"(venv)/PS1=\"(venv:$repo)/g' venv/bin/activate
fi
# Activate virtual environment
source venv/bin/activate
# Upgrade pip and install packages
pip install --upgrade pip
pip install -r requirements.txt
echo $(pwd)
echo $(which python)
# Migrate models to db.sqlite3
python manage.py migrate
# Configure project/.env
dotenv="project/.env"
if [ ! -f dotenv ]; then
touch ${dotenv}
secret=$(venv/bin/python manage.py generate_secret_key)
echo "DJANGO_SECRET_KEY=\"${secret}\"" >> ${dotenv}
echo "DJANGO_DEBUG=true" >> ${dotenv}
echo "BOOTSTRAP=bs5" >> ${dotenv}
fi
# Runserver and test
python manage.py runserver