Tue, 02 Apr 2013 20:44:50 +0200
Correct initial database generation and improve runcommand script logic.
1 ##
2 ## mysql.spec -- OpenPKG RPM Package Specification
3 ## Copyright (c) 2000-2012 OpenPKG Foundation e.V. <http://openpkg.net/>
4 ##
5 ## Permission to use, copy, modify, and distribute this software for
6 ## any purpose with or without fee is hereby granted, provided that
7 ## the above copyright notice and this permission notice appear in all
8 ## copies.
9 ##
10 ## THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
11 ## WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
12 ## MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
13 ## IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR
14 ## CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
15 ## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
16 ## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
17 ## USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
18 ## ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
19 ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
20 ## OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
21 ## SUCH DAMAGE.
22 ##
24 # package version
25 %define V_major 5.5
26 %define V_minor 27
27 %define V_mysql %{V_major}.%{V_minor}
28 %define V_opkg %{V_major}.%{V_minor}
29 %define V_jdbc 5.1.21
31 # package information
32 Name: mysql
33 Summary: Fast Relational Database Management System
34 URL: http://www.mysql.com/products/mysql/
35 Vendor: ORACLE
36 Packager: OpenPKG Foundation e.V.
37 Distribution: OpenPKG Community
38 Class: BASE
39 Group: Database
40 License: GPL
41 Version: %{V_opkg}
42 Release: 20120800
44 # package options
45 %option with_server yes
46 %option with_innobase yes
47 %option with_archive no
48 %option with_blackhole no
49 %option with_federated no
50 %option with_ndbcluster no
51 %option with_partition no
52 %option with_perfschema no
53 %option with_ssl no
54 %option with_embedded no
55 %option with_charset utf8
56 %option with_collation utf8_unicode_ci
57 %option with_jdbc no
59 # fixing implicit interplugin dependencies and correlations
60 %if "%{with_ndbcluster}" == "yes"
61 %undefine with_partition
62 %define with_partition yes
63 %endif
65 # list of sources
66 Source0: http://www.mysql.com/Downloads/MySQL-%{V_major}/mysql-%{V_mysql}.tar.gz
67 Source1: http://ftp.gwdg.de/pub/misc/mysql/Downloads/Connector-J/mysql-connector-java-%{V_jdbc}.tar.gz
68 Source2: my.cnf
69 Source3: my.pwd
70 Source4: rc.mysql
71 Patch0: mysql.patch
73 # build information
74 BuildPreReq: OpenPKG, openpkg >= 20100101, perl, make, cmake, gcc, gcc::with_cxx = yes
75 PreReq: OpenPKG, openpkg >= 20100101, perl
76 BuildPreReq: zlib, readline, ncurses
77 PreReq: zlib, readline, ncurses
78 %if "%{with_ssl}" == "yes"
79 BuildPreReq: openssl
80 PreReq: openssl
81 %endif
82 %if "%{with_jdbc}" == "yes"
83 PreReq: java, JAVA-JDK
84 %endif
86 %description
87 MySQL is a multiuser Relational Database Management System (RDBMS),
88 which is controlled through Structured Query Language (SQL)
89 operating in full multithreading mode. The main goals of MySQL are
90 speed, robustness and ease of use. MySQL was originally developed
91 because of the need for a SQL server that could handle very big
92 databases with magnitude higher speed than what any database vendor
93 could offer.
95 %track
96 prog mysql = {
97 version = %{V_mysql}
98 url = http://dev.mysql.com/downloads/mysql/%{V_major}.html
99 regex = mysql-(__VER__)\.tar\.gz
100 }
101 prog mysql:connector-jdbc = {
102 version = %{V_jdbc}
103 url = http://dev.mysql.com/downloads/connector/j/%{V_major}.html
104 regex = mysql-connector-java-(__VER__)\.tar\.gz
105 }
107 %prep
108 %setup -q
109 %if "%{with_jdbc}" == "yes"
110 %setup -q -T -D -a 1
111 %endif
112 %patch -p0
114 # patch file search path
115 %{l_shtool} subst %{l_value -s -a} \
116 mysys/default.c
118 # fix shebang on supplemental Perl scripts
119 rm -f scripts/*.orig
120 %{l_shtool} subst \
121 -e 's;^#!/usr/bin/perl;#!%{l_prefix}/bin/perl;' \
122 scripts/*
124 %build
125 # create build subdirectory
126 %{l_shtool} mkdir -p objbld
127 cd objbld
129 # configure environment
130 export CC="%{l_cc}"
131 export CXX="%{l_cxx}"
132 export CFLAGS="%{l_cflags -O}"
133 export CXXFLAGS="%{l_cxxflags -O} -felide-constructors -fno-exceptions -fno-rtti"
134 export CPPFLAGS="%{l_cppflags ncurses}"
135 export LDFLAGS="-L`pwd`/libmysql %{l_ldflags}"
136 export LIBS="-lz"
138 # Configure source tree.
139 # Tips are in mysql_release.cmake
140 # or run cmake(1) -L for all opts
141 # Disable dtrace(1) to avoid 'mysqld_dtrace_all.o: file not recognized: Bad value'
142 %{l_prefix}/bin/cmake \
143 -DCMAKE_INSTALL_PREFIX="%{l_prefix}" \
144 -DCMAKE_BUILD_TYPE="RelWithDebInfo" \
145 -DINSTALL_DOCDIR="share/mysql/doc" \
146 -DINSTALL_DOCREADMEDIR="share/mysql/doc" \
147 -DINSTALL_INCLUDEDIR="include/mysql" \
148 -DINSTALL_INFODIR:STRING="info" \
149 -DINSTALL_MYSQLSHAREDIR="share/mysql" \
150 -DINSTALL_SBINDIR="libexec/mysql" \
151 -DINSTALL_SHAREDIR="share/mysql" \
152 -DINSTALL_SCRIPTDIR="bin" \
153 -DINSTALL_SUPPORTFILESDIR="share/mysql" \
154 -DMYSQL_UNIX_ADDR="%{l_prefix}/var/mysql/mysql.sock" \
155 -DFEATURE_SET="community" \
156 -DCOMPILATION_COMMENT="%{l_openpkg_release}" \
157 -DMANUFACTURER="Built from OpenPKG sources" \
158 -DDEFAULT_CHARSET="%{with_charset}" \
159 -DDEFAULT_COLLATION="%{with_collation}" \
160 -DMYSQL_USER="%{l_musr}" \
161 -DWITH_ZLIB=system \
162 -DWITH_READLINE=YES \
163 -DWITH_LIBEDIT=NO \
164 -DWITH_LIBWRAP=NO \
165 -DDISABLE_SHARED=YES \
166 -DENABLE_DTRACE=NO \
167 -DZLIB_INCLUDE_DIR=%{l_cppflags zlib} \
168 -DPKG_CONFIG_EXECUTABLE="PKG_CONFIG_EXECUTABLE-NOTFOUND" \
169 %if "%{with_server}" != "yes"
170 -DWITHOUT_SERVER=YES \
171 %endif
172 %if "%{with_ssl}" == "yes"
173 -DWITH_SSL=system \
174 -DOPENSSL_INCLUDE_DIR="%{l_cppflags openssl}" \
175 -DOPENSSL_SSL_LIBRARY="%{l_prefix}/lib/libssl.a" \
176 -DOPENSSL_CRYPTO_LIBRARY="%{l_prefix}/lib/libcrypto.a" \
177 -DCRYPTO_LIBRARY="%{l_prefix}/lib/libcrypto.a" \
178 %else
179 -DWITH_SSL=NO \
180 %endif
181 %if "%{with_innobase}" == "yes"
182 -DWITH_INNOBASE_STORAGE_ENGINE=YES \
183 %else
184 -DWITH_INNOBASE_STORAGE_ENGINE=NO \
185 %endif
186 %if "%{with_archive}" == "yes"
187 -DWITH_ARCHIVE_STORAGE_ENGINE=YES \
188 %else
189 -DWITH_ARCHIVE_STORAGE_ENGINE=NO \
190 %endif
191 %if "%{with_blackhole}" == "yes"
192 -DWITH_BLACKHOLE_STORAGE_ENGINE=YES \
193 %else
194 -DWITH_BLACKHOLE_STORAGE_ENGINE=NO \
195 %endif
196 %if "%{with_federated}" == "yes"
197 -DWITH_FEDERATED_STORAGE_ENGINE=YES \
198 %else
199 -DWITH_FEDERATED_STORAGE_ENGINE=NO \
200 %endif
201 %if "%{with_ndbcluster}" == "yes"
202 -DWITH_NDBCLUSTER_STORAGE_ENGINE=YES \
203 %else
204 -DWITH_NDBCLUSTER_STORAGE_ENGINE=NO \
205 %endif
206 %if "%{with_partition}" == "yes"
207 -DWITH_PARTITION_STORAGE_ENGINE=YES \
208 %else
209 -DWITH_PARTITION_STORAGE_ENGINE=NO \
210 %endif
211 %if "%{with_perfschema}" == "yes"
212 -DWITH_PERFSCHEMA_STORAGE_ENGINE=YES \
213 %else
214 -DWITH_PERFSCHEMA_STORAGE_ENGINE=NO \
215 %endif
216 %if "%{with_embedded}" == "yes"
217 -DWITH_EMBEDDED_SERVER=YES \
218 %else
219 -DWITH_EMBEDDED_SERVER=NO \
220 %endif
221 ..
223 # build source tree (VERBOSE=1)
224 %{l_make} %{l_mflags -O}
226 %install
227 # install from build subdirectory
228 cd objbld
230 ## patch init script (this broken)
231 #%{l_shtool} subst %{l_value -s -a} \
232 # bin/mysql_install_db.sh
234 # perform standard installation procedure
235 %{l_make} %{l_mflags} install \
236 DESTDIR=$RPM_BUILD_ROOT
238 # cleanup scripts
239 %{l_shtool} subst \
240 -e 's;^\(ldflags=.\).*\(.\)$;\1%{l_ldflags}\2;' \
241 $RPM_BUILD_ROOT%{l_prefix}/bin/mysql_config
243 # move utilities, patched for new paths
244 mv $RPM_BUILD_ROOT%{l_prefix}/bin/replace \
245 $RPM_BUILD_ROOT%{l_prefix}/libexec/mysql/
247 # strip installation area
248 rm -rf $RPM_BUILD_ROOT%{l_prefix}/data
249 rm -rf $RPM_BUILD_ROOT%{l_prefix}/mysql-test
250 rm -rf $RPM_BUILD_ROOT%{l_prefix}/sql-bench
251 rm -f $RPM_BUILD_ROOT%{l_prefix}/share/mysql/binary-configure
252 rm -f $RPM_BUILD_ROOT%{l_prefix}/share/mysql/ndb-config-2-node.ini
253 strip $RPM_BUILD_ROOT%{l_prefix}/bin/* 2>/dev/null || true
254 strip $RPM_BUILD_ROOT%{l_prefix}/libexec/mysql/* 2>/dev/null || true
255 %if "%{with_ndbcluster}" == "yes"
256 rm -f $RPM_BUILD_ROOT%{l_prefix}/bin/ndb*
257 rm -f $RPM_BUILD_ROOT%{l_prefix}/man/man1/ndb*
258 rm -f $RPM_BUILD_ROOT%{l_prefix}/man/man8/ndb*
259 rm -rf $RPM_BUILD_ROOT%{l_prefix}/include/mysql/storage/ndb
260 rm -f $RPM_BUILD_ROOT%{l_prefix}/lib/mysql/libndb*
261 rm -f $RPM_BUILD_ROOT%{l_prefix}/libexec/mysql/ndb*
262 %endif
264 # install global configuration
265 %{l_shtool} mkdir -f -p -m 755 $RPM_BUILD_ROOT%{l_prefix}/etc/mysql
266 sed <%{SOURCE my.cnf} >my.cnf \
267 %if "%{with_innobase}" == "yes"
268 -e '/<\/\{0,1\}with_innobase>/d'
269 %else
270 -e '/<with_innobase>/,/<\/with_innobase>/d'
271 %endif
272 %{l_shtool} install -c -m 644 %{l_value -s -a} \
273 my.cnf \
274 $RPM_BUILD_ROOT%{l_prefix}/etc/mysql/
275 %{l_shtool} install -c -m 600 \
276 %{SOURCE my.pwd} \
277 $RPM_BUILD_ROOT%{l_prefix}/etc/mysql/
279 # install runcommand script
280 %{l_shtool} mkdir -f -p -m 755 $RPM_BUILD_ROOT%{l_prefix}/etc/rc.d
281 %{l_shtool} install -c -m 755 %{l_value -s -a} \
282 %{SOURCE rc.mysql} $RPM_BUILD_ROOT%{l_prefix}/etc/rc.d/
284 # mitigate complex buildconf
285 %{l_shtool} install -c -m 644 \
286 ../INSTALL-SOURCE $RPM_BUILD_ROOT%{l_prefix}/share/mysql/doc/
288 # make sure the database directory exists
289 %{l_shtool} mkdir -f -p -m 755 $RPM_BUILD_ROOT%{l_prefix}/var/mysql
291 # directory for temporary tables
292 %{l_shtool} mkdir -f -p -m 700 $RPM_BUILD_ROOT%{l_prefix}/var/mysql/tmp
294 # optional client-only installation
295 %if "%{with_server}" != "yes"
296 rm -rf $RPM_BUILD_ROOT%{l_prefix}/libexec/mysql
297 ( cd $RPM_BUILD_ROOT%{l_prefix}/bin
298 for bin in *; do
299 case "$bin" in
300 mysql | mysql_config ) ;;
301 * ) rm -f $bin ;;
302 esac
303 done
304 ) || exit $?
305 ( cd $RPM_BUILD_ROOT%{l_prefix}/man/man1
306 for man in *; do
307 case "$man" in
308 mysql.1 | mysql_config.1 ) ;;
309 * ) rm -f $man ;;
310 esac
311 done
312 ) || exit $?
313 %endif
315 # install JDBC driver
316 %if "%{with_jdbc}" == "yes"
317 ( cd mysql-connector-java-%{V_jdbc}
318 %{l_shtool} install -c -m 644 \
319 mysql-connector-java-%{V_jdbc}-bin.jar \
320 $RPM_BUILD_ROOT%{l_prefix}/lib/mysql/mysql.jar
321 ) || exit $?
322 %endif
324 # determine the package files
325 %{l_rpmtool} files -v -ofiles -r$RPM_BUILD_ROOT \
326 %if "%{with_server}" == "yes"
327 %{l_files_std} \
328 '%config %attr(644,%{l_musr},%{l_mgrp}) %{l_prefix}/etc/mysql/my.cnf' \
329 '%config %attr(600,%{l_susr},%{l_mgrp}) %{l_prefix}/etc/mysql/my.pwd' \
330 '%attr(-,%{l_rusr},%{l_rgrp}) %{l_prefix}/var/mysql' \
331 '%attr(-,%{l_rusr},%{l_rgrp}) %{l_prefix}/var/mysql/tmp'
332 %else
333 %{l_files_std}
334 %endif
336 %files -f objbld/files
338 %clean
340 %pre
341 %if "%{with_server}" == "yes"
342 # before upgrade, save status and stop service
343 [ $1 -eq 2 ] || exit 0
344 eval `%{l_rc} mysql status 2>/dev/null | tee %{l_tmpfile}`
345 %{l_rc} mysql stop 2>/dev/null
346 %endif
347 exit 0
349 %post
350 %if "%{with_server}" == "yes"
351 if [ $1 -eq 1 ]; then
352 # after install, create initial database
353 cd $RPM_INSTALL_PREFIX && $RPM_INSTALL_PREFIX/bin/mysql_install_db \
354 --defaults-file=$RPM_INSTALL_PREFIX/etc/mysql/my.cnf \
355 --ldata=$RPM_INSTALL_PREFIX/var/mysql \
356 --user=%{l_rusr} >/dev/null 2>&1
357 chgrp %{l_rgrp} $RPM_INSTALL_PREFIX/var/mysql/mysql
358 ( echo "An initial MySQL DB was created. The owner of the database"
359 echo "is the DB user 'root'. Its initial password is empty."
360 echo "After starting MySQL with..."
361 echo ""
362 echo " \$ $RPM_INSTALL_PREFIX/bin/openpkg rc mysql start"
363 echo ""
364 echo "...you should change the password as soon as possible with:"
365 echo ""
366 echo " \$ $RPM_INSTALL_PREFIX/bin/mysqladmin \\ "
367 echo " -u root password '<new-password>'"
368 echo ""
369 echo "...or alternatively, even better secure the database with:"
370 echo ""
371 echo " \$ $RPM_INSTALL_PREFIX/bin/mysql_secure_installation"
372 echo ""
373 echo "Additionally, because the MySQL package includes automated"
374 echo "maintenance procedures that require administrator access to"
375 echo "the database, you must maintain a (plain text) copy of the"
376 echo "administrator account name and password:"
377 echo ""
378 echo " \$ vi $RPM_INSTALL_PREFIX/etc/mysql/my.pwd"
379 ) | %{l_rpmtool} msg -b -t notice
380 fi
381 if [ $1 -eq 2 ]; then
382 # after upgrade, restore status
383 { eval `cat %{l_tmpfile}`; rm -f %{l_tmpfile}; true; } >/dev/null 2>&1
384 [ ".$mysql_active" = .yes ] && %{l_rc} mysql start
385 fi
386 %endif
387 exit 0
389 %preun
390 %if "%{with_server}" == "yes"
391 # before erase, stop service and remove log files
392 [ $1 -eq 0 ] || exit 0
393 %{l_rc} mysql stop 2>/dev/null
394 rm -f $RPM_INSTALL_PREFIX/var/mysql/*.log* >/dev/null 2>&1 || true
395 rm -f $RPM_INSTALL_PREFIX/var/mysql/*.err* >/dev/null 2>&1 || true
396 %endif
397 exit 0