motd.sh: Make docker optional
This commit is contained in:
parent
c6192fc397
commit
cb8e2fc73f
68
motd.sh
68
motd.sh
@ -57,44 +57,46 @@ 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 [[ "${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
|
||||
|
||||
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"
|
||||
continue
|
||||
fi
|
||||
|
||||
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}}"))
|
||||
if [ ${#containers[@]} -eq 0 ]; then
|
||||
docker_out+=" ${redbg}/!\\\\${undim} - $user,${red}! No container !${undim}\n"
|
||||
continue
|
||||
fi
|
||||
|
||||
docker_out+=" - $user\n"
|
||||
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"
|
||||
docker_out+=" - ${containers[$i]},${green}${container_statuses[$i]}${undim}\n"
|
||||
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
|
||||
done
|
||||
done
|
||||
out+=$docker_out
|
||||
|
||||
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"
|
||||
continue
|
||||
fi
|
||||
|
||||
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}}"))
|
||||
if [ ${#containers[@]} -eq 0 ]; then
|
||||
docker_out+=" ${redbg}/!\\\\${undim} - $user,${red}! No container !${undim}\n"
|
||||
continue
|
||||
fi
|
||||
|
||||
docker_out+=" - $user\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
|
||||
out+=$docker_out
|
||||
fi
|
||||
|
||||
printf "$out" | column -ts $',' -o " "
|
||||
echo -e
|
||||
|
Loading…
Reference in New Issue
Block a user