# Porting mysqldump-secure (port maintainer?)



## cytopia (Mar 14, 2016)

Hi guys,

I am trying to fully port mysqldump-secure over to FreeBSD.
It is already at the state that the script itself is 100% fully working (POSIX shell without any bashism: #!/bin/sh).

I have one request as well as one error and one problem.


1. The request
I would like to get this as a port so I can use it via pkg or preferable via /usr/ports with make install.
However I have absolutely no idea about creating ports.

Maybe someone here wants to take over the port maintenance for that packet.
If so, either write it here or contact me with PM.
Full support will be given on any problems as well as full credit for that.



2. The problem

The problem I have is with tput and colored terminal output.
It works with OSX and Linux so far, but under FreeBSD I am not getting any colors.

The command I am using is as follows:

```
# If having a tty (console) use colors
if [ -t 1 ]; then
    CLR_OK="$(tput setf 2 2>/dev/null || tput setaf 2 2>/dev/null)"
    CLR_FATAL="$(tput setf 4 2>/dev/null || tput setaf 1 2>/dev/null)"
    CLR_ERROR="$(tput setf 4 2>/dev/null || tput setaf 1 2>/dev/null)"
    CLR_WARNING="$(tput setf 6 2>/dev/null || tput setaf 3 2>/dev/null)"
    CLR_DEBUG="$(tput setf 0 2>/dev/null || tput setaf 248 2>/dev/null)"
    CLR_TRACE="$(tput setf 0 2>/dev/null || tput setaf 242 2>/dev/null)"
    CLR_RESET="$(tput sgr0 2>/dev/null)"
# Dump terminal (e.g.: via cron)
else
    CLR_OK=""
    CLR_FATAL=""
    CLR_ERROR=""
    CLR_WARNING=""
    CLR_DEBUG=""
    CLR_TRACE=""
    CLR_RESET=""
fi
```

Any idea what is wrong here?



3. The error

Second, the error is that the Makefile is not working as it does under Linux or OSX.

I am getting the following errors:

```
make: "/root/repo/mysqldump-secure/Makefile" line 15: Unassociated shell command "ifneq ("$(wildcard configure.in)","")"
make: "/root/repo/mysqldump-secure/Makefile" line 16: Unassociated shell command "CONFIGURED = 1"
make: "/root/repo/mysqldump-secure/Makefile" line 17: Unassociated shell command "include configure.in"
make: "/root/repo/mysqldump-secure/Makefile" line 18: Need an operator
make: "/root/repo/mysqldump-secure/Makefile" line 20: Need an operator
make: "/root/repo/mysqldump-secure/Makefile" line 23: Missing dependency operator
make: "/root/repo/mysqldump-secure/Makefile" line 25: Need an operator
make: "/root/repo/mysqldump-secure/Makefile" line 27: Need an operator
make: "/root/repo/mysqldump-secure/Makefile" line 30: Missing dependency operator
make: "/root/repo/mysqldump-secure/Makefile" line 32: Need an operator
make: "/root/repo/mysqldump-secure/Makefile" line 33: Missing dependency operator
make: "/root/repo/mysqldump-secure/Makefile" line 35: Need an operator
make: "/root/repo/mysqldump-secure/Makefile" line 36: Missing dependency operator
make: "/root/repo/mysqldump-secure/Makefile" line 38: Need an operator
make: "/root/repo/mysqldump-secure/Makefile" line 39: Missing dependency operator
make: "/root/repo/mysqldump-secure/Makefile" line 41: Need an operator
make: "/root/repo/mysqldump-secure/Makefile" line 46: Missing dependency operator
make: "/root/repo/mysqldump-secure/Makefile" line 47: Need an operator
make: "/root/repo/mysqldump-secure/Makefile" line 48: Need an operator
make: "/root/repo/mysqldump-secure/Makefile" line 78: Missing dependency operator
make: "/root/repo/mysqldump-secure/Makefile" line 80: Need an operator
make: "/root/repo/mysqldump-secure/Makefile" line 82: Missing dependency operator
make: "/root/repo/mysqldump-secure/Makefile" line 83: warning: duplicate script for target "ifeq" ignored
make: "/root/repo/mysqldump-secure/Makefile" line 79: warning: using previous script for "ifeq" defined here
make: "/root/repo/mysqldump-secure/Makefile" line 84: Need an operator
make: "/root/repo/mysqldump-secure/Makefile" line 125: Missing dependency operator
make: "/root/repo/mysqldump-secure/Makefile" line 126: warning: duplicate script for target "ifeq" ignored
make: "/root/repo/mysqldump-secure/Makefile" line 79: warning: using previous script for "ifeq" defined here
make: "/root/repo/mysqldump-secure/Makefile" line 126: warning: duplicate script for target "(0,0)" ignored
make: "/root/repo/mysqldump-secure/Makefile" line 79: warning: using previous script for "(0,0)" defined here
make: "/root/repo/mysqldump-secure/Makefile" line 127: Need an operator
make: Fatal errors encountered -- cannot continue
make: stopped in /root/repo/mysqldump-secure
```


Unfortunately I have no idea, why this is not working under FreeBSD as it works flawlessly under OSX (and as far as I know they share most binaries...or?)

The Makefile itself can be found here:

https://github.com/cytopia/mysqldump-secure/blob/master/Makefile

Thanks for the time


----------



## SirDice (Mar 14, 2016)

cytopia said:


> Second, the error is that the Makefile is not working as it does under Linux or OSX.


You probably need to use devel/gmake instead of FreeBSD's make(1).


----------



## cytopia (Mar 15, 2016)

SirDice said:


> You probably need to use devel/gmake instead of FreeBSD's make(1).


Thanks for the info!

Is FreeBSD's make(1) compatible with Linux and OSX?
I don't want to pull in devel/gmake on FreeBSD just for the installation process... already put in too much effort to keep dependencies as low as possible


----------



## uzsolt (Mar 15, 2016)

You should use `USES=gmake` in port's Makefile. See more in Porter's Handbook.


----------



## msi (Mar 15, 2016)

There are many ports in FreeBSD that simply _need _devel/gmake where the effort to patch for FreeBSD make(1) exceeds reasonable efforts.

Some upstream won't accept patches since they decided to got with the gmake(1) and stick with it. Since you apparently are the upstream maintainer, you are in a better position to fix things. *cough* 

I'd first try with devel/gmake and get it working, and if you see a possibility to patch the makefiles without too much effort, go ahead.


----------



## kpa (Mar 15, 2016)

They are sort of compatible with extremely simplistic Makefiles that make no use of any advanced features of either one but in any real porting effort you should just use devel/gmake for the Makefiles from the Linux land.


----------



## SirDice (Mar 15, 2016)

cytopia said:


> I don't want to pull in devel/gmake on FreeBSD just for the installation process... already put in too much effort to keep dependencies as low as possible


There are differences between build, run and library dependencies. In this case gmake would be a build dependency, i.e. it's only needed to build the port. People installing the package will not get it as a dependency.


----------



## kpa (Mar 15, 2016)

SirDice said:


> There are differences between build, run and library dependencies. In this case gmake would be a build dependency, i.e. it's only needed to build the port. People installing the package will not get it as a dependency.



Note that there was a major change couple of years ago in how build dependencies were handled by the packages. Before the change your system was littered with build only dependencies if you installed packages because no one had cared to clean up the ports to include only the proper run time dependencies.


----------



## cytopia (Mar 15, 2016)

Ok thanks a lot for all the info. I will then probably stick to gmake.

Any idea why `tput` does not change the terminal color at all?


----------



## NewGuy (Mar 15, 2016)

I have created a rough first draft of the port for mysqldump-secure. The submission is here: https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=208032

Hopefully others will test it and/or have it committed to the ports tree.

Side note to cytopia: The configure script checks to see if the install directory exists and, if it does not, the configure script fails. However, the Makefile creates the installation directory in the next step of the installation. My suggestion would be to remove the check for the target directory in the configure script as installing to a new location will cause configure to fail.


----------



## cytopia (Mar 15, 2016)

NewGuy Thanks for the submission.
Also nice catch. I have removed the directory check in HEAD.

Just as a note: you have added v0.15 and I have released v0.16 just before opening the thread. But I guess that can be changed afterwards


----------



## NewGuy (Mar 15, 2016)

The port should be easy to update. When I put it together I was following the install instructions on the project's website which said 0.15 is the latest stable release.


----------



## cytopia (Mar 17, 2016)

NewGuy
Could you please explain the process about the submission to me (Or point me to some documentation where I can read up on it).

a.) It is on the mailing list now. What are the next required steps.
b.) You have attached a `shar` archive. What is this about and how did you create that

Is there some _more easy to read_ howto than the porters handbook out there?


----------



## SirDice (Mar 17, 2016)

Does this help? https://www.freebsd.org/doc/en_US.ISO8859-1/articles/contributing/ports-contributing.html


----------



## cytopia (Mar 17, 2016)

SirDice that made things clear.

I also saw the following in the `shar` submission:

```
XUSE_MYSQL=yes
```

Does this mean it pull in mysql or will it just check locally for a mysql[d] binary?


----------



## NewGuy (Mar 17, 2016)

USE_MYSQL will check to see if MySQL is installed. If not, the port pulls in MySQL as a dependency. By default, it currently uses MySQL 5.6 as the default version to install/use.


----------



## cytopia (Mar 17, 2016)

NewGuy said:


> USE_MYSQL will check to see if MySQL is installed. If not, the port pulls in MySQL as a dependency. By default, it currently uses MySQL 5.6 as the default version to install/use.


What happens if MariaDB is installed for example. (I know on some systems you cannot install both, but somehow the tools cannot specify that either or is sufficient).


----------



## NewGuy (Mar 17, 2016)

If MariaDB is installed (and at the appropriate version number) then the ports system will accept MariaDB in place of MySQL. So long as the /usr/local/bin/mysql binary is in place, the port considers the dependency met.


----------



## SirDice (Mar 17, 2016)

And if you want to make sure your dependencies are correct you can add to /etc/make.conf:

```
DEFAULT_VERSIONS+= mysql=100m
```
This will set the default "MySQL" to databases/mariadb100-client/databases/mariadb100-server.


----------



## cytopia (Mar 19, 2016)

Hi everybody,

I have tried to fix the `tput` issue by using color codes instead:

```
# If having a tty (console) use colors
if [ -t 1 ]; then
    CLR_FATAL="\033[0;31m"        # Red
    CLR_ERROR="\033[0;31m"        # Red
    CLR_WARNING="\033[0;33m"    # Yellow
    CLR_INFO=""
    CLR_OK="\033[0;32m"            # Green
    CLR_DEBUG="\033[0;37m"        # Gray
    CLR_TRACE="\033[0;37m"        # Gray
    CLR_RESET="\033[m"            # Normal
# Dump terminal (e.g.: via cron)
else
    CLR_FATAL=""
    CLR_ERROR=""
    CLR_WARNING=""
    CLR_INFO=""
    CLR_OK=""
    CLR_DEBUG=""
    CLR_TRACE=""
    CLR_RESET=""
fi
```

But now the output shows the color codes instead of the color itself:


```
\033[0;37m[TRACE] (RUN): MySQL connection test successful.
\033[0;37m[DEBUG] (SRV): MySQL server connection: Localhost via UNIX socket
\033[0;37m[DEBUG] (SRV): MySQL server connection: Not using SSL (plain).
\033[0;37m[DEBUG] (SRV): MySQL server rep type:   master
\033[0;37m[DEBUG] (SRV): MySQL server version:    5.6.22 Source distribution
\033[0;37m[DEBUG] (SRV): MySQL server hostname:   devel-jail.local.lan:3306
```

The color codes work under Linux (tested CentOS and Debian) as well as under OSX and even on Travis-CI (except for gray). Anything I am missing here?

The part of the code (`/bin/sh`) looks like this:


```
IFS='
        '
        for _line in ${_string}; do
            printf "%s%s${_suffix}\n" "${_prefix}" "${_line}" # stdout
        done
        unset IFS
```

`${_prefix}` contains the color code and the verbosity info e.g.: `\033[0;37m[DEBUG]`.

`${_suffix}` contains the resetting color code and `${_line}` is the actual message.


----------



## cytopia (Mar 19, 2016)

OK, got it working.

Somehow on FreeBSD the color codes for `printf` must be within the first argument.
So it works like this.

```
printf "${_prefix}%s${_suffix}\n" "${_line}" # stdout
```


Anyway, I have another question regarding the default log directory:

As I figured out already, ports always install to `/usr/local` and have their configuration in `/usr/local/etc` instead of `/etc` as Linux does.
Is this also true for logfiles?
Do they go to `/usr/local/var/log` or do they go to `/var/log`?


----------

