motd.sh: Make docker optional

This commit is contained in:
Alice Gaudon 2023-08-19 19:43:01 +02:00
parent c6192fc397
commit cb8e2fc73f

24
motd.sh
View File

@ -57,21 +57,22 @@ done
### Docker ###
out+="${bold}[DOCKER]${undim}\n"
containers=($(docker ps --format "{{.Image}}/{{.Names}}"))
container_statuses=($(docker ps --format "{{.State}}"))
docker_out=" [root]\n"
for i in ${!containers[@]}; do
if command -v docker &> /dev/null; then
out+="${bold}[DOCKER]${undim}\n"
containers=($(docker ps --format "{{.Image}}/{{.Names}}"))
container_statuses=($(docker ps --format "{{.State}}"))
docker_out=" [root]\n"
for i in ${!containers[@]}; do
if [[ "${container_statuses[$i]}" == "running" ]]; then
docker_out+=" - ${containers[$i]},${green}${container_statuses[$i]}${undim}\n"
else
docker_out+=" ${redbg}/!\\\\${undim} - ${containers[$i]},${red}${container_statuses[$i]}${undim}\n"
fi
done
done
docker_out+=" [rootless]\n"
rootless_users=($(cat "$dir/.motd.users"))
for user in ${rootless_users[@]}; do
docker_out+=" [rootless]\n"
rootless_users=($(cat "$dir/.motd.users"))
for user in ${rootless_users[@]}; do
if sudo test ! -e /run/user/$(id -u $user)/docker.sock; then
docker_out+=" ${redbg}/!\\\\${undim} - $user,${red}! Docker not running !${undim}\n"
@ -93,8 +94,9 @@ for user in ${rootless_users[@]}; do
docker_out+=" ${redbg}/!\\\\${undim} - ${containers[$i]},${red}${container_statuses[$i]}${undim}\n"
fi
done
done
out+=$docker_out
done
out+=$docker_out
fi
printf "$out" | column -ts $',' -o " "
echo -e