forked from creativecommons/creativecommons.org
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup_engine.sh
executable file
·129 lines (112 loc) · 3.38 KB
/
setup_engine.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
#!/bin/bash
#
# This script:
# 1. Clones cc.engine and related respositories
# - Checks out ARG1 branch (if specified)
# 2. Creates symlinks to support the semantic web
# 3. Creates Python Environment via pipenv
# 4. Generate ccengine.fcgi and copies config.ini into python_env
# 5. Compiles mo files and transstats
# - Creates transstats.csv convenience symlink
set -o errexit
set -o errtrace
set -o nounset
trap '_es=${?};
printf "${0}: line ${LINENO}: \"${BASH_COMMAND}\"";
printf " exited with a status of ${_es}\n";
exit ${_es}' ERR
BRANCH="${1:-master}"
DIR_SCRIPT="${0%/*}"
DIR_TOP="$(python -c \
'import os.path, sys; print(os.path.normpath(sys.argv[1]))' \
"${DIR_SCRIPT}/..")"
DIR_ABS_TOP="$(python -c \
'import os.path, sys; print(os.path.realpath(sys.argv[1]))' "${DIR_TOP}")"
# Change directory to project root
pushd "${DIR_TOP}" >/dev/null
###############################################################################
# Clone/Update Repositories
pushd python_src >/dev/null
REPOS=(cc.engine cc.i18n cc.license cc.licenserdf rdfadict)
for _repo in "${REPOS[@]}"
do
echo "${_repo}"
if [[ ! -d "${_repo}" ]]
then
git clone "https://github.com/creativecommons/${_repo}.git"
pushd "${_repo}">/dev/null
for _script in ../post-clone.d/*
do
[[ -x "${_script}" ]] || continue
"${_script}"
done
popd >/dev/null
fi
pushd "${_repo}">/dev/null
git pull
git checkout ${BRANCH}
echo
popd >/dev/null
done
# return from python_src
popd >/dev/null
###############################################################################
# Support the semantic web
echo 'Create symlinks to support the semantic web'
ln -fns python_src/cc.licenserdf \
docroot/cc.licenserdf
ln -fns docroot/cc.licenserdf/cc/licenserdf/rdf \
docroot/rdf
ln -fns ${DIR_TOP}/docroot/cc.licenserdf/cc/licenserdf/licenses \
/docroot/license_rdf
echo
###############################################################################
# Create Python Environment
if [[ ! -d .venv ]]
then
echo 'ERROR: missing .venv directory' 1>&2
exit 1
fi
if [[ -f .venv/.project ]]
then
echo '*skipping* Create Python Environment (already exists)'
else
pipenv install
fi
echo
###############################################################################
# Generate ccengine.fcgi
if [[ -f python_env/bin/ccengine.fcgi ]]
then
echo '*skipping* Generate ccengine.fcgi (already exists)'
else
echo 'Generate ccengine.fcgi'
sed -e "s|@env_dir@|${DIR_ABS_TOP}/python_env|" \
< "python_src/bin/ccengine.fcgi.in" \
> "python_env/bin/ccengine.fcgi"
chmod 755 python_env/bin/ccengine.fcgi
fi
echo
if [[ -f python_env/config.ini ]]
then
echo '*skipping* Copy config.ini into Python environment (already exists)'
else
echo 'Copy config.ini into Python environment'
cp python_src/config.ini python_env/config.ini
fi
echo
###############################################################################
# compile_mo & transstats are needed by cc.engine at runtime, run them now
echo 'Run compile_mo'
pipenv run compile_mo
echo
echo 'Run transstats'
pipenv run transstats
echo
echo 'Create transstats.csv convenience symlink'
ln -fns python_src/cc.i18n/cc/i18n/transstats.csv .
echo
###############################################################################
# Done!
# return from DIR_TOP
popd >/dev/null