demo / network-computer
Public
Copy of github.com/askrobots/network-computer (MIT): a desk you reach from anything. The original lives on GitHub.
GitStable demo
README: say this is a copy and where the original is
cde82c2
14 hours, 3 minutes ago
History
nc-object-files · 1.6 KB · 34 lines
| 1 | #!/bin/sh |
| 2 | # The object server's files as a folder: ~/Objects on this desk, mounted over |
| 3 | # WebDAV (the object server's /dav/files/) with davfs2, so every app, the |
| 4 | # terminal and voice see them as plain files. Run by nc-object-files.service. |
| 5 | # |
| 6 | # nc-object-files mount | umount | status |
| 7 | # |
| 8 | # Signs in with an API key minted for the desk user by nc-object-bootstrap and |
| 9 | # kept root-only in /etc/nc/davfs2.secrets (on the desk volume when there is |
| 10 | # one). The object server has no locks, hence use_locks 0 in davfs2.conf. |
| 11 | . /etc/nc/env |
| 12 | U=$NC_DESK_USER |
| 13 | M=$(getent passwd "$U" | cut -d: -f6)/Objects |
| 14 | URL=http://127.0.0.1:8001/dav/files/ |
| 15 | case "$1" in |
| 16 | mount) |
| 17 | mountpoint -q "$M" && ls "$M" >/dev/null 2>&1 && exit 0 |
| 18 | # a dead mount (davfs2 was killed): "Transport endpoint is not connected" |
| 19 | if grep -qs " $M fuse" /proc/mounts; then umount -l "$M"; fi |
| 20 | rm -f "/var/run/mount.davfs/$(echo "${M#/}" | tr / -).pid" |
| 21 | [ -s /etc/nc/davfs2.secrets ] || { echo "no /etc/nc/davfs2.secrets (run nc-object-bootstrap)"; exit 1; } |
| 22 | install -d -o "$U" -g "$U" "$M" |
| 23 | # uid/gid: the files are the desk user's; 0600/0700 like the rest of home |
| 24 | exec mount -t davfs "$URL" "$M" \ |
| 25 | -o uid="$U",gid="$U",file_mode=0600,dir_mode=0700,conf=/etc/nc/davfs2.conf ;; |
| 26 | umount) |
| 27 | mountpoint -q "$M" || exit 0 |
| 28 | # davfs2 uploads what is still in its cache before it lets go |
| 29 | exec umount "$M" ;; |
| 30 | status) |
| 31 | mountpoint -q "$M" && ls "$M" >/dev/null 2>&1 && echo "mounted at $M" && exit 0 |
| 32 | echo "not mounted"; exit 1 ;; |
| 33 | *) echo "usage: nc-object-files mount|umount|status"; exit 2 ;; |
| 34 | esac |