diff options
Diffstat (limited to 'support-files/rpm/server-postin.sh')
-rw-r--r-- | support-files/rpm/server-postin.sh | 31 |
1 files changed, 18 insertions, 13 deletions
diff --git a/support-files/rpm/server-postin.sh b/support-files/rpm/server-postin.sh index 156865b61ad..b5ba10bd265 100644 --- a/support-files/rpm/server-postin.sh +++ b/support-files/rpm/server-postin.sh @@ -5,41 +5,46 @@ if [ $1 = 1 ] ; then /sbin/chkconfig --add mysql fi - mysql_dirs=(`%{_sbindir}/mysqld --verbose --help 2>/dev/null|sed -ne 's/^\(basedir\|datadir\)[[:space:]]*\(.*\)$/\2/p'`) - basedir="${mysql_dirs[0]}" - datadir="${mysql_dirs[1]}" - # datadir may be relative to a basedir! - if expr $datadir : / > /dev/null; then - mysql_datadir=$datadir + basedir=`%{_bindir}/my_print_defaults --mysqld|sed -ne 's/^--basedir=//p'|tail -1` + if [ -z "$basedir" ] ; then + basedir=%{mysqlbasedir} + fi + + datadir=`%{_bindir}/my_print_defaults --mysqld|sed -ne 's/^--datadir=//p'|tail -1` + if [ -z "$datadir" ] ; then + datadir=%{mysqldatadir} else - mysql_datadir=$basedir/$datadir + # datadir may be relative to a basedir! + if ! expr $datadir : / > /dev/null; then + datadir=$basedir/$datadir + fi fi # Create a MySQL user and group. Do not report any problems if it already # exists. groupadd -r %{mysqld_group} 2> /dev/null || true - useradd -M -r -d $mysql_datadir -s /bin/bash -c "MySQL server" -g %{mysqld_group} %{mysqld_user} 2> /dev/null || true + useradd -M -r -d $datadir -s /bin/bash -c "MySQL server" -g %{mysqld_group} %{mysqld_user} 2> /dev/null || true # The user may already exist, make sure it has the proper group nevertheless (BUG#12823) usermod -g %{mysqld_group} %{mysqld_user} 2> /dev/null || true # Change permissions so that the user that will run the MySQL daemon # owns all database files. - chown -R %{mysqld_user}:%{mysqld_group} $mysql_datadir + chown -R %{mysqld_user}:%{mysqld_group} $datadir - if [ ! -e $mysql_datadir ]; then + if [ ! -e $datadir ]; then # Create data directory - mkdir -p $mysql_datadir/{mysql,test} + mkdir -p $datadir/{mysql,test} # Initiate databases %{_bindir}/mysql_install_db --rpm --user=%{mysqld_user} fi # Change permissions again to fix any new files. - chown -R %{mysqld_user}:%{mysqld_group} $mysql_datadir + chown -R %{mysqld_user}:%{mysqld_group} $datadir # Fix permissions for the permission database so that only the user # can read them. - chmod -R og-rw $mysql_datadir/mysql + chmod -R og-rw $datadir/mysql fi # install SELinux files - but don't override existing ones |