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
verify.sh · 10.9 KB · 118 lines
| 1 | #!/bin/sh |
| 2 | # Check that a host has every piece of setup the network computer needs. |
| 3 | # Each line is a fix that was once done by hand; if it is not here, it was |
| 4 | # not captured in provisioning. Exits non-zero if anything fails. |
| 5 | # |
| 6 | # sh provision/verify.sh (run as root on the host; apply.sh runs it last) |
| 7 | export DISPLAY=:0 |
| 8 | PASS=0; FAIL=0 |
| 9 | check() { # check "<what>" <command...> |
| 10 | what=$1; shift |
| 11 | if "$@" >/dev/null 2>&1; then printf ' ok %s\n' "$what"; PASS=$((PASS+1)) |
| 12 | else printf ' FAIL %s\n' "$what"; FAIL=$((FAIL+1)); fi |
| 13 | } |
| 14 | has() { grep -q "$2" "$1" 2>/dev/null; } |
| 15 | |
| 16 | echo "services" |
| 17 | for s in nc-xorg nc-desktop nc-audio nc-rendezvous nc-host; do check "$s running" systemctl is-active --quiet "$s"; done |
| 18 | |
| 19 | echo "display" |
| 20 | check "X answers on :0" xset q |
| 21 | check "screen blanking off" sh -c 'xset q | grep -q "timeout: 0"' |
| 22 | check "uinput device available" test -c /dev/uinput |
| 23 | |
| 24 | echo "audio" |
| 25 | check "virtual sink 'nc' exists" sh -c 'pactl list short sinks | grep -qP "^\d+\tnc\t"' |
| 26 | check "sink runs at 48 kHz" sh -c 'pactl list short sinks | grep -P "\tnc\t" | grep -q 48000Hz' |
| 27 | check "'nc' is the default sink" sh -c '[ "$(pactl get-default-sink)" = nc ]' |
| 28 | check "pulse socket at /run/nc-pulse" test -S /run/nc-pulse/native |
| 29 | check "mic sink 'nc-mic' exists" sh -c 'pactl list short sinks | grep -qP "^\d+\tnc-mic\t"' |
| 30 | check "phone mic is the default input" sh -c '[ "$(pactl get-default-source)" = nc-mic-in ]' |
| 31 | check "host plays client mic (-mic-device)" sh -c 'systemctl cat nc-host | grep -q -- "-mic-device nc-mic"' |
| 32 | check "waveform launcher installed" sh -c 'command -v ffplay && command -v nc-mic-scope && test -f /usr/share/applications/nc-mic-scope.desktop' |
| 33 | check "sound recorder (Audacity) installed" command -v audacity |
| 34 | check "video player (VLC) is the default" sh -c 'command -v vlc && grep -q "^video/mp4=vlc.desktop" /etc/xdg/mimeapps.list' |
| 35 | check "file transfer (nc-send, Send to my device)" sh -c 'command -v nc-send && test -S /run/nc-host/send.sock && . /etc/nc/env; grep -q nc-send /home/$NC_DESK_USER/.config/Thunar/uca.xml' |
| 36 | check "printing (My device is the default printer)" sh -c 'lpstat -d | grep -q my-device && lpstat -p my-device | grep -q enabled && [ "$(stat -c %a /usr/lib/cups/backend/ncdevice)" = 700 ]' |
| 37 | check "camera: network-computer camera at /dev/video10, the desk user's" sh -c '. /etc/nc/env; [ "$(cat /sys/class/video4linux/video10/name)" = "network-computer camera" ] && [ "$(stat -c %U /dev/video10)" = "$NC_DESK_USER" ] && v4l2-ctl -d /dev/video10 -C keep_format | grep -q ": 1" && grep -q -- "-camera-device /dev/video10" /etc/systemd/system/nc-host.service' |
| 38 | check "live streams ready (MediaMTX $(/usr/local/bin/mediamtx --version 2>/dev/null), nc-stream)" sh -c 'test -x /usr/local/bin/mediamtx && test -f /etc/nc/mediamtx.yml && test -x /usr/local/bin/nc-stream && id nc-streams >/dev/null' |
| 39 | check "live streams: only SRT is reachable from outside, and only with a passphrase" sh -c 'systemctl is-active --quiet nc-streams || exit 0; test "$(grep -c "^MTX_PATHDEFAULTS_SRTPUBLISHPASSPHRASE=.\{10,\}" /etc/nc/streams.env)" = 1 && ! ss -Hltn | awk "{print \$4}" | grep -E ":(9997|9998|9996|8554|8888|8889)$" | grep -vqE "^(127\.0\.0\.1|\[::1\]):"' |
| 40 | check "hey desk: Vosk and its model for the stream ears" sh -c '/opt/piper/bin/python -c "import vosk" && test -f /opt/vosk/vosk-model-small-en-us-0.15/am/final.mdl' |
| 41 | check "talkback to phones: through https, and only with the passphrase" sh -c '. /etc/nc/info; [ -n "$NC_DOMAIN" ] || exit 0; systemctl is-active --quiet nc-voice || exit 0; test "$(curl -s -o /dev/null -w %{http_code} https://$NC_DOMAIN/talkback/api/voice/status)" = 401 && test "$(curl -s -o /dev/null -w %{http_code} -X POST https://$NC_DOMAIN/talkback/api/voice)" = 405' |
| 42 | check "search and launch bar (Alt+Space)" sh -c 'command -v rofi && command -v nc-launch && nc-as-user xfconf-query -c xfce4-keyboard-shortcuts -p "/commands/custom/<Alt>space" | grep -qx nc-launch' |
| 43 | check "object server answers (local only)" sh -c 'curl -sf http://127.0.0.1:8001/health >/dev/null && ! ss -ltn | grep -q "0.0.0.0:8001"' |
| 44 | check "voice listener running (nc-voice)" systemctl is-active --quiet nc-voice |
| 45 | check "computer controller (nc-desk) sees the screen" sh -c 'nc-desk screen | grep -q "\"ok\": true"' |
| 46 | check "only the needed ports are public" sh -c '! ss -ltnu | grep -E "0\.0\.0\.0:(5353|631|8001|8009|8765) |\*:(5353|631) "' |
| 47 | check "desk socket for the desk user only (0660)" sh -c 'test "$(stat -c %a /run/nc-host/send.sock)" = 660' |
| 48 | check "object server sign-in needs a one-time code" sh -c 'curl -s -o /dev/null -w "%{http_code}" "http://localhost:8009/open?next=/" | grep -qx 403 && ! ss -ltn | grep -q "0.0.0.0:8009" && test "$(stat -c %a /run/nc-voice)" = 700' |
| 49 | check "self-check timer (nc-health) active" systemctl is-active --quiet nc-health.timer |
| 50 | check "memory: swap on, earlyoom running" sh -c 'swapon --show=NAME --noheadings | grep -q . && systemctl is-active --quiet earlyoom' |
| 51 | check "desktop dashboard running (conky)" pgrep -x conky |
| 52 | check "dashboard layouts for small screens (compact, mini)" sh -c 'test -f /etc/nc-dashboard/compact.conf && test -f /etc/nc-dashboard/mini.conf && command -v xdpyinfo' |
| 53 | check "dashboard Today: weather, headlines, radio (nc-feeds, nc-radio, defaults)" sh -c 'test -f /etc/nc-dashboard/feeds.txt && test -f /etc/nc-dashboard/stations.txt && test -f /etc/nc-dashboard/dashboard.env && nc-as-user nc-feeds lines full >/dev/null && nc-as-user nc-radio now >/dev/null && command -v cvlc >/dev/null && command -v zenity >/dev/null && test -f /usr/share/applications/nc-today.desktop && test -f /usr/share/applications/nc-radio.desktop' |
| 54 | check "object server app windows (WebKitGTK)" python3 -c "import gi; gi.require_version(\"WebKit2\", \"4.1\"); from gi.repository import WebKit2" |
| 55 | check "object server daemon (notifications)" systemctl is-active --quiet nc-object-daemon |
| 56 | check "object server files as ~/Objects (WebDAV)" nc-object-files status |
| 57 | check "AI keys in ~/.config/dbbasic/ai.env (0600, the user's)" sh -c '. /etc/nc/env; H=$(getent passwd "$NC_DESK_USER" | cut -d: -f6); test "$(stat -L -c %U:%a "$H/.config/dbbasic/ai.env")" = "$NC_DESK_USER:600"' |
| 58 | check "package installs never restart nc-* services" test -f /etc/needrestart/conf.d/nc.conf |
| 59 | check "~/Objects key is root-only" sh -c 'test "$(stat -L -c %U:%a /etc/nc/davfs2.secrets)" = root:600' |
| 60 | check "/dav/ refuses a request without a key" sh -c 'curl -s -o /dev/null -w "%{http_code}" -X PROPFIND http://127.0.0.1:8001/dav/files/ | grep -qx 401' |
| 61 | check "ALSA apps record from pulse" sh -c 'timeout 5 arecord -q -D default -d 1 -f S16_LE -r 48000 -c 2 /dev/null' |
| 62 | check "pavucontrol installed" command -v pavucontrol |
| 63 | check "no pulse autospawn override" sh -c '! test -e /etc/pulse/client.conf.d/01-enable-autospawn.conf' |
| 64 | |
| 65 | echo "browser + default apps" |
| 66 | check "Firefox from Mozilla (not snap)" sh -c 'dpkg-query -W -f="\${Version}" firefox | grep -q build' |
| 67 | check "https opens Firefox" sh -c '[ "$(xdg-mime query default x-scheme-handler/https)" = firefox.desktop ]' |
| 68 | check "xfce WebBrowser helper = firefox" has /etc/xdg/xfce4/helpers.rc '^WebBrowser=firefox' |
| 69 | check "keyboard layout tools installed" sh -c 'command -v nc-keyboard && command -v nc-input-hook && command -v setxkbmap && command -v xinput' |
| 70 | check "screen resize helper installed" sh -c 'command -v nc-display && command -v cvt && command -v xrandr' |
| 71 | check "xdotool installed" command -v xdotool |
| 72 | |
| 73 | echo "desktop polish" |
| 74 | check "cloud config drive hidden from the desktop" sh -c 'd=$(blkid -L config-2) || exit 0; udevadm info --query=property --name="$d" | grep -qx UDISKS_IGNORE=1' |
| 75 | check "mousepad word wrap on" sh -c '[ "$(gsettings get org.xfce.mousepad.preferences.view word-wrap)" = true ]' |
| 76 | |
| 77 | set -a; . /etc/nc/env 2>/dev/null; set +a # NC_DOMAIN decides the firewall check |
| 78 | echo "network" |
| 79 | check "IPv6 disabled (no route here)" sh -c '[ "$(cat /proc/sys/net/ipv6/conf/all/disable_ipv6)" = 1 ]' |
| 80 | if [ -n "$NC_DOMAIN" ]; then # https on 443; 8765 is loopback only |
| 81 | check "firewall closes 8765/tcp (domain)" sh -c '! ufw status | grep -q "8765/tcp"' |
| 82 | else |
| 83 | check "firewall allows 8765/tcp" sh -c 'ufw status | grep -q "8765/tcp"' |
| 84 | fi |
| 85 | check "firewall allows 3478/udp" sh -c 'ufw status | grep -q "3478/udp"' |
| 86 | |
| 87 | echo "network computer" |
| 88 | set -a; . /etc/nc/env 2>/dev/null; set +a # export, so the checks below see them |
| 89 | check "rendezvous accepts the password" sh -c 'curl -sf -o /dev/null -u "nc:$NC_PASSWORD" http://127.0.0.1:8765/hosts' |
| 90 | check "host name recorded in /etc/nc/env" test -n "$NC_HOST_NAME" |
| 91 | check "host registered as '$NC_HOST_NAME'" sh -c 'curl -sf -u "nc:$NC_PASSWORD" http://127.0.0.1:8765/hosts | grep -q "\"$NC_HOST_NAME\""' |
| 92 | if [ -n "$NC_DOMAIN" ]; then |
| 93 | echo "https ($NC_DOMAIN)" |
| 94 | check "DNS points $NC_DOMAIN here" sh -c '[ "$(getent ahostsv4 "$NC_DOMAIN" | awk "NR==1{print \$1}")" = "$NC_PUBLIC_IP" ]' |
| 95 | check "valid certificate (no -k)" sh -c 'curl -sf -o /dev/null --max-time 20 "https://$NC_DOMAIN/"' |
| 96 | check "reports secure mode" sh -c 'curl -sf -X POST --max-time 10 "https://$NC_DOMAIN/auth" -d "{\"user\":\"nc\",\"password\":\"$NC_PASSWORD\"}" | grep -q "\"mode\":\"secure\""' |
| 97 | check "local host listener (loopback)" sh -c 'curl -sf -o /dev/null -u "nc:$NC_PASSWORD" http://127.0.0.1:8765/hosts' |
| 98 | check "firewall allows 80,443/tcp" sh -c 'ufw status | grep -q "^80/tcp" && ufw status | grep -q "^443/tcp"' |
| 99 | fi |
| 100 | if [ -n "$NC_KEYBOARD" ]; then |
| 101 | check "desktop layout is $NC_KEYBOARD" sh -c 'v=${NC_KEYBOARD#*:}; [ "$v" = "$NC_KEYBOARD" ] && v=""; DISPLAY=:0 setxkbmap -query | grep -q "^layout: *${NC_KEYBOARD%%:*}" && { [ -z "$v" ] || DISPLAY=:0 setxkbmap -query | grep -q "^variant: *$v"; }' |
| 102 | fi |
| 103 | echo "desktop user" |
| 104 | check "desktop runs as '$NC_DESK_USER', not root" sh -c 'pgrep -u "$NC_DESK_USER" -x xfce4-session && ! pgrep -u root -x xfce4-session' |
| 105 | if ls /dev/disk/by-id/scsi-0DO_Volume_desk-* >/dev/null 2>&1; then |
| 106 | echo "desk" |
| 107 | check "desk mounted at /desk" mountpoint -q /desk |
| 108 | check "desk under 80% full" sh -c '[ "$(df --output=pcent /desk | tail -1 | tr -dc 0-9)" -lt 80 ]' |
| 109 | check "identity lives on the desk (0600)" sh -c '[ "$(readlink /etc/nc/env)" = /desk/nc/env ] && [ "$(stat -c %a /desk/nc/env)" = 600 ]' |
| 110 | check "pairing secret on the desk (0600)" sh -c '[ "$(readlink /var/lib/nc-host)" = /desk/nc/host ] && [ "$(stat -c %a /desk/nc/host/pair.key)" = 600 ]' |
| 111 | check "certificate cache on the desk" sh -c '[ "$(readlink /var/lib/nc-rendezvous)" = /desk/nc/rendezvous ]' |
| 112 | check "locker folders live on the desk" sh -c 'h=$(getent passwd "$NC_DESK_USER" | cut -d: -f6); for p in Documents Desktop .config; do [ "$(readlink "$h/$p")" = "/desk/home/$p" ] || exit 1; done' |
| 113 | check "secrets folder private to the user" sh -c '[ "$(stat -c %a:%U /desk/secrets)" = "700:$NC_DESK_USER" ]' |
| 114 | check "services wait for the desk at boot" sh -c 'for s in nc-host nc-rendezvous nc-desktop; do systemctl show -p RequiresMountsFor $s | grep -q /desk || exit 1; done' |
| 115 | fi |
| 116 | echo |
| 117 | echo "$PASS ok, $FAIL failed" |
| 118 | [ "$FAIL" -eq 0 ] |