motd.sh: add rootless docker from userlist

This commit is contained in:
Alice Gaudon 2023-06-05 11:34:52 +02:00
parent e689665674
commit 39b4cdc3c0

16
motd.sh
View File

@ -69,6 +69,22 @@ done
printf "\nDocker:\n" printf "\nDocker:\n"
printf "$out" | column -ts $',' | sed -e 's/^/ /' 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 ### ### Disk space ###
# config # config