#!/bin/bash # -*- coding: utf-8 mode: sh -*- vim:sw=4:sts=4:et:ai:si:sta:fenc=utf-8 source "$(dirname -- "$0")/lib/ulib/auto" || exit 1 [ -n "$COMPOSE_V1" ] && DOCKER_COMPOSE=(docker-compose) || DOCKER_COMPOSE=(docker compose) function display_help() { uecho "$scriptname: se connecter à la base MySQL USAGE $scriptname [DATABASE] $scriptname -d [-uUSER [-pPASSWORD]] DATABASES... >backup.sql $scriptname -c [-uUSER [-pPASSWORD]] /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 ipdesc="${ip%,}" if [ -z "$ipnum" ] && [[ "$ipdesc" == *,* ]]; then enote "Le service est accessible sur plusieurs adresses ip: $ipdesc" enote "Pensez à spécifier l'option -i pour désigner l'adresse à utiliser (-i1 pour la première, -i2 pour la seconde, etc.)" fi if [ -n "$ipnum" ]; then let ipnum=ipnum-1 while [ $ipnum -gt 0 ]; do ip="${ip#*,}" let ipnum=ipnum-1 done fi ip="${ip%%,*}" [ -n "$ip" ] || die_not_found edebug "$service ip: $ip" if [ -n "$mysql_cmd" ]; then mysql -h"$ip" ${user:+-u"$user"} ${password:+-p"$password"} "$@" elif [ -n "$mysqldump_cmd" ]; then mysqldump --databases --add-drop-database -h"$ip" ${user:+-u"$user"} ${password:+-p"$password"} "$@" elif [ -n "$klean" ]; then estep "klean" docker exec "$cid" klean estep "wait 10sec..." sleep 10 estep "start" "${DOCKER_COMPOSE[@]}" start "$service" else [ -f bin/conndev.php ] || die "Impossible de trouver le script compagnon conndev.php" mysql_cmd="$(php bin/conndev.php "$ip" "$@")" edebug "mysql_cmd: $mysql_cmd" eval "$mysql_cmd" fi