Make motd.sh compatible with NixOS

This commit is contained in:
Alice Gaudon 2023-08-19 19:31:39 +02:00
parent 825edbe388
commit c6192fc397
2 changed files with 9 additions and 5 deletions

4
.gitignore vendored
View File

@ -1,2 +1,4 @@
*.lock
caddy_docker_custom_user/run_*
caddy_docker_custom_user/run_*
.motd.services
.motd.users

10
motd.sh
View File

@ -1,4 +1,5 @@
#!/bin/bash
#!/usr/bin/env bash
dir=$(dirname "$0")
### Time and date ###
echo -e "$(date)"
@ -11,7 +12,8 @@ echo -e
### System info ###
echo -e "$(cat /etc/*release | grep PRETTY_NAME | cut -d = -f 2- | sed 's/\"//g') | Kernel: $(uname -r)"
echo -e "Uptime: $(uptime -p | sed 's/up //')"
uptime=$(uptime | awk -F'( |,|:)+' '{d=h=m=0; if ($7=="min") m=$6; else {if ($7~/^day/) {d=$6;h=$8;m=$9} else {h=$6;m=$7}}} {print d+0,"days,",h+0,"hours,",m+0,"minutes."}')
echo -e "Uptime: ${uptime}"
echo -e
### Colors ###
@ -32,7 +34,7 @@ redbg="\e[41m"
greenbg="\e[42m"
### Services ###
services=($(cat /.motd.services))
services=($(cat "$dir/.motd.services"))
# sort services
#IFS=$'\n' services=($(sort <<<"${services[*]}"))
#unset IFS
@ -68,7 +70,7 @@ for i in ${!containers[@]}; do
done
docker_out+=" [rootless]\n"
rootless_users=($(cat /.motd.users))
rootless_users=($(cat "$dir/.motd.users"))
for user in ${rootless_users[@]}; do
if sudo test ! -e /run/user/$(id -u $user)/docker.sock; then