askrobots / network-computer
Public
Your phone is the terminal. Stream a Linux/Mac desktop to an iPhone over WebRTC through NAT, with audio and input. Open source, single binaries.
Dan Quellhorst
Firefox policy: no WebRTC mDNS (a page using WebRTC made Firefox listen on UDP 5353)
a1d92f3
1 month, 3 weeks ago
History
nc-dashboard-info · 3.2 KB · 68 lines
| 1 | #!/bin/sh |
| 2 | # Lines for the desktop dashboard (conky runs this every minute): who and where |
| 3 | # this computer is, what it costs, and whether its services are up. Reads only |
| 4 | # /etc/nc/info (no secrets); API keys are listed by name, never value. |
| 5 | # "$$" is conky for "$". DigitalOcean bills at most 672 hours a month. |
| 6 | # |
| 7 | # nc-dashboard-info [full|compact|mini] |
| 8 | # full: everything (a big screen); compact and mini (smaller screens, a phone): |
| 9 | # the most important first, in fewer lines: services only as "ok" or by what is |
| 10 | # failing, cost as what was spent. See docs/DESIGN.md, "less room, less shown". |
| 11 | MODE=${1:-full} |
| 12 | [ -r /etc/nc/info ] && . /etc/nc/info |
| 13 | UP=$(awk '{print $1}' /proc/uptime) |
| 14 | failing() { |
| 15 | for s in host rendezvous voice object-server audio; do |
| 16 | systemctl is-active --quiet nc-$s 2>/dev/null || printf '%s ' "$s" |
| 17 | done |
| 18 | } |
| 19 | use_line() { |
| 20 | S=$(cat /run/nc-host/idle 2>/dev/null) |
| 21 | case "$S" in |
| 22 | busy*) echo "${S#busy } connected" ;; |
| 23 | idle-since*) echo "idle $(( ($(date +%s) - ${S#idle-since }) / 60 )) min" ;; |
| 24 | esac |
| 25 | } |
| 26 | if [ "$MODE" != full ]; then |
| 27 | F=$(failing) |
| 28 | if [ -n "$F" ]; then svc="\${color4}down: ${F% }\${color}"; else svc="\${color3}services ok\${color}"; fi |
| 29 | spent="" |
| 30 | [ -n "$NC_PRICE_HOURLY" ] && spent=$(awk -v p="$NC_PRICE_HOURLY" -v u="$UP" 'BEGIN{printf "$$%.2f spent", p*u/3600}') |
| 31 | if [ "$MODE" = mini ]; then |
| 32 | echo "\${color2}${NC_HOST_NAME:-$(hostname)}\${color} $svc" |
| 33 | echo "$(use_line)${spent:+ $spent}" |
| 34 | else |
| 35 | echo "\${color2}${NC_HOST_NAME:-$(hostname)}\${color} ${NC_DOMAIN:-${NC_PUBLIC_IP:-}}" |
| 36 | echo "$svc $(use_line)" |
| 37 | [ -n "$NC_PRICE_HOURLY" ] && awk -v p="$NC_PRICE_HOURLY" -v u="$UP" 'BEGIN{printf "$$%.3f/h $$%.2f since boot\n", p, p*u/3600}' |
| 38 | fi |
| 39 | exit 0 |
| 40 | fi |
| 41 | PRIV=$(curl -s -m 1 http://169.254.169.254/metadata/v1/interfaces/private/0/ipv4/address 2>/dev/null) |
| 42 | [ -n "$PRIV" ] || PRIV=$(ip -4 -o addr show 2>/dev/null | awk '$2!="lo" && $4 ~ /^10\.|^172\.(1[6-9]|2[0-9]|3[01])\.|^192\.168\./ {sub("/.*","",$4); print $4; exit}') |
| 43 | REGION=$(curl -s -m 1 http://169.254.169.254/metadata/v1/region 2>/dev/null) |
| 44 | echo "\${color2}THIS COMPUTER\${color}" |
| 45 | echo "name ${NC_HOST_NAME:-$(hostname)}${NC_DOMAIN:+ ($NC_DOMAIN)}" |
| 46 | echo "public ${NC_PUBLIC_IP:-?}" |
| 47 | echo "private ${PRIV:-none}" |
| 48 | echo "where ${REGION:-?} ${NC_SIZE}" |
| 49 | if [ -n "$NC_PRICE_HOURLY" ]; then |
| 50 | awk -v p="$NC_PRICE_HOURLY" -v u="$UP" 'BEGIN{ |
| 51 | printf "cost $$%.3f/h $$%.2f/day $$%.0f/month max\n", p, p*24, p*672 |
| 52 | printf "spent $$%.2f since this boot (%.1f h)\n", p*u/3600, u/3600 }' |
| 53 | fi |
| 54 | S=$(cat /run/nc-host/idle 2>/dev/null); A=$(cat /etc/nc/autostop 2>/dev/null) |
| 55 | case "$S" in |
| 56 | busy*) echo "use ${S#busy } device(s) connected" ;; |
| 57 | idle-since*) M=$(( ($(date +%s) - ${S#idle-since }) / 60 )) |
| 58 | echo "use idle ${M} min${A:+ (auto-stop at ${A} min)}" ;; |
| 59 | esac |
| 60 | echo |
| 61 | echo "\${color2}SERVICES\${color}" |
| 62 | for s in host rendezvous voice object-server audio; do |
| 63 | st=$(systemctl is-active nc-$s 2>/dev/null) |
| 64 | if [ "$st" = active ]; then c='${color3}'; else c='${color4}'; fi |
| 65 | printf "%-14s %s%s\${color}\n" "$s" "$c" "$st" |
| 66 | done |
| 67 | K=$(grep -o '^[A-Z_]*_KEY=.' "$HOME/.config/dbbasic/ai.env" 2>/dev/null | cut -d= -f1 | sed 's/_API_KEY$//;s/_KEY$//' | tr 'A-Z\n' 'a-z ') |
| 68 | echo "keys ${K:-none}" |