possibilité de choisir l'adresse IP

This commit is contained in:
Jephté Clain 2022-06-17 15:21:28 +04:00
parent af9096df0c
commit e83b6d1036
1 changed files with 17 additions and 1 deletions

View File

@ -29,6 +29,7 @@ OPTIONS
} }
service=db service=db
ipnum=
mysql_cmd= mysql_cmd=
mysqldump_cmd= mysqldump_cmd=
klean= klean=
@ -37,6 +38,7 @@ password=
args=( args=(
--help '$exit_with display_help' --help '$exit_with display_help'
-h:,-s:,--service: service= -h:,-s:,--service: service=
-i:,--ipnum: ipnum=
-c,--mysql-cmd mysql_cmd=1 -c,--mysql-cmd mysql_cmd=1
-d,--mysqldump-cmd mysqldump_cmd=1 -d,--mysqldump-cmd mysqldump_cmd=1
-k,--klean klean=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" edebug "$service id: $cid"
function die_not_found() { die "$service: $cid: ip introuvable"; } 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 [ -n "$ip" ] || die_not_found
edebug "$service ip: $ip" edebug "$service ip: $ip"