56 lines
1.3 KiB
Plaintext
56 lines
1.3 KiB
Plaintext
|
#!/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"
|
||
|
|
||
|
###
|
||
|
|
||
|
setx cid=docker-compose ps -q "$service" 2>/dev/null || die "$service: service introuvable"
|
||
|
|
||
|
setx ip=docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' "$cid"
|
||
|
edebug "$service: $ip"
|
||
|
|
||
|
mysqlcmd="$(php bin/conndev.php -- "$ip" "$@")"
|
||
|
edebug "mysqlcmd: $mysqlcmd"
|
||
|
|
||
|
eval "$mysqlcmd"
|