motd.sh: Make docker optional
This commit is contained in:
parent
c6192fc397
commit
cb8e2fc73f
24
motd.sh
24
motd.sh
@ -57,21 +57,22 @@ done
|
|||||||
|
|
||||||
|
|
||||||
### Docker ###
|
### Docker ###
|
||||||
out+="${bold}[DOCKER]${undim}\n"
|
if command -v docker &> /dev/null; then
|
||||||
containers=($(docker ps --format "{{.Image}}/{{.Names}}"))
|
out+="${bold}[DOCKER]${undim}\n"
|
||||||
container_statuses=($(docker ps --format "{{.State}}"))
|
containers=($(docker ps --format "{{.Image}}/{{.Names}}"))
|
||||||
docker_out=" [root]\n"
|
container_statuses=($(docker ps --format "{{.State}}"))
|
||||||
for i in ${!containers[@]}; do
|
docker_out=" [root]\n"
|
||||||
|
for i in ${!containers[@]}; do
|
||||||
if [[ "${container_statuses[$i]}" == "running" ]]; then
|
if [[ "${container_statuses[$i]}" == "running" ]]; then
|
||||||
docker_out+=" - ${containers[$i]},${green}${container_statuses[$i]}${undim}\n"
|
docker_out+=" - ${containers[$i]},${green}${container_statuses[$i]}${undim}\n"
|
||||||
else
|
else
|
||||||
docker_out+=" ${redbg}/!\\\\${undim} - ${containers[$i]},${red}${container_statuses[$i]}${undim}\n"
|
docker_out+=" ${redbg}/!\\\\${undim} - ${containers[$i]},${red}${container_statuses[$i]}${undim}\n"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
docker_out+=" [rootless]\n"
|
docker_out+=" [rootless]\n"
|
||||||
rootless_users=($(cat "$dir/.motd.users"))
|
rootless_users=($(cat "$dir/.motd.users"))
|
||||||
for user in ${rootless_users[@]}; do
|
for user in ${rootless_users[@]}; do
|
||||||
|
|
||||||
if sudo test ! -e /run/user/$(id -u $user)/docker.sock; then
|
if sudo test ! -e /run/user/$(id -u $user)/docker.sock; then
|
||||||
docker_out+=" ${redbg}/!\\\\${undim} - $user,${red}! Docker not running !${undim}\n"
|
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"
|
docker_out+=" ${redbg}/!\\\\${undim} - ${containers[$i]},${red}${container_statuses[$i]}${undim}\n"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
done
|
done
|
||||||
out+=$docker_out
|
out+=$docker_out
|
||||||
|
fi
|
||||||
|
|
||||||
printf "$out" | column -ts $',' -o " "
|
printf "$out" | column -ts $',' -o " "
|
||||||
echo -e
|
echo -e
|
||||||
|
Loading…
Reference in New Issue
Block a user