From 39b4cdc3c0ced80a6561d6fa74094c49b4f86e51 Mon Sep 17 00:00:00 2001 From: Alice Gaudon Date: Mon, 5 Jun 2023 11:34:52 +0200 Subject: [PATCH] motd.sh: add rootless docker from userlist --- motd.sh | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/motd.sh b/motd.sh index 3880e8e..40e7659 100755 --- a/motd.sh +++ b/motd.sh @@ -69,6 +69,22 @@ done printf "\nDocker:\n" printf "$out" | column -ts $',' | sed -e 's/^/ /' +rootless_users=($(cat /.motd.users)) +for user in ${rootless_users[@]}; do + containers=($(sudo -n DOCKER_HOST=unix:///run/user/$(id -u $user)/docker.sock docker ps --format "{{.Image}}/{{.Names}}")) + container_statuses=($(sudo -n DOCKER_HOST=unix:///run/user/$(id -u $user)/docker.sock docker ps --format "{{.State}}")) + out="" + for i in ${!containers[@]}; do + if [[ "${container_statuses[$i]}" == "running" ]]; then + out+="${containers[$i]}:,${green}${container_statuses[$i]}${undim}," + else + out+="${containers[$i]}:,${red}${container_statuses[$i]}${undim}," + fi + out+="\n" + done + printf "\nDocker > $user:\n" + printf "$out" | column -ts $',' | sed -e 's/^/ /' +done ### Disk space ### # config