nutools/cx-conndev

61 lines
1.5 KiB
Bash
Executable File

#!/bin/bash
# -*- coding: utf-8 mode: sh -*- vim:sw=4:sts=4:et:ai:si:sta:fenc=utf-8
source "$(dirname "$0")/lib/ulib/ulib" || exit 1
urequire DEFAULTS
function display_help() {
uecho "$scriptname: se connecter à la base MySQL
USAGE
$scriptname [DATABASE]
OPTIONS
-h, -s, --service SERVICE
Spécifier le nom du service. La valeur par défaut est db"
}
service=db
args=(
--help '$exit_with display_help'
-h:,-s:,--service: service=
)
parse_args "$@"; set -- "${args[@]}"
[ -n "$service" ] || die "Vous devez spécifier le nom du service"
found=
first=1
while true; do
if [ -f composer.json ]; then
found=1
break
fi
first=
cd ..
if [ "$(pwd)" == "$HOME" ]; then
die "Cette commande ne peut être lancée que depuis un projet Composer"
fi
done
if [ -z "$first" ]; then
enote "Le répertoire du projet est $(ppath . ~)"
fi
[ -f bin/conndev.php ] || die "Impossible de trouver le script compagnon conndev.php"
###
function die_not_found() { die "$service: service introuvable"; }
setx cid=docker-compose ps -q "$service" 2>/dev/null || die_not_found
[ -n "$cid" ] || die_not_found
edebug "$service id: $cid"
function die_not_found() { die "$service: $cid: ip introuvable"; }
setx ip=docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' "$cid" || die_not_found
[ -n "$ip" ] || die_not_found
edebug "$service ip: $ip"
mysqlcmd="$(php bin/conndev.php "$ip" "$@")"
edebug "mysqlcmd: $mysqlcmd"
eval "$mysqlcmd"