# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4
# $Id: Portfile 85114 2011-10-09 22:13:11Z nicos@macports.org $

PortSystem              1.0

name                    mariadb-server
version                 5.2.9
categories              databases
platforms               darwin
license                 GPL-2
maintainers             jogwtr@googlemail.com

description \
    A database server that offers drop-in replacement functionality for MySQL
long_description \
    MariaDB is a database server that offers drop-in replacement functionality for \
    MySQL1. MariaDB is built by some of the original authors of MySQL, with \
    assistance from the broader community of Free and open source software \
    developers. In addition to the core functionality of MySQL, MariaDB offers a \
    rich set of feature enhancements including alternate storage engines, server \
    optimizations, and patches.
homepage                http://mariadb.org/

distfiles

depends_run             port:mariadb

set major_version       [strsed ${version} {s/\..*$//}]
set mariadb             mysql5
set libdir              ${prefix}/lib/${mariadb}
set bindir              ${libdir}/bin
set dbdir               ${prefix}/var/db/${mariadb}
set sysconfdir          ${prefix}/etc/${mariadb}

if {"darwin" == ${os.platform} && ${os.major} > 8} {
    set mariadbuser       _mysql
} else {
    set mariadbuser       mysql
}

startupitem.create      yes
startupitem.name        ${mariadb}
startupitem.start       "${prefix}/share/${mariadb}/mysql/mysql.server start"
startupitem.stop        "${prefix}/share/${mariadb}/mysql/mysql.server stop"

use_configure           no
supported_archs         noarch

build {}

destroot {
    addgroup ${mariadbuser}
    set gid [existsgroup ${mariadbuser}]
    adduser ${mariadbuser} gid=${gid} realname=MariaDB\ Server
    
    xinstall -m 755 -o root -d ${destroot}${prefix}/var/run
    
    xinstall -m 755 -o ${mariadbuser} -g ${mariadbuser} -d \
        ${destroot}${dbdir} \
        ${destroot}${prefix}/var/log/${mariadb} \
        ${destroot}${prefix}/var/run/${mariadb}
    destroot.keepdirs-append  \
        ${destroot}${dbdir} \
        ${destroot}${prefix}/var/log/${mariadb} \
        ${destroot}${prefix}/var/run/${mariadb}
}

post-install {
    ui_msg "******************************************************"
    ui_msg "* In order to setup the database, you might want to run"
    ui_msg "* sudo -u ${mariadbuser} mysql_install_db5"
    ui_msg "* if this is a new install"
    ui_msg "******************************************************"
}
