/[gentoo-x86]/eclass/mysql-v2.eclass
Gentoo

Contents of /eclass/mysql-v2.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.26 - (hide annotations) (download)
Wed Jan 8 06:20:29 2014 UTC (6 months, 2 weeks ago) by vapier
Branch: MAIN
Changes since 1.25: +2 -2 lines
Inherit the user eclass for enewuser/etc...

1 jmbsvicetto 1.12 # Copyright 1999-2012 Gentoo Foundation
2 robbat2 1.1 # Distributed under the terms of the GNU General Public License v2
3 vapier 1.26 # $Header: /var/cvsroot/gentoo-x86/eclass/mysql-v2.eclass,v 1.25 2013/06/26 19:31:49 jmbsvicetto Exp $
4 robbat2 1.1
5     # @ECLASS: mysql-v2.eclass
6     # @MAINTAINER:
7     # Maintainers:
8     # - MySQL Team <mysql-bugs@gentoo.org>
9     # - Robin H. Johnson <robbat2@gentoo.org>
10     # - Jorge Manuel B. S. Vicetto <jmbsvicetto@gentoo.org>
11     # @BLURB: This eclass provides most of the functions for mysql ebuilds
12     # @DESCRIPTION:
13     # The mysql-v2.eclass is the base eclass to build the mysql and
14 jmbsvicetto 1.25 # alternative projects (mariadb and percona) ebuilds.
15 robbat2 1.1 # This eclass uses the mysql-autotools and mysql-cmake eclasses for the
16     # specific bits related to the build system.
17     # It provides the src_unpack, src_prepare, src_configure, src_compile,
18 heroxbd 1.16 # src_install, pkg_preinst, pkg_postinst, pkg_config and pkg_postrm
19 robbat2 1.1 # phase hooks.
20    
21     # @ECLASS-VARIABLE: BUILD
22 vapier 1.7 # @DESCRIPTION:
23     # Build type of the mysql version
24 robbat2 1.1 : ${BUILD:=autotools}
25    
26     case ${BUILD} in
27     "cmake")
28     BUILD_INHERIT="mysql-cmake"
29     ;;
30     "autotools")
31     BUILD_INHERIT="mysql-autotools"
32    
33     WANT_AUTOCONF="latest"
34     WANT_AUTOMAKE="latest"
35     ;;
36     *)
37     die "${BUILD} is not a valid build system for mysql"
38     ;;
39     esac
40    
41     MYSQL_EXTRAS=""
42    
43     # @ECLASS-VARIABLE: MYSQL_EXTRAS_VER
44 vapier 1.7 # @DESCRIPTION:
45     # The version of the MYSQL_EXTRAS repo to use to build mysql
46 jmbsvicetto 1.9 # Use "none" to disable it's use
47 jmbsvicetto 1.25 [[ ${MY_EXTRAS_VER} == "live" ]] && MYSQL_EXTRAS="git-2"
48 robbat2 1.1
49 vapier 1.26 inherit eutils flag-o-matic gnuconfig ${MYSQL_EXTRAS} ${BUILD_INHERIT} mysql_fx versionator toolchain-funcs user
50 robbat2 1.1
51     #
52     # Supported EAPI versions and export functions
53     #
54    
55     case "${EAPI:-0}" in
56 jmbsvicetto 1.25 4|5) ;;
57 robbat2 1.1 *) die "Unsupported EAPI: ${EAPI}" ;;
58     esac
59    
60 jmbsvicetto 1.3 EXPORT_FUNCTIONS pkg_setup src_unpack src_prepare src_configure src_compile src_install pkg_preinst pkg_postinst pkg_config pkg_postrm
61 robbat2 1.1
62     #
63     # VARIABLES:
64     #
65    
66     # Shorten the path because the socket path length must be shorter than 107 chars
67     # and we will run a mysql server during test phase
68     S="${WORKDIR}/mysql"
69    
70 jmbsvicetto 1.25 [[ ${MY_EXTRAS_VER} == "latest" ]] && MY_EXTRAS_VER="20090228-0714Z"
71     if [[ ${MY_EXTRAS_VER} == "live" ]]; then
72 robbat2 1.1 EGIT_PROJECT=mysql-extras
73     EGIT_REPO_URI="git://git.overlays.gentoo.org/proj/mysql-extras.git"
74     fi
75    
76     # @ECLASS-VARIABLE: MYSQL_PV_MAJOR
77     # @DESCRIPTION:
78     # Upstream MySQL considers the first two parts of the version number to be the
79     # major version. Upgrades that change major version should always run
80     # mysql_upgrade.
81     MYSQL_PV_MAJOR="$(get_version_component_range 1-2 ${PV})"
82    
83     # @ECLASS-VARIABLE: MYSQL_VERSION_ID
84     # @DESCRIPTION:
85     # MYSQL_VERSION_ID will be:
86     # major * 10e6 + minor * 10e4 + micro * 10e2 + gentoo revision number, all [0..99]
87     # This is an important part, because many of the choices the MySQL ebuild will do
88     # depend on this variable.
89     # In particular, the code below transforms a $PVR like "5.0.18-r3" in "5001803"
90     # We also strip off upstream's trailing letter that they use to respin tarballs
91     MYSQL_VERSION_ID=""
92     tpv="${PV%[a-z]}"
93     tpv=( ${tpv//[-._]/ } ) ; tpv[3]="${PVR:${#PV}}" ; tpv[3]="${tpv[3]##*-r}"
94     for vatom in 0 1 2 3 ; do
95     # pad to length 2
96     tpv[${vatom}]="00${tpv[${vatom}]}"
97     MYSQL_VERSION_ID="${MYSQL_VERSION_ID}${tpv[${vatom}]:0-2}"
98     done
99     # strip leading "0" (otherwise it's considered an octal number by BASH)
100     MYSQL_VERSION_ID=${MYSQL_VERSION_ID##"0"}
101    
102     # This eclass should only be used with at least mysql-5.1.50
103     mysql_version_is_at_least "5.1.50" || die "This eclass should only be used with >=mysql-5.1.50"
104    
105     # @ECLASS-VARIABLE: XTRADB_VER
106     # @DEFAULT_UNSET
107     # @DESCRIPTION:
108     # Version of the XTRADB storage engine
109    
110     # @ECLASS-VARIABLE: PERCONA_VER
111     # @DEFAULT_UNSET
112     # @DESCRIPTION:
113     # Designation by PERCONA for a MySQL version to apply an XTRADB release
114    
115     # Work out the default SERVER_URI correctly
116 jmbsvicetto 1.25 if [[ -z ${SERVER_URI} ]]; then
117     [[ -z ${MY_PV} ]] && MY_PV="${PV//_/-}"
118     if [[ ${PN} == "mariadb" || ${PN} == "mariadb-galera" ]]; then
119     MARIA_FULL_PV=$(replace_version_separator 3 '-' ${MY_PV})
120 robbat2 1.1 MARIA_FULL_P="${PN}-${MARIA_FULL_PV}"
121     SERVER_URI="
122     http://ftp.osuosl.org/pub/mariadb/${MARIA_FULL_P}/kvm-tarbake-jaunty-x86/${MARIA_FULL_P}.tar.gz
123     http://ftp.rediris.es/mirror/MariaDB/${MARIA_FULL_P}/kvm-tarbake-jaunty-x86/${MARIA_FULL_P}.tar.gz
124     http://maria.llarian.net/download/${MARIA_FULL_P}/kvm-tarbake-jaunty-x86/${MARIA_FULL_P}.tar.gz
125     http://launchpad.net/maria/${MYSQL_PV_MAJOR}/ongoing/+download/${MARIA_FULL_P}.tar.gz
126     http://mirrors.fe.up.pt/pub/${PN}/${MARIA_FULL_P}/kvm-tarbake-jaunty-x86/${MARIA_FULL_P}.tar.gz
127     http://ftp-stud.hs-esslingen.de/pub/Mirrors/${PN}/${MARIA_FULL_P}/kvm-tarbake-jaunty-x86/${MARIA_FULL_P}.tar.gz
128     "
129 jmbsvicetto 1.25 if [[ ${PN} == "mariadb-galera" ]]; then
130     MY_SOURCEDIR="${PN%%-galera}-${MARIA_FULL_PV}"
131     fi
132     elif [[ ${PN} == "percona-server" ]]; then
133     PERCONA_PN="Percona-Server"
134     MIRROR_PV=$(get_version_component_range 1-2 ${PV})
135     MY_PV=$(get_version_component_range 1-3 ${PV})
136     MY_PATCH=$(get_version_component_range 4 ${PV})
137     SERVER_URI="http://www.percona.com/redir/downloads/${PERCONA_PN}-${MIRROR_PV}/LATEST/source/${PERCONA_PN}-${MY_PV}-rel30.${MY_PATCH}.tar.gz"
138     # http://www.percona.com/redir/downloads/Percona-Server-5.5/LATEST/source/Percona-Server-5.5.30-rel30.2.tar.gz
139 robbat2 1.15 else
140     URI_DIR="MySQL"
141     URI_FILE="mysql"
142 robbat2 1.1 URI_A="${URI_FILE}-${MY_PV}.tar.gz"
143     MIRROR_PV=$(get_version_component_range 1-2 ${PV})
144     # Recently upstream switched to an archive site, and not on mirrors
145     SERVER_URI="http://downloads.mysql.com/archives/${URI_FILE}-${MIRROR_PV}/${URI_A}
146     mirror://mysql/Downloads/${URI_DIR}-${PV%.*}/${URI_A}"
147     fi
148     fi
149    
150     # Define correct SRC_URIs
151     SRC_URI="${SERVER_URI}"
152    
153     # Gentoo patches to MySQL
154 jmbsvicetto 1.25 if [[ ${MY_EXTRAS_VER} != "live" && ${MY_EXTRAS_VER} != "none" ]]; then
155     SRC_URI="${SRC_URI}
156 robbat2 1.1 mirror://gentoo/mysql-extras-${MY_EXTRAS_VER}.tar.bz2
157     http://g3nt8.org/patches/mysql-extras-${MY_EXTRAS_VER}.tar.bz2
158 jmbsvicetto 1.4 http://dev.gentoo.org/~robbat2/distfiles/mysql-extras-${MY_EXTRAS_VER}.tar.bz2
159     http://dev.gentoo.org/~jmbsvicetto/distfiles/mysql-extras-${MY_EXTRAS_VER}.tar.bz2"
160 jmbsvicetto 1.25 fi
161 robbat2 1.1
162     DESCRIPTION="A fast, multi-threaded, multi-user SQL database server."
163     HOMEPAGE="http://www.mysql.com/"
164 jmbsvicetto 1.25 if [[ ${PN} == "mariadb" ]]; then
165 robbat2 1.1 HOMEPAGE="http://mariadb.org/"
166 robbat2 1.23 DESCRIPTION="An enhanced, drop-in replacement for MySQL"
167 robbat2 1.1 fi
168 jmbsvicetto 1.25 if [[ ${PN} == "mariadb-galera" ]]; then
169     HOMEPAGE="http://mariadb.org/"
170     DESCRIPTION="An enhanced, drop-in replacement for MySQL with Galera Replication"
171     fi
172     if [[ ${PN} == "percona-server" ]]; then
173     HOMEPAGE="http://www.percona.com/software/percona-server"
174     DESCRIPTION="An enhanced, drop-in replacement fro MySQL from the Percona team"
175     fi
176 robbat2 1.1 LICENSE="GPL-2"
177     SLOT="0"
178    
179     case "${BUILD}" in
180     "autotools")
181     IUSE="big-tables debug embedded minimal +perl selinux ssl static test"
182     ;;
183     "cmake")
184     IUSE="debug embedded minimal +perl selinux ssl static test"
185     ;;
186     esac
187    
188     IUSE="${IUSE} latin1"
189    
190     IUSE="${IUSE} extraengine"
191 robbat2 1.15 IUSE="${IUSE} cluster"
192 robbat2 1.1
193     IUSE="${IUSE} max-idx-128"
194 robbat2 1.15 IUSE="${IUSE} +community profiling"
195 robbat2 1.1
196 jmbsvicetto 1.25 if [[ ${PN} == "mariadb" || ${PN} == "mariadb-galera" ]]; then
197     mysql_check_version_range "5.1.38 to 5.3.99" && IUSE="${IUSE} libevent"
198     mysql_version_is_at_least "5.2" && IUSE="${IUSE} oqgraph"
199     mysql_version_is_at_least "5.2.5" && IUSE="${IUSE} sphinx"
200     mysql_version_is_at_least "5.2.10" && IUSE="${IUSE} pam"
201     fi
202 robbat2 1.24
203 robbat2 1.21 if mysql_version_is_at_least "5.5"; then
204     REQUIRED_USE="tcmalloc? ( !jemalloc ) jemalloc? ( !tcmalloc )"
205     IUSE="${IUSE} jemalloc tcmalloc"
206     fi
207    
208 jmbsvicetto 1.25 if mysql_version_is_at_least "5.5.7"; then
209     IUSE="${IUSE} systemtap"
210     fi
211    
212     if [[ ${PN} == "percona-server" ]]; then
213     mysql_version_is_at_least "5.5.10" && IUSE="${IUSE} pam"
214     fi
215    
216 robbat2 1.23 REQUIRED_USE="${REQUIRED_USE} minimal? ( !cluster !extraengine !embedded ) static? ( !ssl )"
217    
218 robbat2 1.1 #
219     # DEPENDENCIES:
220     #
221    
222     # Be warned, *DEPEND are version-dependant
223     # These are used for both runtime and compiletime
224     DEPEND="
225     ssl? ( >=dev-libs/openssl-0.9.6d )
226 jmbsvicetto 1.9 kernel_linux? ( sys-process/procps )
227 robbat2 1.1 >=sys-apps/sed-4
228     >=sys-apps/texinfo-4.7-r1
229     >=sys-libs/readline-4.1
230     >=sys-libs/zlib-1.2.3
231     "
232    
233 jmbsvicetto 1.25 if [[ ${PN} == "mariadb" || ${PN} == "mariadb-galera" ]] ; then
234     mysql_check_version_range "5.1.38 to 5.3.99" && DEPEND="${DEPEND} libevent? ( >=dev-libs/libevent-1.4 )"
235     mysql_version_is_at_least "5.2" && DEPEND="${DEPEND} oqgraph? ( >=dev-libs/boost-1.40.0 )"
236     mysql_version_is_at_least "5.2.5" && DEPEND="${DEPEND} sphinx? ( app-misc/sphinx )"
237     mysql_version_is_at_least "5.2.10" && DEPEND="${DEPEND} !minimal? ( pam? ( virtual/pam ) )"
238     # Bug 441700 MariaDB >=5.3 include custom mytop
239     mysql_version_is_at_least "5.3" && DEPEND="${DEPEND} perl? ( !dev-db/mytop )"
240     fi
241 robbat2 1.1
242     # Having different flavours at the same time is not a good idea
243 jmbsvicetto 1.25 for i in "mysql" "mariadb" "mariadb-galera" "percona-server"; do
244 robbat2 1.1 [[ ${i} == ${PN} ]] ||
245     DEPEND="${DEPEND} !dev-db/${i}"
246     done
247    
248 jmbsvicetto 1.25 if mysql_version_is_at_least "5.5" ; then
249     DEPEND="${DEPEND} jemalloc? ( dev-libs/jemalloc )"
250     DEPEND="${DEPEND} tcmalloc? ( dev-util/google-perftools )"
251     fi
252 robbat2 1.22
253 jmbsvicetto 1.25 if mysql_version_is_at_least "5.5.7" ; then
254     DEPEND="${DEPEND} systemtap? ( >=dev-util/systemtap-1.3 )"
255     DEPEND="${DEPEND} kernel_linux? ( dev-libs/libaio )"
256     fi
257 robbat2 1.22
258 grobian 1.8 # prefix: first need to implement something for #196294
259 robbat2 1.1 RDEPEND="${DEPEND}
260 grobian 1.8 !minimal? ( !prefix? ( dev-db/mysql-init-scripts ) )
261 robbat2 1.1 selinux? ( sec-policy/selinux-mysql )
262     "
263    
264 jmbsvicetto 1.25 if [[ ${PN} == "mariadb" || ${PN} == "mariadb-galera" ]] ; then
265     # Bug 455016 Add dependencies of mytop
266     if mysql_version_is_at_least "5.3" ; then
267     RDEPEND="${RDEPEND} perl? (
268     virtual/perl-Getopt-Long
269     dev-perl/TermReadKey
270     virtual/perl-Term-ANSIColor
271     virtual/perl-Time-HiRes ) "
272     fi
273     fi
274 robbat2 1.24
275 jmbsvicetto 1.6 DEPEND="${DEPEND}
276     virtual/yacc
277     "
278    
279 jmbsvicetto 1.17 DEPEND="${DEPEND} static? ( sys-libs/ncurses[static-libs] )"
280 robbat2 1.1
281     # compile-time-only
282     DEPEND="${DEPEND} >=dev-util/cmake-2.4.3"
283    
284     # compile-time-only
285 jmbsvicetto 1.25 if mysql_version_is_at_least "5.5.8" ; then
286     DEPEND="${DEPEND} >=dev-util/cmake-2.6.3"
287     fi
288 robbat2 1.1
289     # dev-perl/DBD-mysql is needed by some scripts installed by MySQL
290     PDEPEND="perl? ( >=dev-perl/DBD-mysql-2.9004 )"
291    
292     # For other stuff to bring us in
293     PDEPEND="${PDEPEND} =virtual/mysql-${MYSQL_PV_MAJOR}"
294    
295     #
296     # External patches
297     #
298    
299     # MariaDB has integrated PBXT
300     # PBXT_VERSION means that we have a PBXT patch for this PV
301     # PBXT was only introduced after 5.1.12
302     pbxt_patch_available() {
303 jmbsvicetto 1.25 [[ ${PN} != "mariadb" && ${PN} != "mariadb-galera" && ( -n "${PBXT_VERSION}" ) ]]
304 robbat2 1.1 return $?
305     }
306    
307     pbxt_available() {
308 jmbsvicetto 1.25 pbxt_patch_available || [[ ${PN} == "mariadb" || ${PN} == "mariadb-galera" ]]
309 robbat2 1.1 return $?
310     }
311    
312     # Get the percona tarball if XTRADB_VER and PERCONA_VER are both set
313     # MariaDB has integrated XtraDB
314     # XTRADB_VERS means that we have a XTRADB patch for this PV
315     # XTRADB was only introduced after 5.1.26
316     xtradb_patch_available() {
317 jmbsvicetto 1.25 [[ ${PN} != "mariadb" && ${PN} != "mariadb-galera"
318     && ( -n "${XTRADB_VER}" ) && ( -n "${PERCONA_VER}" ) ]]
319 robbat2 1.1 return $?
320     }
321    
322     if pbxt_patch_available; then
323    
324     PBXT_P="pbxt-${PBXT_VERSION}"
325     PBXT_SRC_URI="http://www.primebase.org/download/${PBXT_P}.tar.gz mirror://sourceforge/pbxt/${PBXT_P}.tar.gz"
326     SRC_URI="${SRC_URI} pbxt? ( ${PBXT_SRC_URI} )"
327 robbat2 1.15 fi
328    
329     # PBXT_NEWSTYLE means pbxt is in storage/ and gets enabled as other plugins
330     # vs. built outside the dir
331     if pbxt_available; then
332 robbat2 1.1
333 robbat2 1.15 IUSE="${IUSE} pbxt"
334     PBXT_NEWSTYLE=1
335 robbat2 1.23 REQUIRED_USE="${REQUIRED_USE} pbxt? ( !embedded ) "
336 robbat2 1.1 fi
337    
338     if xtradb_patch_available; then
339     XTRADB_P="percona-xtradb-${XTRADB_VER}"
340     XTRADB_SRC_URI_COMMON="${PERCONA_VER}/source/${XTRADB_P}.tar.gz"
341     XTRADB_SRC_B1="http://www.percona.com/"
342     XTRADB_SRC_B2="${XTRADB_SRC_B1}/percona-builds/"
343     XTRADB_SRC_URI1="${XTRADB_SRC_B2}/Percona-Server/Percona-Server-${XTRADB_SRC_URI_COMMON}"
344     XTRADB_SRC_URI2="${XTRADB_SRC_B2}/xtradb/${XTRADB_SRC_URI_COMMON}"
345     XTRADB_SRC_URI3="${XTRADB_SRC_B1}/${PN}/xtradb/${XTRADB_SRC_URI_COMMON}"
346     SRC_URI="${SRC_URI} xtradb? ( ${XTRADB_SRC_URI1} ${XTRADB_SRC_URI2} ${XTRADB_SRC_URI3} )"
347     IUSE="${IUSE} xtradb"
348 robbat2 1.23 REQUIRED_USE="${REQUIRED_USE} xtradb? ( !embedded ) "
349 robbat2 1.1 fi
350    
351     #
352     # HELPER FUNCTIONS:
353     #
354    
355     # @FUNCTION: mysql-v2_disable_test
356     # @DESCRIPTION:
357     # Helper function to disable specific tests.
358     mysql-v2_disable_test() {
359     ${BUILD_INHERIT}_disable_test "$@"
360     }
361    
362     # @FUNCTION: mysql-v2_configure_minimal
363     # @DESCRIPTION:
364     # Helper function to configure minimal build
365     configure_minimal() {
366     ${BUILD_INHERIT}_configure_minimal "$@"
367     }
368    
369     # @FUNCTION: mysql-v2_configure_common
370     # @DESCRIPTION:
371     # Helper function to configure common builds
372     configure_common() {
373     ${BUILD_INHERIT}_configure_common "$@"
374     }
375    
376     #
377     # EBUILD FUNCTIONS
378     #
379    
380     # @FUNCTION: mysql-v2_pkg_setup
381     # @DESCRIPTION:
382     # Perform some basic tests and tasks during pkg_setup phase:
383     # die if FEATURES="test", USE="-minimal" and not using FEATURES="userpriv"
384     # check for conflicting use flags
385     # create new user and group for mysql
386     # warn about deprecated features
387     mysql-v2_pkg_setup() {
388    
389     if has test ${FEATURES} ; then
390     if ! use minimal ; then
391 jmbsvicetto 1.12 if ! has userpriv ${FEATURES} ; then
392 robbat2 1.1 eerror "Testing with FEATURES=-userpriv is no longer supported by upstream. Tests MUST be run as non-root."
393     fi
394     fi
395     fi
396    
397     # Check for USE flag problems in pkg_setup
398 jmbsvicetto 1.25 if ! mysql_version_is_at_least "5.2" && use debug ; then
399 robbat2 1.1 # Also in package.use.mask
400     die "Bug #344885: Upstream has broken USE=debug for 5.1 series >=5.1.51"
401     fi
402    
403     # This should come after all of the die statements
404     enewgroup mysql 60 || die "problem adding 'mysql' group"
405     enewuser mysql 60 -1 /dev/null mysql || die "problem adding 'mysql' user"
406    
407 robbat2 1.15 if use cluster; then
408 robbat2 1.1 ewarn "Upstream has noted that the NDB cluster support in the 5.0 and"
409     ewarn "5.1 series should NOT be put into production. In the near"
410     ewarn "future, it will be disabled from building."
411     fi
412     }
413    
414     # @FUNCTION: mysql-v2_src_unpack
415     # @DESCRIPTION:
416     # Unpack the source code
417     mysql-v2_src_unpack() {
418    
419     # Initialize the proper variables first
420     mysql_init_vars
421    
422     unpack ${A}
423     # Grab the patches
424     [[ "${MY_EXTRAS_VER}" == "live" ]] && S="${WORKDIR}/mysql-extras" git-2_src_unpack
425    
426     mv -f "${WORKDIR}/${MY_SOURCEDIR}" "${S}"
427     }
428    
429     # @FUNCTION: mysql-v2_src_prepare
430     # @DESCRIPTION:
431     # Apply patches to the source code and remove unneeded bundled libs.
432     mysql-v2_src_prepare() {
433     ${BUILD_INHERIT}_src_prepare "$@"
434     }
435    
436     # @FUNCTION: mysql-v2_src_configure
437     # @DESCRIPTION:
438     # Configure mysql to build the code for Gentoo respecting the use flags.
439     mysql-v2_src_configure() {
440     ${BUILD_INHERIT}_src_configure "$@"
441     }
442    
443     # @FUNCTION: mysql-v2_src_compile
444     # @DESCRIPTION:
445     # Compile the mysql code.
446     mysql-v2_src_compile() {
447     ${BUILD_INHERIT}_src_compile "$@"
448     }
449    
450     # @FUNCTION: mysql-v2_src_install
451     # @DESCRIPTION:
452     # Install mysql.
453     mysql-v2_src_install() {
454     ${BUILD_INHERIT}_src_install "$@"
455     }
456    
457     # @FUNCTION: mysql-v2_pkg_preinst
458     # @DESCRIPTION:
459     # Create the user and groups for mysql - die if that fails.
460     mysql-v2_pkg_preinst() {
461     enewgroup mysql 60 || die "problem adding 'mysql' group"
462     enewuser mysql 60 -1 /dev/null mysql || die "problem adding 'mysql' user"
463     }
464    
465     # @FUNCTION: mysql-v2_pkg_postinst
466     # @DESCRIPTION:
467     # Run post-installation tasks:
468     # create the dir for logfiles if non-existant
469     # touch the logfiles and secure them
470     # install scripts
471     # issue required steps for optional features
472     # issue deprecation warnings
473     mysql-v2_pkg_postinst() {
474    
475     # Make sure the vars are correctly initialized
476     mysql_init_vars
477    
478     # Check FEATURES="collision-protect" before removing this
479 jmbsvicetto 1.12 [[ -d "${ROOT}${MY_LOGDIR}" ]] || install -d -m0750 -o mysql -g mysql "${ROOT}${MY_LOGDIR}"
480 robbat2 1.1
481     # Secure the logfiles
482     touch "${ROOT}${MY_LOGDIR}"/mysql.{log,err}
483     chown mysql:mysql "${ROOT}${MY_LOGDIR}"/mysql*
484     chmod 0660 "${ROOT}${MY_LOGDIR}"/mysql*
485    
486     # Minimal builds don't have the MySQL server
487     if ! use minimal ; then
488     docinto "support-files"
489     for script in \
490     support-files/my-*.cnf \
491     support-files/magic \
492     support-files/ndb-config-2-node.ini
493     do
494     [[ -f "${script}" ]] \
495     && dodoc "${script}"
496     done
497    
498     docinto "scripts"
499     for script in scripts/mysql* ; do
500 jmbsvicetto 1.25 if [[ -f "${script}" && "${script%.sh}" == "${script}" ]]; then
501     dodoc "${script}"
502     fi
503 robbat2 1.1 done
504    
505 jmbsvicetto 1.25 if [[ ${PN} == "mariadb" || ${PN} == "mariadb-galera" ]] \
506     && mysql_version_is_at_least "5.2.10" && use pam ; then
507 robbat2 1.24 einfo
508     elog "This install includes the PAM authentication plugin."
509     elog "To activate and configure the PAM plugin, please read:"
510     elog "https://kb.askmonty.org/en/pam-authentication-plugin/"
511     einfo
512     fi
513    
514 robbat2 1.1 einfo
515     elog "You might want to run:"
516     elog "\"emerge --config =${CATEGORY}/${PF}\""
517     elog "if this is a new install."
518     einfo
519    
520     einfo
521     elog "If you are upgrading major versions, you should run the"
522     elog "mysql_upgrade tool."
523     einfo
524     fi
525    
526     if pbxt_available && use pbxt ; then
527 robbat2 1.21 elog "Note: PBXT is now statically built when enabled."
528     elog ""
529     elog "If, you previously installed as a plugin and "
530     elog "you cannot start the MySQL server,"
531 robbat2 1.1 elog "remove the ${MY_DATADIR}/mysql/plugin.* files, then"
532     elog "use the MySQL upgrade script to restore the table"
533     elog "or execute the following SQL command:"
534     elog " CREATE TABLE IF NOT EXISTS plugin ("
535     elog " name char(64) binary DEFAULT '' NOT NULL,"
536     elog " dl char(128) DEFAULT '' NOT NULL,"
537     elog " PRIMARY KEY (name)"
538     elog " ) CHARACTER SET utf8 COLLATE utf8_bin;"
539     fi
540     }
541    
542 robbat2 1.20 # @FUNCTION: mysql-v2_getopt
543     # @DESCRIPTION:
544     # Use my_print_defaults to extract specific config options
545     mysql-v2_getopt() {
546     local mypd="${EROOT}"/usr/bin/my_print_defaults
547     section="$1"
548     flag="--${2}="
549     "${mypd}" $section | sed -n "/^${flag}/p"
550     }
551    
552     # @FUNCTION: mysql-v2_getoptval
553     # @DESCRIPTION:
554     # Use my_print_defaults to extract specific config options
555     mysql-v2_getoptval() {
556     local mypd="${EROOT}"/usr/bin/my_print_defaults
557     section="$1"
558     flag="--${2}="
559     "${mypd}" $section | sed -n "/^${flag}/s,${flag},,gp"
560     }
561    
562 robbat2 1.1 # @FUNCTION: mysql-v2_pkg_config
563     # @DESCRIPTION:
564     # Configure mysql environment.
565     mysql-v2_pkg_config() {
566    
567     local old_MY_DATADIR="${MY_DATADIR}"
568 robbat2 1.20 local old_HOME="${HOME}"
569     # my_print_defaults needs to read stuff in $HOME/.my.cnf
570     export HOME=/root
571 robbat2 1.1
572     # Make sure the vars are correctly initialized
573     mysql_init_vars
574    
575     [[ -z "${MY_DATADIR}" ]] && die "Sorry, unable to find MY_DATADIR"
576    
577     if built_with_use ${CATEGORY}/${PN} minimal ; then
578     die "Minimal builds do NOT include the MySQL server"
579     fi
580    
581     if [[ ( -n "${MY_DATADIR}" ) && ( "${MY_DATADIR}" != "${old_MY_DATADIR}" ) ]]; then
582 ferringb 1.18 local MY_DATADIR_s="${ROOT}/${MY_DATADIR}"
583     MY_DATADIR_s="${MY_DATADIR_s%%/}"
584 robbat2 1.20 local old_MY_DATADIR_s="${ROOT}/${old_MY_DATADIR}"
585 ferringb 1.18 old_MY_DATADIR_s="${old_MY_DATADIR_s%%/}"
586 robbat2 1.1
587 jmbsvicetto 1.25 if [[ ( -d "${old_MY_DATADIR_s}" ) && ( "${old_MY_DATADIR_s}" != / ) ]]; then
588 robbat2 1.1 if [[ -d "${MY_DATADIR_s}" ]]; then
589     ewarn "Both ${old_MY_DATADIR_s} and ${MY_DATADIR_s} exist"
590     ewarn "Attempting to use ${MY_DATADIR_s} and preserving ${old_MY_DATADIR_s}"
591     else
592     elog "Moving MY_DATADIR from ${old_MY_DATADIR_s} to ${MY_DATADIR_s}"
593     mv --strip-trailing-slashes -T "${old_MY_DATADIR_s}" "${MY_DATADIR_s}" \
594     || die "Moving MY_DATADIR failed"
595     fi
596     else
597     ewarn "Previous MY_DATADIR (${old_MY_DATADIR_s}) does not exist"
598     if [[ -d "${MY_DATADIR_s}" ]]; then
599     ewarn "Attempting to use ${MY_DATADIR_s}"
600     else
601     eerror "New MY_DATADIR (${MY_DATADIR_s}) does not exist"
602     die "Configuration Failed! Please reinstall ${CATEGORY}/${PN}"
603     fi
604     fi
605     fi
606    
607     local pwd1="a"
608     local pwd2="b"
609     local maxtry=15
610    
611 robbat2 1.20 if [ -z "${MYSQL_ROOT_PASSWORD}" ]; then
612     MYSQL_ROOT_PASSWORD="$(mysql-v2_getoptval 'client mysql' password)"
613     fi
614     MYSQL_TMPDIR="$(mysql-v2_getoptval mysqld tmpdir)"
615     # These are dir+prefix
616     MYSQL_RELAY_LOG="$(mysql-v2_getoptval mysqld relay-log)"
617     MYSQL_RELAY_LOG=${MYSQL_RELAY_LOG%/*}
618     MYSQL_LOG_BIN="$(mysql-v2_getoptval mysqld log-bin)"
619     MYSQL_LOG_BIN=${MYSQL_LOG_BIN%/*}
620    
621     if [[ ! -d "${EROOT}"/$MYSQL_TMPDIR ]]; then
622     einfo "Creating MySQL tmpdir $MYSQL_TMPDIR"
623     install -d -m 770 -o mysql -g mysql "${EROOT}"/$MYSQL_TMPDIR
624     fi
625     if [[ ! -d "${EROOT}"/$MYSQL_LOG_BIN ]]; then
626     einfo "Creating MySQL log-bin directory $MYSQL_LOG_BIN"
627     install -d -m 770 -o mysql -g mysql "${EROOT}"/$MYSQL_LOG_BIN
628     fi
629     if [[ ! -d "${EROOT}"/$MYSQL_RELAY_LOG ]]; then
630     einfo "Creating MySQL relay-log directory $MYSQL_RELAY_LOG"
631     install -d -m 770 -o mysql -g mysql "${EROOT}"/$MYSQL_RELAY_LOG
632 robbat2 1.1 fi
633    
634     if [[ -d "${ROOT}/${MY_DATADIR}/mysql" ]] ; then
635     ewarn "You have already a MySQL database in place."
636     ewarn "(${ROOT}/${MY_DATADIR}/*)"
637     ewarn "Please rename or delete it if you wish to replace it."
638     die "MySQL database already exists!"
639     fi
640    
641     # Bug #213475 - MySQL _will_ object strenously if your machine is named
642     # localhost. Also causes weird failures.
643     [[ "${HOSTNAME}" == "localhost" ]] && die "Your machine must NOT be named localhost"
644    
645     if [ -z "${MYSQL_ROOT_PASSWORD}" ]; then
646    
647     einfo "Please provide a password for the mysql 'root' user now, in the"
648     einfo "MYSQL_ROOT_PASSWORD env var or through the /root/.my.cnf file."
649     ewarn "Avoid [\"'\\_%] characters in the password"
650     read -rsp " >" pwd1 ; echo
651    
652     einfo "Retype the password"
653     read -rsp " >" pwd2 ; echo
654    
655     if [[ "x$pwd1" != "x$pwd2" ]] ; then
656     die "Passwords are not the same"
657     fi
658     MYSQL_ROOT_PASSWORD="${pwd1}"
659     unset pwd1 pwd2
660     fi
661    
662 robbat2 1.20 local options="--log-warnings=0"
663 robbat2 1.1 local sqltmp="$(emktemp)"
664    
665     local help_tables="${ROOT}${MY_SHAREDSTATEDIR}/fill_help_tables.sql"
666     [[ -r "${help_tables}" ]] \
667     && cp "${help_tables}" "${TMPDIR}/fill_help_tables.sql" \
668     || touch "${TMPDIR}/fill_help_tables.sql"
669     help_tables="${TMPDIR}/fill_help_tables.sql"
670 jmbsvicetto 1.25
671 robbat2 1.20 # Figure out which options we need to disable to do the setup
672     helpfile="${TMPDIR}/mysqld-help"
673     ${EROOT}/usr/sbin/mysqld --verbose --help >"${helpfile}" 2>/dev/null
674 jmbsvicetto 1.25 for opt in grant-tables host-cache name-resolve networking slave-start \
675 robbat2 1.20 federated innodb ssl log-bin relay-log slow-query-log external-locking \
676     ndbcluster log-slave-updates \
677     ; do
678     optexp="--(skip-)?${opt}" optfull="--loose-skip-${opt}"
679     egrep -sq -- "${optexp}" "${helpfile}" && options="${options} ${optfull}"
680     done
681     # But some options changed names
682     egrep -sq external-locking "${helpfile}" && \
683     options="${options/skip-locking/skip-external-locking}"
684    
685     use prefix || options="${options} --user=mysql"
686 robbat2 1.1
687     pushd "${TMPDIR}" &>/dev/null
688 robbat2 1.20 #cmd="'${EROOT}/usr/share/mysql/scripts/mysql_install_db' '--basedir=${EPREFIX}/usr' ${options}"
689     cmd=${EROOT}usr/share/mysql/scripts/mysql_install_db
690 jmbsvicetto 1.25 [[ -f ${cmd} ]] || cmd=${EROOT}usr/bin/mysql_install_db
691 robbat2 1.20 cmd="'$cmd' '--basedir=${EPREFIX}/usr' ${options}"
692     einfo "Command: $cmd"
693     eval $cmd \
694     >"${TMPDIR}"/mysql_install_db.log 2>&1
695 robbat2 1.1 if [ $? -ne 0 ]; then
696     grep -B5 -A999 -i "ERROR" "${TMPDIR}"/mysql_install_db.log 1>&2
697 jmbsvicetto 1.12 die "Failed to run mysql_install_db. Please review ${EPREFIX}/var/log/mysql/mysqld.err AND ${TMPDIR}/mysql_install_db.log"
698 robbat2 1.1 fi
699     popd &>/dev/null
700     [[ -f "${ROOT}/${MY_DATADIR}/mysql/user.frm" ]] \
701     || die "MySQL databases not installed"
702     chown -R mysql:mysql "${ROOT}/${MY_DATADIR}" 2>/dev/null
703     chmod 0750 "${ROOT}/${MY_DATADIR}" 2>/dev/null
704    
705     # Filling timezones, see
706     # http://dev.mysql.com/doc/mysql/en/time-zone-support.html
707 jmbsvicetto 1.12 "${EROOT}/usr/bin/mysql_tzinfo_to_sql" "${EROOT}/usr/share/zoneinfo" > "${sqltmp}" 2>/dev/null
708 robbat2 1.1
709     if [[ -r "${help_tables}" ]] ; then
710     cat "${help_tables}" >> "${sqltmp}"
711     fi
712    
713     einfo "Creating the mysql database and setting proper"
714     einfo "permissions on it ..."
715    
716 jmbsvicetto 1.25 # Now that /var/run is a tmpfs mount point, we need to ensure it exists before using it
717     PID_DIR="${EROOT}/var/run/mysqld"
718     if [[ ! -d "${PID_DIR}" ]]; then
719     mkdir "${PID_DIR}"
720     chown mysql:mysql "${PID_DIR}"
721     chmod 755 "${PID_DIR}"
722     fi
723    
724 jmbsvicetto 1.12 local socket="${EROOT}/var/run/mysqld/mysqld${RANDOM}.sock"
725     local pidfile="${EROOT}/var/run/mysqld/mysqld${RANDOM}.pid"
726     local mysqld="${EROOT}/usr/sbin/mysqld \
727 robbat2 1.1 ${options} \
728     --user=mysql \
729 robbat2 1.20 --log-warnings=0 \
730 jmbsvicetto 1.12 --basedir=${EROOT}/usr \
731 robbat2 1.1 --datadir=${ROOT}/${MY_DATADIR} \
732     --max_allowed_packet=8M \
733     --net_buffer_length=16K \
734     --default-storage-engine=MyISAM \
735     --socket=${socket} \
736     --pid-file=${pidfile}"
737     #einfo "About to start mysqld: ${mysqld}"
738     ebegin "Starting mysqld"
739 robbat2 1.20 einfo "Command ${mysqld}"
740 robbat2 1.1 ${mysqld} &
741     rc=$?
742     while ! [[ -S "${socket}" || "${maxtry}" -lt 1 ]] ; do
743     maxtry=$((${maxtry}-1))
744     echo -n "."
745     sleep 1
746     done
747     eend $rc
748    
749     if ! [[ -S "${socket}" ]]; then
750     die "Completely failed to start up mysqld with: ${mysqld}"
751     fi
752    
753     ebegin "Setting root password"
754     # Do this from memory, as we don't want clear text passwords in temp files
755     local sql="UPDATE mysql.user SET Password = PASSWORD('${MYSQL_ROOT_PASSWORD}') WHERE USER='root'"
756 jmbsvicetto 1.12 "${EROOT}/usr/bin/mysql" \
757 robbat2 1.1 --socket=${socket} \
758     -hlocalhost \
759     -e "${sql}"
760     eend $?
761    
762     ebegin "Loading \"zoneinfo\", this step may require a few seconds ..."
763 jmbsvicetto 1.12 "${EROOT}/usr/bin/mysql" \
764 robbat2 1.1 --socket=${socket} \
765     -hlocalhost \
766     -uroot \
767 robbat2 1.20 --password="${MYSQL_ROOT_PASSWORD}" \
768 robbat2 1.1 mysql < "${sqltmp}"
769     rc=$?
770     eend $?
771 jmbsvicetto 1.25 [[ $rc -ne 0 ]] && ewarn "Failed to load zoneinfo!"
772 robbat2 1.1
773     # Stop the server and cleanup
774     einfo "Stopping the server ..."
775     kill $(< "${pidfile}" )
776     rm -f "${sqltmp}"
777     wait %1
778     einfo "Done"
779     }
780    
781     # @FUNCTION: mysql-v2_pkg_postrm
782     # @DESCRIPTION:
783     # Remove mysql symlinks.
784     mysql-v2_pkg_postrm() {
785    
786 jmbsvicetto 1.12 : # mysql_lib_symlinks "${ED}"
787 robbat2 1.1 }

  ViewVC Help
Powered by ViewVC 1.1.20