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 @ 145:b4ad250ded02
merge
author | Daniel Neugebauer <dneuge@energiequant.de> |
---|---|
date | Mon, 28 Mar 2016 21:22:53 +0200 |
parents | dev-vcs/kallithea/kallithea-9999.ebuild@fa6d2de366ac dev-vcs/kallithea/kallithea-9999.ebuild@b4939be30911 |
children | 28f6280ecbce |
comparison
equal
deleted
inserted
replaced
133:fa6d2de366ac | 145:b4ad250ded02 |
---|---|
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 IUSE="+git mysql postgres sqlite" | |
24 REQUIRED_USE="|| ( mysql postgres sqlite )" | |
25 | |
26 RDEPEND=" | |
27 dev-python/virtualenv | |
28 git? ( dev-vcs/git ) | |
29 mysql? ( dev-db/mysql ) | |
30 postgres? ( dev-db/postgresql ) | |
31 sqlite? ( dev-lang/python:2.7[sqlite] ) | |
32 " | |
33 #mysql? ( virtual/libmysqlclient ) | |
34 | |
35 DEPEND="${RDEPEND} | |
36 app-arch/unzip | |
37 sys-apps/sed" | |
38 | |
39 LICENSE="GPL-3" | |
40 SLOT="0" | |
41 KEYWORDS="~amd64 ~x86" | |
42 | |
43 RESTRICT_PYTHON_ABIS="3.*" | |
44 | |
45 installDataPath="/var/lib/kallithea" | |
46 installBasePath="/opt/kallithea" | |
47 installConfigPath="/etc/kallithea" | |
48 virtualenvActivationPath="bin/activate" | |
49 | |
50 urlDocumentationSetup="http://kallithea.readthedocs.org/en/${PV}/setup.html" | |
51 urlDocumentationRhodeCode="http://kallithea.readthedocs.org/en/${PV}/readme.html#converting-from-rhodecode" | |
52 urlDocumentationMegacoffee="http://gentoo-overlay.megacoffee.net/s/docs-kallithea-apache-mod_wsgi" | |
53 | |
54 pkg_setup() { | |
55 # create user and group | |
56 enewgroup kallithea | |
57 enewuser kallithea -1 -1 "${installDataPath}" kallithea | |
58 } | |
59 | |
60 src_unpack() { | |
61 unpack ${A} | |
62 mv Kallithea-${PV} kallithea-${PV} || die "Unexpected directory structure, aborting..." | |
63 } | |
64 | |
65 src_compile() { | |
66 # not really compiling anything | |
67 | |
68 realWorkDir=$(pwd) | |
69 | |
70 # create new virtual environment | |
71 virtualenv --python=python2.7 --no-site-packages dist/v | |
72 | |
73 # activate environment | |
74 source "dist/v/${virtualenvActivationPath}" | |
75 | |
76 # WORKAROUND: | |
77 # we need to make sure we have a current version of setuptools to install Kallithea's dependencies | |
78 pip2.7 install 'setuptools>=17.1' || die "Failed to install setuptools, aborting!" | |
79 | |
80 # WORKAROUND: | |
81 # _after_ installation on --config we need a certain version of paster to create the initial config file... | |
82 pip2.7 install 'PasteScript==2.0.2' || die "Failed to install PasteScript, aborting!" | |
83 | |
84 # WORKAROUND: | |
85 # Kallithea's attempt to install Mercurial fails, so we do it first | |
86 pip2.7 install 'mercurial>=2.9,<3.8' || die "Failed to install Mercurial, aborting!" | |
87 | |
88 # WORKAROUND: | |
89 # Kallithea needs psycopg2 for PostgreSQL support which is not currently listed as a dependency?! | |
90 # at the time of writing 2.6.1 is current, so we limit the version to <2.7 | |
91 if use postgres ; then | |
92 pip2.7 install 'psycopg2>=2.6,<2.7' || die "Failed to install psycopg2 (required for PostgreSQL support), aborting!" | |
93 fi | |
94 | |
95 # WORKAROUND: | |
96 # Kallithea needs MySQLdb for MySQL support which is not currently listed as a dependency?! | |
97 # at the time of writing 1.2.5 is current, so we limit the version to <1.3 | |
98 if use mysql ; then | |
99 pip2.7 install 'MySQL-python>=1.2,<1.3' || die "Failed to install MySQL-python (required for MySQL support), aborting!" | |
100 fi | |
101 | |
102 # perform automatic installation, includes dependencies | |
103 echo | |
104 echo "===> output by Kallithea's setup.py" | |
105 python2.7 setup.py install | |
106 retval=$? | |
107 echo "<=== Kallithea's setup.py is done, resuming ebuild code" | |
108 echo | |
109 | |
110 # quit now if failed | |
111 if [ ${retval} -ne 0 ]; then | |
112 echo "Bad return value ${retval} from setup.py install" | |
113 exit 1 | |
114 fi | |
115 | |
116 # unzip all eggs | |
117 echo 'Unzipping all eggs...' | |
118 cd dist/v/lib/python2.7/site-packages/ || die "site-packages not found" | |
119 for eggname in *.egg; do | |
120 if [ -f "${eggname}" ]; then | |
121 mv "${eggname}" tmp.extract.zip | |
122 unzip -d "${eggname}" tmp.extract.zip | |
123 rm tmp.extract.zip | |
124 fi | |
125 done | |
126 | |
127 # disable Git support according to manual | |
128 # see: http://kallithea.readthedocs.org/en/0.3.1/usage/vcs_support.html | |
129 if ! use git ; then | |
130 sed -i -e "/^BACKENDS\s*=\s*{/,/}/ s/^\(\s*\)\('git'\)/\1#\2/" Kallithea-${PV}-py2.7.egg/kallithea/__init__.py || die 'Failed to disable git support, aborting...' | |
131 fi | |
132 | |
133 # create config | |
134 mkdir "${realWorkDir}/etc" | |
135 cd "${realWorkDir}/etc" | |
136 paster make-config Kallithea production.ini || die "unable to create configuration file" | |
137 | |
138 # rewrite config to refer to correct default paths | |
139 sed -i -e "s/%(here)s\(\/\(tarballcache\|data\)\)/${installDataPath//\//\\/}\1/" production.ini | |
140 sed -i -e "s/%(here)s\(\/kallithea.db\)/${installDataPath//\//\\/}\1/" production.ini | |
141 | |
142 # rewrite config to only log from WARN level to "console" | |
143 # By Kallithea defaults, handler_console logs everything from INFO level to "console". | |
144 # As mod_wsgi logs everything from "console" to error_log this results in a huge amount | |
145 # of unnecessary log entries which we would like to prevent. | |
146 # NOTE: As sed syntax is hard to read... this replacement rule is prefixed with an "address" which | |
147 # is being defined by two regexps, effectively restricting replacements just to the | |
148 # handler_console section of our ini file. | |
149 sed -i -e '/^\[handler_console\]/,/^\[/ s/level\s*=\s*INFO/level = WARN/' production.ini | |
150 | |
151 # rewrite config to disable debug mode | |
152 # By default, Kallithea uses debug = true which should *NOT* be used except during development. | |
153 # See: http://kallithea.readthedocs.org/en/0.3.1/usage/debugging.html | |
154 sed -i -e '/^\[DEFAULT\]/,/^\[/ s/\(debug\s*=\s*\)true/\1false/' production.ini | |
155 | |
156 ## (disabled, does not work from sandbox) | |
157 ## maintain system-unique variables from previous production.ini if available | |
158 #previousProductionConfig="${installConfigPath}/production.ini" | |
159 #if [ -e "${previousProductionConfig}" ]; then | |
160 # previousAppInstanceUUID="$(grep -oE '^\s*app_instance_uuid\s*=\s*[0-9a-f\-]+' /etc/kallithea/production.ini | cut -d'=' -f2 | tr -d ' ')" | |
161 # previousBeakerSessionSecret="$(grep -oE '^\s*beaker\.session\.secret\s*=\s*[0-9a-f\-]+' "${previousProductionConfig}" | cut -d'=' -f2 | tr -d ' ')" | |
162 # | |
163 # if [ ! -z "${previousAppInstanceUUID}" ]; then | |
164 # echo 'Transferring previous app instance UUID to new production.ini' | |
165 # sed -i -e "s/^\(\s*app_instance_uuid\s*=\s*\).*/\1${previousAppInstanceUUID}/" production.ini | |
166 # fi | |
167 # | |
168 # if [ ! -z "${previousBeakerSessionSecret}" ]; then | |
169 # echo 'Transferring previous Beaker session secret to new production.ini' | |
170 # sed -i -e "s/^\(\s*beaker\.session\.secret\s*=\s*\).*/\1${previousBeakerSessionSecret}/" production.ini | |
171 # fi | |
172 #fi | |
173 | |
174 # remove newly generated UUID and Beaker session secret from config | |
175 # as user should configure that instead and config diffs don't show | |
176 # unnecessary stuff | |
177 sed -i -e "s/^\(\s*app_instance_uuid\s*=\).*/#\1 (run uuidgen and insert the returned UUID here)/" production.ini | |
178 sed -i -e "s/^\(\s*beaker\.session\.secret\s*=\).*/#\1 (run uuidgen and insert the returned UUID here)/" production.ini | |
179 | |
180 # comment out sqlite DB as we don't want users to use it by accident | |
181 sed -i -e 's/^\(\s*\)\(sqlalchemy\.db1\.url\s*=\s*sqlite:.*\)/\1#\2/' production.ini | |
182 | |
183 # rename production.ini as it requires more configuration and is hard to read | |
184 mv production.ini production.ini.example | |
185 | |
186 # rewrite virtualenv directory to later installation directory | |
187 oldIFS="${IFS}" | |
188 IFS=" | |
189 " | |
190 echo "Searching files that need to have paths replaced when leaving portage sandbox..." | |
191 dirtyFiles=$(grep -Ri "${realWorkDir}/dist/v" ${realWorkDir}/dist/v | grep -vE '^Binary' | cut -d':' -f1 | sort | uniq) | |
192 for dirtyFile in ${dirtyFiles}; do | |
193 echo " patching ${dirtyFile}" | |
194 sed -e "s#${realWorkDir}/dist/v#${installBasePath}#" -i "${dirtyFile}" | |
195 done | |
196 IFS="${oldIFS}" | |
197 | |
198 # create WSGI file | |
199 cd "${realWorkDir}/etc" | |
200 cp "${FILESDIR}/production.wsgi" . | |
201 sed -e "s:###BASEDIR###:${installBasePath}:" -i production.wsgi | |
202 sed -e "s:###DATADIR###:${installDataPath}:" -i production.wsgi | |
203 sed -e "s:###CONFDIR###:${installConfigPath}:" -i production.wsgi | |
204 } | |
205 | |
206 src_install() { | |
207 # QA: no need to have anything world-writable... | |
208 chmod o-w -R dist/v/lib/python2.7/site-packages/ | |
209 | |
210 # just copy the virtualenv directory to /opt/kallithea | |
211 dodir /opt | |
212 cp -aR "${S}/dist/v" "${D}${installBasePath}" | |
213 | |
214 # install configuration files to /etc/kallithea | |
215 diropts -m750 -oroot -gkallithea | |
216 insopts -m640 -oroot -gkallithea | |
217 insinto "${installConfigPath}" | |
218 doins "${S}/etc/production.ini.example" | |
219 insopts -m644 -oroot -gkallithea | |
220 doins "${S}/etc/production.wsgi" | |
221 | |
222 # create data directory and subdirectories | |
223 diropts -m2770 -okallithea -gkallithea | |
224 keepdir "${installDataPath}" | |
225 keepdir "${installDataPath}/data" | |
226 keepdir "${installDataPath}/data/cache" | |
227 keepdir "${installDataPath}/data/cache/data" | |
228 keepdir "${installDataPath}/data/cache/lock" | |
229 keepdir "${installDataPath}/data/index" | |
230 keepdir "${installDataPath}/repositories" | |
231 keepdir "${installDataPath}/tarballcache" | |
232 } | |
233 | |
234 pkg_postinst() { | |
235 # 1 2 3 4 5 6 7 8 | |
236 # 12345678901234567890123456789012345678901234567890123456789012345678901234567890 | |
237 elog "An example configuration file has already been created so you don't need to run" | |
238 elog "make-config again; please copy and edit carefully on first setup:" | |
239 elog " cp -a ${installConfigPath}/production.ini.example ${installConfigPath}/production.ini" | |
240 elog " \$EDITOR ${installConfigPath}/production.ini" | |
241 elog "" | |
242 elog "After updates, please compare what has changed and copy any necessary changes:" | |
243 elog " diff -u ${installConfigPath}/production.ini ${installConfigPath}/production.ini.example" | |
244 elog "" | |
245 elog "You still need to follow Kallithea's other setup steps according to the" | |
246 elog "instructions at:" | |
247 elog " ${urlDocumentationSetup}" | |
248 elog "" | |
249 elog "When doing so, please mind that Kallithea was installed into a Python virtual" | |
250 elog "environment that has to be \"activated\" before it can be used. To do so," | |
251 elog "you will have to run a dedicated shell and initialize the environment by running" | |
252 elog "" | |
253 elog " source ${installBasePath}/${virtualenvActivationPath}" | |
254 elog "" | |
255 elog "We altered the default config slightly. It may be best to have a look at our" | |
256 elog "short example on how to setup hosting with Apache and mod_wsgi, even if you" | |
257 elog "prefer another method of hosting Kallithea:" | |
258 elog " ${urlDocumentationMegacoffee}" | |
259 elog "" | |
260 #elog "We can wrap those commands for you if you run (no prior activation needed):" | |
261 #elog " emerge --config =${CATEGORY}/${PF}" | |
262 #elog "" | |
263 elog "Kallithea also provides a way to migrate your database if you are coming from" | |
264 elog "RhodeCode 2.2 or below. Instructions can be found at:" | |
265 elog "${urlDocumentationRhodeCode}" | |
266 elog "" | |
267 ewarn "Bear in mind that the whole purpose of a Python virtual environment is to" | |
268 ewarn "isolate complex dependency installations from other instances installed on the" | |
269 ewarn "same system so you will have to remember to re-emerge this ebuild when" | |
270 ewarn "Kallithea's dependencies received bug and in particular security fixes (assuming" | |
271 ewarn "it allows any more recent versions to be installed)." | |
272 | |
273 if use sqlite ; then | |
274 ewarn "" | |
275 ewarn "You chose to use SQLite for Kallithea. Please be advised that this is *ONLY* for" | |
276 ewarn "testing purposes, please avoid using SQLite in production and choose a different" | |
277 ewarn "database instead." | |
278 fi | |
279 } | |
280 | |
281 | |
282 | |
283 | |
284 | |
285 ################################################################################################# | |
286 ### EVERYTHING BELOW WAS AN ATTEMPT TO ASSIST USERS ON SETUP BUT CALLING EDITORS NEVER WORKED ### | |
287 ### SHOULD STAY DEACTIVATED FOR NOW ### | |
288 ################################################################################################# | |
289 | |
290 | |
291 my_read_line() { | |
292 # BASH function 'read' cannot write input back to variable in correct environment | |
293 # when run by emerge so we have to do *this* instead... great... :/ | |
294 # (at least this works...) | |
295 | |
296 python -c 'import sys; print(sys.stdin.readline().strip())' | |
297 } | |
298 | |
299 config_menu() { | |
300 choice="" | |
301 | |
302 oldIFS="${IFS}" | |
303 IFS=" | |
304 " | |
305 | |
306 # 1 2 3 4 5 6 7 8 | |
307 # 12345678901234567890123456789012345678901234567890123456789012345678901234567890 | |
308 echo | |
309 echo "===============================================================================" | |
310 echo | |
311 echo "Your options:" | |
312 echo | |
313 echo " 1) create production config from template (paster make-config ...)" | |
314 echo " 2) edit production config" | |
315 echo " 3) initialize Kallithea (paster setup-db)" | |
316 echo " This will also ask for repository location and create an admin account." | |
317 echo " 0) quit" | |
318 echo " Kallithea should be able to run now, check documentation for more options" | |
319 echo " such as setting up a task queue or full text search if you need it." | |
320 echo | |
321 | |
322 echo "TERM is ${TERM}" | |
323 | |
324 while [[ ! "${choice}" =~ ^[0-3]$ ]]; do | |
325 echo -n "Your choice? " | |
326 choice=$(my_read_line) | |
327 done | |
328 | |
329 IFS="${oldIFS}" | |
330 | |
331 return ${choice} | |
332 } | |
333 | |
334 pkg_config() { | |
335 echo "Erm... You are not supposed to call --config as it has not been completed." | |
336 echo "Sorry, you will have to follow the docs yourself for now, see:" | |
337 echo " ${urlDocumentationSetup}" | |
338 echo | |
339 echo | |
340 exit 1 | |
341 | |
342 # 1 2 3 4 5 6 7 8 | |
343 # 12345678901234567890123456789012345678901234567890123456789012345678901234567890 | |
344 | |
345 echo "Kallithea setup requires following multiple steps, some of which need to be run" | |
346 echo "in the correct virtual Python environment. This script helps you running those" | |
347 echo "commands by wrapping the commands to be run inside the correct virtualenv." | |
348 echo "You may still want to read the setup instructions while running this script:" | |
349 echo | |
350 echo " ${urlDocumentationSetup}" | |
351 | |
352 # activate virtualenv | |
353 cd ${installBasePath} || die "installation is gone? (${installBasePath})" | |
354 source "${virtualenvActivationPath}" || die "failed to activate virtualenv (${installBasePath}/${virtualenvActivationPath})" | |
355 | |
356 configFileName='production.ini' | |
357 | |
358 while true; do | |
359 config_menu | |
360 choice=$? | |
361 echo | |
362 | |
363 case "${choice}" in | |
364 0) break | |
365 ;; | |
366 | |
367 1) mkdir -p "${installBasePath}/etc" | |
368 cd "${installBasePath}/etc" | |
369 | |
370 shouldCreate="y" | |
371 if [ -e "${configFileName}" ]; then | |
372 shouldCreate="" | |
373 while true; do | |
374 echo "${configFileName} already exists, overwrite?" | |
375 while [[ ! "${shouldCreate}" =~ ^[yn]$ ]]; do | |
376 echo -n "Enter y to overwrite, n to abort: " | |
377 shouldCreate=$(my_read_line) | |
378 done | |
379 done | |
380 fi | |
381 | |
382 if [ "${shouldCreate}" == 'y' ]; then | |
383 echo 'Creating configuration file...' | |
384 paster make-config Kallithea ${configFileName} | |
385 else | |
386 echo 'Aborted, configuration file has not been overwritten.' | |
387 fi | |
388 ;; | |
389 | |
390 2) iniPath="${installBasePath}/etc/${configFileName}" | |
391 | |
392 if [ ! -e "${iniPath}" ]; then | |
393 echo "config not found at ${iniPath}; did you follow step 1?" | |
394 continue | |
395 fi | |
396 | |
397 # terminal and shell need a reset or editor will be screwed up | |
398 source /etc/profile | |
399 reset | |
400 stty sane | |
401 | |
402 # open editor | |
403 if [[ "${EDITOR}" != "" ]] && [ -e "${EDITOR}" ]; then | |
404 TERM="xterm" ${EDITOR} "${iniPath}" | |
405 else | |
406 TERM="xterm" nano -w "${iniPath}" | |
407 fi | |
408 | |
409 # we better reset again... | |
410 source /etc/profile | |
411 reset | |
412 stty sane | |
413 ;; | |
414 | |
415 *) echo "invalid choice ${choice}" | |
416 ;; | |
417 esac | |
418 done | |
419 } |