-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprepare.sh
executable file
·81 lines (66 loc) · 2.35 KB
/
prepare.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
#!/bin/sh -u
# Go to current directory
cd `dirname $0`
PWD=`pwd`
BASEPATH=`basename $PWD`
GIT=git
VIRTUALENV="virtualenv --system-site-packages --distribute --prompt=($BASEPATH)"
PIP="pip --timeout 30 -q --use-mirrors"
ENVDIR=env
SETTINGS_DIR=$PWD/sportschool/settings
MANAGE_PY="$ENVDIR/bin/python ./manage.py"
echo "Checking PIP and virtualenv availability"
#pip install 'pip>=1.0' 'virtualenv>=1.7.1.2'
if [ $? -eq 0 ]; then
echo 'PIP and virtualenv available'
else
echo 'Error installing PIP and virtualenv, breaking off.'
echo 'Please install PIP >= 1.0 and VirtualEnv >= 1.7.1.2 manually.'
exit 1
fi
if [ ! -d $ENVDIR ]; then
echo "Preparing virtualenv environment in $ENVDIR directory"
$VIRTUALENV $ENVDIR
$ENVDIR/bin/pip install --upgrade setuptools
fi
echo 'Installing required packages'
# Install Django first because some Django apps require Django to be fully
# installed before they will install properly.
DJANGO=`grep "Django==" requirements.txt`
$ENVDIR/bin/pip install $DJANGO
if [ $? -ne 0 ]; then
echo "Error installing $DJANGO."
exit 1
fi
if $ENVDIR/bin/pip install -r requirements.txt; then
echo 'That went alright, continue'
else
echo 'Error installing dependencies, breaking off'
exit 1
fi
LOCAL_SETTINGS=$SETTINGS_DIR/local.py
LOCAL_SETTINGS_EXAMPLE=$SETTINGS_DIR/local.py.example
if [ ! -f $LOCAL_SETTINGS ]; then
echo "No local settings file found, copying from $LOCAL_SETTINGS_EXAMPLE"
cp -v $LOCAL_SETTINGS_EXAMPLE $LOCAL_SETTINGS
fi
SECRETS_FILE=$SETTINGS_DIR/secrets.py
SECRETS_FILE_EXAMPLE=$SETTINGS_DIR/secrets.py.example
if [ ! -f $SECRETS_FILE ]; then
echo
echo "No secrets file found, copying from $SECRETS_FILE_EXAMPLE"
cp -v $SECRETS_FILE_EXAMPLE $SECRETS_FILE
echo "Generating secret key"
# Ref: https://build.opensuse.org/package/view_file?file=fix-initscript.dif&package=cobbler&project=systemsmanagement
RAND_SECRET=$(openssl rand -base64 42 | sed 's/\//\\\//g')
if [ $RAND_SECRET ]; then
# Update SECRET_KEY
sed -i "s/^SECRET_KEY.*/SECRET_KEY = \'$RAND_SECRET\'/" $SECRETS_FILE
else
echo 'Error generating secret key, breaking off.'
# Cleanup after ourselves
rm -f $SECRETS_FILE
exit 1
fi
fi
echo "Please configure your local database in $SECRETS_FILE and run './manage.py syncdb --migrate to get you started.'"