Skip to content

Instantly share code, notes, and snippets.

@scottstanfield
Created March 11, 2024 17:56
Show Gist options
  • Select an option

  • Save scottstanfield/5c44ca6bb18ef1e00a30570906c3f7cf to your computer and use it in GitHub Desktop.

Select an option

Save scottstanfield/5c44ca6bb18ef1e00a30570906c3f7cf to your computer and use it in GitHub Desktop.

Revisions

  1. scottstanfield created this gist Mar 11, 2024.
    77 changes: 77 additions & 0 deletions splash
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,77 @@
    #!/bin/bash
    # vim:filetype=bash:

    readonly _D="$(dirname "$(readlink -f "$0")")" && cd $_D

    ansi_colors()
    {
    esc=""

    black="$esc[30m"; red="$esc[31m"; green="$esc[32m"
    yellow="$esc[33m" blue="$esc[34m"; purple="$esc[35m"
    cyan="$esc[36m"; white="$esc[37m"

    blackb="$esc[40m"; redb="$esc[41m"; greenb="$esc[42m"
    yellowb="$esc[43m" blueb="$esc[44m"; purpleb="$esc[45m"
    cyanb="$esc[46m"; whiteb="$esc[47m"

    bold="$esc[1m"; boldoff="$esc[22m"
    italics="$esc[3m"; italicsoff="$esc[23m"
    ul="$esc[4m"; uloff="$esc[24m"
    inv="$esc[7m"; invoff="$esc[27m"

    reset="$esc[0m"
    r="$esc[0m"
    }

    ansi_colors

    # 32, 33, 36
    # green, yellow, cyan

    h3="$reset$bold$purple"
    h2="$reset$bold$yellow"
    h1="$reset$bold$green"
    p1="$reset"

    function cpufreq()
    {
    min=$(cat /sys/devices/system/cpu/cpufreq/policy0/scaling_min_freq)
    cur=$(cat /sys/devices/system/cpu/cpufreq/policy0/scaling_cur_freq)
    max=$(cat /sys/devices/system/cpu/cpufreq/policy0/scaling_max_freq)
    printf "%s MHz [min=%s max=%s]" $(($cur / 1000)) $(($min / 1000)) $(($max / 1000))
    }


    ip="$(ip route get 1.1.1.1 | head -1 | cut -d' ' -f7)"
    kernel="$(uname -srm)"
    os="$(source /etc/os-release; echo $NAME $VERSION)"
    uptime="$(uptime -p | sed 's/up //')"
    load=$(cat /proc/loadavg | cut -d ' ' -f 1,2,3)
    temperature="$(vcgencmd measure_temp | cut -d '=' -f 2)"
    temperature="$(vcgencmd measure_temp | tr -cd '[0-9].')"
    #cpu_t1k=$(cat /sys/class/thermal/thermal_zone0/temp)
    #cpu_t=$(printf %.1f "$((10**3 * $cpu_t1k / 1000))e-3")
    temps="$temperature° C"
    #fan_speed=$(cat /sys/devices/platform/cooling_fan/hwmon/*/fan1_input)
    freq=$(cpufreq)

    # Useful for repos
    # version="${MOABIAN:-3.0.0}"
    # branch="$(git status | head -n 1 | cut -d " " -f 3)"
    # sha="$(git rev-parse HEAD | cut -c 1-4)"
    # moabian_version="${version} · ${branch}:${sha^^}"

    #

    cat <<EOF
    ${h2} · Hostname ${r}${os}
    ${h2} · Kernel ${r}${kernel}
    ${h2} · Load ${r}${load}
    ${h2} · CPU ${r}${temps}
    ${h2} · Frequency ${r}${freq}
    ${h2} · IP ${r}${ip}
    ${h1} ○ Hostname ${h3}$(hostname)
    EOF