forked from mineta/taskbuster-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtbsetup.sh
executable file
·137 lines (100 loc) · 3.37 KB
/
tbsetup.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#!/bin/bash
# webanz / [email protected]
# https://github.com/webanz/taskbuster-setup
# See
# https://github.com/mineta/taskbuster-boilerplate
# TODO #
# Add proper cmd argument handling
# Use a generated random secret
if [ "$#" -ne 4 ]; then
echo "Usage : ./tbsetup.sh project_name env_prefix python_path pip_command"
echo "Example : ./tbsetup.sh mydjango myd /usr/bin/python3 pip3 "
exit 1
fi
#Do not run as root
if [[ $EUID -eq 0 ]]; then
echo "This script must not be run as root" 1>&2
exit 1
fi
venvSh=`env | grep virtualenvwrapper.sh | awk -F= '{print $2}'`
# Source virtualenvwrapper
if [ -z $venvSh ];then
echo 'Unable to source virtualenvwrapper.sh'
exit 1
fi
source $venvSh
# Checks whether a virtualenv exist or not
existVenv() {
envName=$1
envRes=`lsvirtualenv -b | grep '^'$envName'$'`
if [ "$envRes" == "$envName" ] ; then
return 0
else
return 1
fi
}
# Taskbuster
repoUrl='https://github.com/mineta/taskbuster-boilerplate'
tb_bp='taskbuster-boilerplate'
tb_proj='taskbuster'
declare -A Ev
Ev=(['_dev']='development' ['_test']='testing')
# Command Line Arguments
project_name=$1
env_prefix=$2
python=$3
pip=$4
# TODO Generate
secret=`cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1`
# clone Repo
if [ -d ${tb_bp} ]; then
echo -e "$(tput setaf 1)Directory ${tb_bp} exist. Not cloning $repoUrl . Abort. $(tput sgr0) "
exit 1
fi
git clone $repoUrl
if [ $? -ne 0 ]; then
echo -e "$(tput setaf 1)Error clonig ${repoUrl}. Abort. $(tput sgr0)"
exit 1
fi
project_dir=${project_name}'_project'
if [ -d $project_dir ] ; then
echo -e "$(tput setaf 1)${project_dir} exist. Abort.$(tput sgr0)"
exit 1
fi
# create virtualenv and postactivate, predeactivate files
for k in ${!Ev[@]}
do
if existVenv $env_prefix$k ; then
echo "$(tput setaf 1)Virtualenv $env_prefix$k already exist. Abort.$(tput sgr0)"
exit 1
fi
mkvirtualenv -p $python $env_prefix$k
echo $VIRTUAL_ENV
echo 'export DJANGO_SETTINGS_MODULE="'$project_name.settings.${Ev[$k]}'"' > ${VIRTUAL_ENV}/bin/postactivate
echo 'export SECRET_KEY="'$secret'"' >> ${VIRTUAL_ENV}/bin/postactivate
echo 'unset SECRET_KEY' > ${VIRTUAL_ENV}/bin/predeactivate
deactivate
echo $VIRTUAL_ENV
done
# Move taskbuster-boilerplate to target dir
mv ${tb_bp} ${project_dir}
# rename project
mv ${project_dir}/${tb_proj} ${project_dir}/${project_name}
urls="'"${project_name}.urls"'"
wsgi="'"${project_name}.wsgi.application"'"
settings="${project_name}.settings"
sed -i "s/ROOT_URLCONF = 'taskbuster.urls'/ROOT_URLCONF = ${urls}/g" \
${project_dir}/${project_name}/settings/base.py
sed -i "s/WSGI_APPLICATION = 'taskbuster.wsgi.application'/WSGI_APPLICATION = ${wsgi}/g" \
${project_dir}/${project_name}/settings/base.py
sed -i 's/os.environ.setdefault("DJANGO_SETTINGS_MODULE", "taskbuster.settings")/os.environ.setdefault("DJANGO_SETTINGS_MODULE","'${settings}'")/g' \
${project_dir}/${project_name}/wsgi.py
sed -i 's/os.environ.setdefault("DJANGO_SETTINGS_MODULE", "taskbuster.settings")/os.environ.setdefault("DJANGO_SETTINGS_MODULE","'${settings}'")/g' \
${project_dir}/manage.py
workon ${env_prefix}_dev
$pip install -r ${project_dir}/requirements/development.txt
deactivate
workon ${env_prefix}_test
$pip install -r ${project_dir}/requirements/testing.txt
deactivate
mv ${project_dir} .. #