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"