#!/bin/bash -e

GREEN="\e[32m"
RED="\e[31m"
NC="\e[0m"

services=(
    rudesktop-analytics.service
    rudesktop-analytics.socket
)

print_status() {
    local svc=$1
    local active=$(systemctl is-active "$svc")
    local enabled=$(systemctl is-enabled "$svc")
    local since=$(systemctl show -p ActiveEnterTimestamp --value "$svc")
    local desc=$(systemctl show -p Description --value "$svc")
    local label="$svc ($desc)"

    if [[ "$active" == "active" ]]; then
        COLOR="$GREEN"
    else
        COLOR="$RED"
    fi

    printf "%-60s | %b%-7s%b | %-7s | %s\n" \
        "$label" "$COLOR" "$active" "$NC" "$enabled" "$since"
}

printf "%-60s | %-7s | %-7s | %s\n" "Service (Description)" "Active" "Enabled" "Since"
printf "%0.s-" {1..110}
echo

for svc in "${services[@]}"; do
    print_status "$svc"
done
