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.6.ebuild @ 220:5fc6acd937e1

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