#!/usr/bin/env bash
VERSION='v2.3'
warn() { echo "$@" >&2; }
die() { warn "$@"; exit 1; }
DETECT=$(perl -MNarada -E 'say Narada::detect(@ARGV)') || exit 1
if test "$DETECT" = "narada"; then
config_dir='config/mysql'
else
config_dir='config/db'
fi
[ $# -eq 0 ] || die "Usage: narada-mysql"
if [ ! -s "$config_dir/db" ]; then
echo "ERROR: $config_dir/db absent or empty!" >&2
exit 1
fi
restore_umask=$(umask -p)
umask 0077
echo '[client]' > tmp/my.cnf.$$
$restore_umask
echo database = "$(< "$config_dir/db" )" >> tmp/my.cnf.$$
echo user = "$(< "$config_dir/login" )" >> tmp/my.cnf.$$
[ -s "$config_dir/pass" ] && echo password = "$(< "$config_dir/pass" )" >> tmp/my.cnf.$$
[ -s "$config_dir/host" ] && echo host = "$(< "$config_dir/host" )" >> tmp/my.cnf.$$
[ -s "$config_dir/port" ] && echo port = "$(< "$config_dir/port" )" >> tmp/my.cnf.$$
exec 3< tmp/my.cnf.$$
rm tmp/my.cnf.$$
exec mysql --defaults-file=/proc/self/fd/3 --pager=less\ -XSFe
: <<'=cut'
=encoding utf8
=head1 NAME
narada-mysql - start mysql client for this project
=head1 VERSION
This document describes narada-mysql version v2.3=head1 USAGE
narada-mysql
=head1 DESCRIPTION
Should be executed in project deploy directory (or Narada 1.x project root
directory).
Start mysql client using connection details from C<config/mysql/>.
=head1 CONFIGURATION AND ENVIRONMENT
config/mysql/db
config/mysql/login
config/mysql/pass
config/mysql/host (optional)
config/mysql/port (optional)
Narada 1.x project use C<config/db/> instead of C<config/mysql/>.
=head1 SUPPORT
=head2 Bugs / Feature Requests
Please report any bugs or feature requests through the issue tracker
at L<https://github.com/powerman/Narada/issues>.
You will be notified automatically of any progress on your issue.
=head2 Source Code
This is open source software. The code repository is available for
public review and contribution under the terms of the license.
Feel free to fork the repository and submit pull requests.
L<https://github.com/powerman/Narada>
git clone https://github.com/powerman/Narada.git
=head2 Resources
=over
=item * MetaCPAN Search
L<https://metacpan.org/search?q=Narada>
=item * CPAN Ratings
L<http://cpanratings.perl.org/dist/Narada>
=item * AnnoCPAN: Annotated CPAN documentation
L<http://annocpan.org/dist/Narada>
=item * CPAN Testers Matrix
L<http://matrix.cpantesters.org/?dist=Narada>
=item * CPANTS: A CPAN Testing Service (Kwalitee)
L<http://cpants.cpanauthors.org/dist/Narada>
=back
=head1 AUTHOR
Alex Efros E<lt>powerman@cpan.orgE<gt>
=head1 COPYRIGHT AND LICENSE
This software is Copyright (c) 2008-2015 by Alex Efros E<lt>powerman@cpan.orgE<gt>.
This is free software, licensed under:
The MIT (X11) License
=cut