megacoffee.net Gentoo overlay - legacy mirror
We have moved to Git. This repository is only provided for compatibility with old installations. Learn how to migrate your installation here.
comparison dev-vcs/kallithea/kallithea-0.3.1.ebuild @ 134:702382d06f80
dev-vcs/kallithea: first fully working ebuild (tested with mod_wsgi)
author | Daniel Neugebauer <dneuge@energiequant.de> |
---|---|
date | Sat, 26 Mar 2016 22:44:41 +0100 |
parents | dev-vcs/kallithea/kallithea-9999.ebuild@af030a9d6541 |
children | 4f080a258623 |
comparison
equal
deleted
inserted
replaced
132:af030a9d6541 | 134:702382d06f80 |
---|---|
1 # Copyright 1999-2016 Gentoo Foundation | |
2 # Distributed under the terms of the GNU General Public License v2 | |
3 | |
4 ### NOTES ########################################################################## | |
5 # | |
6 # When updating this ebuild, comment out all workarounds and try without them first. | |
7 # Only re-enable them if they are still required. | |
8 # | |
9 # Also check that documentation URLs are still correct. | |
10 # | |
11 #################################################################################### | |
12 | |
13 EAPI="5" | |
14 PYTHON_DEPEND="2" | |
15 SUPPORT_PYTHON_ABIS="1" | |
16 | |
17 inherit user | |
18 | |
19 DESCRIPTION="a web-based frontend and middleware to Mercurial and Git repositories" | |
20 HOMEPAGE="https://kallithea-scm.org/" | |
21 SRC_URI="https://pypi.python.org/packages/source/K/Kallithea/Kallithea-${PV}.tar.bz2" | |
22 | |
23 RDEPEND="dev-python/virtualenv" | |
24 | |
25 DEPEND="${RDEPEND}" | |
26 | |
27 LICENSE="GPL-3" | |
28 SLOT="0" | |
29 KEYWORDS="~amd64 ~x86" | |
30 IUSE="" | |
31 | |
32 RESTRICT_PYTHON_ABIS="3.*" | |
33 | |
34 installDataPath="/var/lib/kallithea" | |
35 installBasePath="/opt/kallithea" | |
36 installConfigPath="/etc/kallithea" | |
37 virtualenvActivationPath="bin/activate" | |
38 | |
39 urlDocumentationSetup="http://kallithea.readthedocs.org/en/${PV}/setup.html" | |
40 urlDocumentationRhodeCode="http://kallithea.readthedocs.org/en/${PV}/readme.html#converting-from-rhodecode" | |
41 | |
42 pkg_setup() { | |
43 # create user and group | |
44 enewgroup kallithea | |
45 enewuser kallithea -1 -1 "${installDataPath}" kallithea | |
46 } | |
47 | |
48 src_unpack() { | |
49 unpack ${A} | |
50 mv Kallithea-${PV} kallithea-${PV} || die "Unexpected directory structure, aborting..." | |
51 } | |
52 | |
53 src_compile() { | |
54 # not really compiling anything | |
55 | |
56 realWorkDir=$(pwd) | |
57 | |
58 # create new virtual environment | |
59 virtualenv --no-site-packages dist/v | |
60 | |
61 # activate environment | |
62 source "dist/v/${virtualenvActivationPath}" | |
63 | |
64 # WORKAROUND: | |
65 # we need to make sure we have a current version of setuptools to install Kallithea's dependencies | |
66 pip install 'setuptools>=17.1' | |
67 | |
68 # WORKAROUND: | |
69 # _after_ installation on --config we need a certain version of paster to create the initial config file... | |
70 pip install 'PasteScript==2.0.2' | |
71 | |
72 # WORKAROUND: | |
73 # Kallithea's attempt to install Mercurial fails, so we do it first | |
74 pip install 'mercurial>=2.9,<3.8' | |
75 | |
76 # perform automatic installation, includes dependencies | |
77 echo | |
78 echo "===> output by Kallithea's setup.py" | |
79 python setup.py install | |
80 retval=$? | |
81 echo "<=== Kallithea's setup.py is done, resuming ebuild code" | |
82 echo | |
83 | |
84 # quit now if failed | |
85 if [ ${retval} -ne 0 ]; then | |
86 echo "Bad return value ${retval} from setup.py install" | |
87 exit 1 | |
88 fi | |
89 | |
90 # unzip all eggs | |
91 echo 'Unzipping all eggs...' | |
92 cd dist/v/lib/python2.7/site-packages/ || die "site-packages not found" | |
93 for eggname in *.egg; do | |
94 if [ -f "${eggname}" ]; then | |
95 mv "${eggname}" tmp.extract.zip | |
96 unzip -d "${eggname}" tmp.extract.zip | |
97 rm tmp.extract.zip | |
98 fi | |
99 done | |
100 | |
101 # TODO: remove dummy config & directory | |
102 | |
103 # create config | |
104 mkdir "${realWorkDir}/etc" | |
105 cd "${realWorkDir}/etc" | |
106 paster make-config Kallithea production.ini || die "unable to create configuration file" | |
107 | |
108 # rewrite config to refer to correct default paths | |
109 sed -i -e "s/%(here)s\(\/\(tarballcache\|data\)\)/${installDataPath//\//\\/}\1/" production.ini | |
110 sed -i -e "s/%(here)s\(\/kallithea.db\)/${installDataPath//\//\\/}\1/" production.ini | |
111 | |
112 # TODO: only log WARN by default? | |
113 | |
114 # rewrite virtualenv directory to later installation directory | |
115 oldIFS="${IFS}" | |
116 IFS=" | |
117 " | |
118 echo "Searching files that need to have paths replaced when leaving portage sandbox..." | |
119 dirtyFiles=$(grep -Ri "${realWorkDir}/dist/v" ${realWorkDir}/dist/v | grep -vE '^Binary' | cut -d':' -f1 | sort | uniq) | |
120 for dirtyFile in ${dirtyFiles}; do | |
121 echo " patching ${dirtyFile}" | |
122 sed -e "s#${realWorkDir}/dist/v#${installBasePath}#" -i "${dirtyFile}" | |
123 done | |
124 IFS="${oldIFS}" | |
125 | |
126 # create WSGI file | |
127 cd "${realWorkDir}/etc" | |
128 cp "${FILESDIR}/production.wsgi" . | |
129 sed -e "s:###BASEDIR###:${installBasePath}:" -i production.wsgi | |
130 sed -e "s:###DATADIR###:${installDataPath}:" -i production.wsgi | |
131 sed -e "s:###CONFDIR###:${installConfigPath}:" -i production.wsgi | |
132 } | |
133 | |
134 src_install() { | |
135 # QA: no need to have anything world-writable... | |
136 chmod o-w -R dist/v/lib/python2.7/site-packages/ | |
137 | |
138 # just copy the virtualenv directory to /opt/kallithea | |
139 dodir /opt | |
140 cp -aR "${S}/dist/v" "${D}${installBasePath}" | |
141 | |
142 # install configuration files to /etc/kallithea | |
143 diropts -m750 -oroot -gkallithea | |
144 insopts -m640 -oroot -gkallithea | |
145 insinto "${installConfigPath}" | |
146 doins "${S}/etc/production.ini" | |
147 insopts -m644 -oroot -gkallithea | |
148 doins "${S}/etc/production.wsgi" | |
149 | |
150 # create data directory | |
151 diropts -m2770 -okallithea -gkallithea | |
152 keepdir "${installDataPath}" | |
153 } | |
154 | |
155 pkg_postinst() { | |
156 # 1 2 3 4 5 6 7 8 | |
157 # 12345678901234567890123456789012345678901234567890123456789012345678901234567890 | |
158 einfo "An example configuration file has already been created so you don't need to run" | |
159 einfo "make-config again, see:" | |
160 einfo " ${installConfigPath}/production.ini" | |
161 einfo "" | |
162 einfo "You still need to follow Kallithea's other setup steps according to the" | |
163 einfo "instructions at:" | |
164 einfo " ${urlDocumentationSetup}" | |
165 einfo "" | |
166 einfo "When doing so, please mind that Kallithea was installed into a Python virtual" | |
167 einfo "environment that has to be \"activated\" before it can be used. To do so," | |
168 einfo "you will have to run a dedicated shell and initialize the environment by running" | |
169 einfo "" | |
170 einfo " source ${installBasePath}/${virtualenvActivationPath}" | |
171 einfo "" | |
172 #einfo "We can wrap those commands for you if you run (no prior activation needed):" | |
173 #einfo " emerge --config =${CATEGORY}/${PF}" | |
174 #einfo "" | |
175 einfo "Kallithea also provides a way to migrate your database if you are coming from" | |
176 einfo "RhodeCode 2.2 or below. Instructions can be found at:" | |
177 einfo "${urlDocumentationRhodeCode}" | |
178 einfo "" | |
179 ewarn "Bear in mind that the whole purpose of a Python virtual environment is to" | |
180 ewarn "isolate complex dependency installations from other instances installed on the" | |
181 ewarn "same system so you will have to remember to re-emerge this ebuild when" | |
182 ewarn "Kallithea's dependencies received bug and in particular security fixes (assuming" | |
183 ewarn "it allows any more recent versions to be installed)." | |
184 } | |
185 | |
186 | |
187 | |
188 | |
189 | |
190 ################################################################################################# | |
191 ### EVERYTHING BELOW WAS AN ATTEMPT TO ASSIST USERS ON SETUP BUT CALLING EDITORS NEVER WORKED ### | |
192 ### SHOULD STAY DEACTIVATED FOR NOW ### | |
193 ################################################################################################# | |
194 | |
195 | |
196 my_read_line() { | |
197 # BASH function 'read' cannot write input back to variable in correct environment | |
198 # when run by emerge so we have to do *this* instead... great... :/ | |
199 # (at least this works...) | |
200 | |
201 python -c 'import sys; print(sys.stdin.readline().strip())' | |
202 } | |
203 | |
204 config_menu() { | |
205 choice="" | |
206 | |
207 oldIFS="${IFS}" | |
208 IFS=" | |
209 " | |
210 | |
211 # 1 2 3 4 5 6 7 8 | |
212 # 12345678901234567890123456789012345678901234567890123456789012345678901234567890 | |
213 echo | |
214 echo "===============================================================================" | |
215 echo | |
216 echo "Your options:" | |
217 echo | |
218 echo " 1) create production config from template (paster make-config ...)" | |
219 echo " 2) edit production config" | |
220 echo " 3) initialize Kallithea (paster setup-db)" | |
221 echo " This will also ask for repository location and create an admin account." | |
222 echo " 0) quit" | |
223 echo " Kallithea should be able to run now, check documentation for more options" | |
224 echo " such as setting up a task queue or full text search if you need it." | |
225 echo | |
226 | |
227 echo "TERM is ${TERM}" | |
228 | |
229 while [[ ! "${choice}" =~ ^[0-3]$ ]]; do | |
230 echo -n "Your choice? " | |
231 choice=$(my_read_line) | |
232 done | |
233 | |
234 IFS="${oldIFS}" | |
235 | |
236 return ${choice} | |
237 } | |
238 | |
239 pkg_config() { | |
240 echo "Erm... You are not supposed to call --config as it has not been completed." | |
241 echo "Sorry, you will have to follow the docs yourself for now, see:" | |
242 echo " ${urlDocumentationSetup}" | |
243 echo | |
244 echo | |
245 exit 1 | |
246 | |
247 # 1 2 3 4 5 6 7 8 | |
248 # 12345678901234567890123456789012345678901234567890123456789012345678901234567890 | |
249 | |
250 echo "Kallithea setup requires following multiple steps, some of which need to be run" | |
251 echo "in the correct virtual Python environment. This script helps you running those" | |
252 echo "commands by wrapping the commands to be run inside the correct virtualenv." | |
253 echo "You may still want to read the setup instructions while running this script:" | |
254 echo | |
255 echo " ${urlDocumentationSetup}" | |
256 | |
257 # activate virtualenv | |
258 cd ${installBasePath} || die "installation is gone? (${installBasePath})" | |
259 source "${virtualenvActivationPath}" || die "failed to activate virtualenv (${installBasePath}/${virtualenvActivationPath})" | |
260 | |
261 configFileName='production.ini' | |
262 | |
263 while true; do | |
264 config_menu | |
265 choice=$? | |
266 echo | |
267 | |
268 case "${choice}" in | |
269 0) break | |
270 ;; | |
271 | |
272 1) mkdir -p "${installBasePath}/etc" | |
273 cd "${installBasePath}/etc" | |
274 | |
275 shouldCreate="y" | |
276 if [ -e "${configFileName}" ]; then | |
277 shouldCreate="" | |
278 while true; do | |
279 echo "${configFileName} already exists, overwrite?" | |
280 while [[ ! "${shouldCreate}" =~ ^[yn]$ ]]; do | |
281 echo -n "Enter y to overwrite, n to abort: " | |
282 shouldCreate=$(my_read_line) | |
283 done | |
284 done | |
285 fi | |
286 | |
287 if [ "${shouldCreate}" == 'y' ]; then | |
288 echo 'Creating configuration file...' | |
289 paster make-config Kallithea ${configFileName} | |
290 else | |
291 echo 'Aborted, configuration file has not been overwritten.' | |
292 fi | |
293 ;; | |
294 | |
295 2) iniPath="${installBasePath}/etc/${configFileName}" | |
296 | |
297 if [ ! -e "${iniPath}" ]; then | |
298 echo "config not found at ${iniPath}; did you follow step 1?" | |
299 continue | |
300 fi | |
301 | |
302 # terminal and shell need a reset or editor will be screwed up | |
303 source /etc/profile | |
304 reset | |
305 stty sane | |
306 | |
307 # open editor | |
308 if [[ "${EDITOR}" != "" ]] && [ -e "${EDITOR}" ]; then | |
309 TERM="xterm" ${EDITOR} "${iniPath}" | |
310 else | |
311 TERM="xterm" nano -w "${iniPath}" | |
312 fi | |
313 | |
314 # we better reset again... | |
315 source /etc/profile | |
316 reset | |
317 stty sane | |
318 ;; | |
319 | |
320 *) echo "invalid choice ${choice}" | |
321 ;; | |
322 esac | |
323 done | |
324 } |