From e83b6d10360c64668538caee0b888a5238113a14 Mon Sep 17 00:00:00 2001 From: Jephte Clain Date: Fri, 17 Jun 2022 15:21:28 +0400 Subject: [PATCH] =?UTF-8?q?possibilit=C3=A9=20de=20choisir=20l'adresse=20I?= =?UTF-8?q?P?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cx-conndev | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/cx-conndev b/cx-conndev index c20cb04..8cdd645 100755 --- a/cx-conndev +++ b/cx-conndev @@ -29,6 +29,7 @@ OPTIONS } service=db +ipnum= mysql_cmd= mysqldump_cmd= klean= @@ -37,6 +38,7 @@ password= args=( --help '$exit_with display_help' -h:,-s:,--service: service= + -i:,--ipnum: ipnum= -c,--mysql-cmd mysql_cmd=1 -d,--mysqldump-cmd mysqldump_cmd=1 -k,--klean klean=1 @@ -72,7 +74,21 @@ setx cid=docker-compose ps -q "$service" 2>/dev/null || 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 +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 le cas échéant" +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"