Mount SFTP folders in network storage, as CoreDesktop does
configure storage now finds machines that announce SFTP as well as SMB servers, and takes sftp://[user@]host[:port][/path] addresses. Folders are mounted with SSHFS on macFUSE, as you, with your SSH keys (Bitwarden's SSH agent while it runs one), and never ask for a password. storage-mount mounts them again at login and when the network changes, as it does SMB shares; each line of the list now records its mount point. macFUSE and SSHFS are offered for download, checked against their Team ID (3T5GSNBU6W, read from the packages' signatures). On macOS 26 and later macFUSE mounts through FSKit, whose extension you turn on once in System Settings. Earlier macOS needs its kernel extension, which this uses if it's running but doesn't set up. smoketest: 85-sftp installs both and mounts a folder from the VM itself over SSH, if macFUSE's extension can be turned on there. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -41,7 +41,9 @@ To run it as just `configure`, link it into a directory on your PATH, e.g. `ln -
|
|||||||
- launchd starts it hourly and at login, and it backs up once a day, so a Mac that was asleep or off catches up soon after. It's started through a small app, "Federated Backup" in ~/Applications, because macOS only lets apps into Desktop, Documents, Mail and Photos once you give them Full Disk Access. `configure` opens the right place in System Settings and checks that it worked. Without it, backups leave those folders out and you get a notification each time.
|
- launchd starts it hourly and at login, and it backs up once a day, so a Mac that was asleep or off catches up soon after. It's started through a small app, "Federated Backup" in ~/Applications, because macOS only lets apps into Desktop, Documents, Mail and Photos once you give them Full Disk Access. `configure` opens the right place in System Settings and checks that it worked. Without it, backups leave those folders out and you get a notification each time.
|
||||||
- The log is `~/Library/Logs/Federated Connector/backup.log`. Run `configure backup` again to back up now or to turn backups off; turning them off also offers to delete the backups.
|
- The log is `~/Library/Logs/Federated Connector/backup.log`. Run `configure backup` again to back up now or to turn backups off; turning them off also offers to delete the backups.
|
||||||
- To restore, see "Restoring from a backup" below.
|
- To restore, see "Restoring from a backup" below.
|
||||||
- **Network storage**: shared folders (SMB) from Windows PCs, NAS boxes and Macs with File Sharing on. It finds them on your network, or you enter an address (`smb://nas.local/files`; leave out the share to choose from a list). macOS mounts them in /Volumes and shows them in Finder's sidebar, and its sign-in window can keep the password in your keychain. A launchd job mounts them again at login and when the network changes, skipping servers it can't reach. Folders over SSH (SFTP) need macFUSE, which this doesn't set up.
|
- **Network storage**: shared folders from other machines on your network, mounted in /Volumes and shown in Finder's sidebar. It finds SMB servers (Windows PCs, NAS boxes, Macs with File Sharing on) and machines that announce SFTP (Macs with Remote Login on, many Linux machines), or you enter an address (`smb://nas.local/files`, `sftp://me@server.local/srv/data`). A launchd job mounts them again at login and when the network changes, skipping servers it can't reach. "Remove one" unmounts it and takes it off the list.
|
||||||
|
- **SMB** is built into macOS. Leave out the share to choose from a list. The sign-in window can keep the password in your keychain, and mounting again at login needs it there.
|
||||||
|
- **SFTP** uses [macFUSE](https://macfuse.github.io) and SSHFS, which `configure storage` offers to install. It needs macOS 26 or later, where macFUSE runs in user space through FSKit; you turn on its file system extension once, in System Settings > General > Login Items & Extensions. On earlier macOS, macFUSE needs its kernel extension, which on Apple silicon means starting up in Recovery and lowering security. This doesn't do that, but it uses the kernel extension if you've set it up yourself. As in CoreDesktop, an SFTP folder is mounted as you with your SSH keys (Bitwarden's SSH agent while it's running, otherwise macOS' agent and `~/.ssh`) and never asks for a password, so the server has to accept one of your keys.
|
||||||
- **AI agents**: offers to install Claude Code, opencode and Hermes Agent with each one's own installer, and runs them in a sandbox (see below). `configure claude`, `configure opencode` and `configure hermes` sign in to them and choose their model providers.
|
- **AI agents**: offers to install Claude Code, opencode and Hermes Agent with each one's own installer, and runs them in a sandbox (see below). `configure claude`, `configure opencode` and `configure hermes` sign in to them and choose their model providers.
|
||||||
- **Agent sandbox**: iCloud Drive and other cloud drives' files are hidden from agents. Reading a file macOS keeps only in the cloud downloads it. To let agents read one of these, switch it here.
|
- **Agent sandbox**: iCloud Drive and other cloud drives' files are hidden from agents. Reading a file macOS keeps only in the cloud downloads it. To let agents read one of these, switch it here.
|
||||||
- **AI servers**: LLM servers on this Mac or your network, such as Ollama or LM Studio. It finds the machines on your network over Bonjour and asks each one on the ports LLM servers use (11434 Ollama, 1234 LM Studio, 8080 llama.cpp, 8000 vLLM); or you enter an address. For the server you choose, it lets the sandboxed agents reach it (that port only), adds it to opencode with its models, offers to make it Hermes' model, and lets the commands Claude Code runs reach it too. A server on another machine has to accept connections from other machines: in Ollama's settings turn on "Expose Ollama to the network"; in LM Studio, "Serve on Local Network".
|
- **AI servers**: LLM servers on this Mac or your network, such as Ollama or LM Studio. It finds the machines on your network over Bonjour and asks each one on the ports LLM servers use (11434 Ollama, 1234 LM Studio, 8080 llama.cpp, 8000 vLLM); or you enter an address. For the server you choose, it lets the sandboxed agents reach it (that port only), adds it to opencode with its models, offers to make it Hermes' model, and lets the commands Claude Code runs reach it too. A server on another machine has to accept connections from other machines: in Ollama's settings turn on "Expose Ollama to the network"; in LM Studio, "Serve on Local Network".
|
||||||
@@ -86,6 +88,8 @@ If an app a step needs isn't on this Mac, `configure` offers to download and ins
|
|||||||
| Nextcloud | Your files | github.com/nextcloud-releases/desktop | `NKUJUXUJ3B` |
|
| Nextcloud | Your files | github.com/nextcloud-releases/desktop | `NKUJUXUJ3B` |
|
||||||
| Element | Your Core's chat | packages.element.io | `7J4U792NQT` |
|
| Element | Your Core's chat | packages.element.io | `7J4U792NQT` |
|
||||||
| Tailscale | Your Core's network | pkgs.tailscale.com | `W5364U7YZB` |
|
| Tailscale | Your Core's network | pkgs.tailscale.com | `W5364U7YZB` |
|
||||||
|
| macFUSE | SFTP folders | github.com/macfuse/macfuse | `3T5GSNBU6W` |
|
||||||
|
| SSHFS | SFTP folders | github.com/libfuse/sshfs (linked from macfuse.github.io) | `3T5GSNBU6W` |
|
||||||
|
|
||||||
An app is installed only if it's signed with its maker's Developer ID (the Team ID above) and Gatekeeper accepts it, which means Apple notarized it. The apps update themselves after that. Installing a .pkg (Nextcloud, Tailscale) asks for your Mac password.
|
An app is installed only if it's signed with its maker's Developer ID (the Team ID above) and Gatekeeper accepts it, which means Apple notarized it. The apps update themselves after that. Installing a .pkg (Nextcloud, Tailscale) asks for your Mac password.
|
||||||
|
|
||||||
@@ -135,6 +139,6 @@ Keep to bash 3.2: no `mapfile`, `read -i`, associative arrays or `${var,,}`.
|
|||||||
- Mail, Calendar and Contacts come from a configuration profile, not GNOME Online Accounts. macOS asks you to approve the profile.
|
- Mail, Calendar and Contacts come from a configuration profile, not GNOME Online Accounts. macOS asks you to approve the profile.
|
||||||
- Files sync through the Nextcloud app rather than a davfs2 mount.
|
- Files sync through the Nextcloud app rather than a davfs2 mount.
|
||||||
- Backups and network storage run from launchd rather than systemd. Backups need Full Disk Access (see above), and network storage uses macOS' own SMB mounting and keychain rather than /etc/fstab.
|
- Backups and network storage run from launchd rather than systemd. Backups need Full Disk Access (see above), and network storage uses macOS' own SMB mounting and keychain rather than /etc/fstab.
|
||||||
- Network storage is SMB only; SFTP would need macFUSE.
|
- SFTP folders need macFUSE and SSHFS, and macOS 26 or later (or macFUSE's kernel extension), where CoreDesktop uses sshfs on FUSE, built into Linux.
|
||||||
- The sandbox uses Seatbelt rather than bubblewrap, so sandboxed agents reach everything, including local servers, through srt's proxy.
|
- The sandbox uses Seatbelt rather than bubblewrap, so sandboxed agents reach everything, including local servers, through srt's proxy.
|
||||||
- Not ported: Cline Desktop (not packaged for macOS here), running Hermes' gateway in the sandbox, printers (AirPrint finds them), languages, Tally and the email watcher.
|
- Not ported: Cline Desktop (not packaged for macOS here), running Hermes' gateway in the sandbox, printers (AirPrint finds them), languages, Tally and the email watcher.
|
||||||
|
|||||||
+139
-34
@@ -6,14 +6,19 @@ TITLE="Network storage"
|
|||||||
# shellcheck disable=SC2034
|
# shellcheck disable=SC2034
|
||||||
DESCRIPTION="Mount shared folders from your network"
|
DESCRIPTION="Mount shared folders from your network"
|
||||||
|
|
||||||
# What's mounted, one smb://user@host/share per line. It exists once you've
|
# What's mounted, one "<url>|<mount point>" per line (see
|
||||||
# run this, even if you added nothing, so this isn't "to do" without a server.
|
# system/storage-mount). It exists once you've run this, even if you added
|
||||||
|
# nothing, so this isn't "to do" without a server.
|
||||||
STORAGE_CONF="$CONF_DIR/storage"
|
STORAGE_CONF="$CONF_DIR/storage"
|
||||||
STORAGE_MOUNT="$CONNECTOR/system/storage-mount"
|
STORAGE_MOUNT="$CONNECTOR/system/storage-mount"
|
||||||
LABEL="computer.federated.connector.storage"
|
LABEL="computer.federated.connector.storage"
|
||||||
PLIST="$HOME/Library/LaunchAgents/$LABEL.plist"
|
PLIST="$HOME/Library/LaunchAgents/$LABEL.plist"
|
||||||
|
LOGIN_ITEMS_PANE="x-apple.systempreferences:com.apple.LoginItems-Settings.extension"
|
||||||
|
source "$CONNECTOR/configure.d/lib/json.sh"
|
||||||
|
source "$CONNECTOR/configure.d/lib/apps.sh"
|
||||||
source "$CONNECTOR/configure.d/lib/mdns.sh"
|
source "$CONNECTOR/configure.d/lib/mdns.sh"
|
||||||
source "$CONNECTOR/configure.d/lib/smb.sh"
|
source "$CONNECTOR/configure.d/lib/smb.sh"
|
||||||
|
source "$CONNECTOR/configure.d/lib/sftp.sh"
|
||||||
|
|
||||||
is_configured() {
|
is_configured() {
|
||||||
[ -f "$STORAGE_CONF" ]
|
[ -f "$STORAGE_CONF" ]
|
||||||
@@ -96,95 +101,195 @@ add_share() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# record <url> <mount point>: add it to the list, and the job that mounts
|
||||||
|
# it again at login
|
||||||
record() {
|
record() {
|
||||||
local url="$1" point="$2" line
|
local url="$1" point="$2" line
|
||||||
while IFS= read -r line; do
|
while IFS='|' read -r line _; do
|
||||||
[ "$(share_key "$line")" = "$(share_key "$url")" ] && { echo "$url was already added."; return 0; }
|
case "$url" in
|
||||||
|
smb://*) [ "$(share_key "$line")" = "$(share_key "$url")" ] ;;
|
||||||
|
*) [ "$line" = "$url" ] ;;
|
||||||
|
esac && { echo "$url was already added."; return 0; }
|
||||||
done < "$STORAGE_CONF"
|
done < "$STORAGE_CONF"
|
||||||
echo "$url" >> "$STORAGE_CONF"
|
echo "$url|$point" >> "$STORAGE_CONF"
|
||||||
[ -f "$PLIST" ] || install_job
|
[ -f "$PLIST" ] || install_job
|
||||||
echo "$url is at $point (in Finder's sidebar under Locations). It's mounted again at login."
|
echo "$url is at $point (in Finder's sidebar under Locations). It's mounted again at login."
|
||||||
}
|
}
|
||||||
|
|
||||||
# Unmount it and take it out of the list
|
# A name usable in a path: "Pi-Star Files" -> pi-star-files
|
||||||
remove_share() {
|
slug() {
|
||||||
local url="$1" point tmp
|
local s
|
||||||
if point="$(mounted_at "$url")"; then
|
s="$(tr '[:upper:]' '[:lower:]' <<< "$1" | sed -E 's/[^a-z0-9._-]+/-/g; s/^-+//; s/-+$//')"
|
||||||
diskutil unmount "$point" > /dev/null 2>&1 || umount "$point" 2> /dev/null \
|
echo "${s:-folder}"
|
||||||
|| echo "Couldn't unmount $point; eject it in Finder."
|
|
||||||
fi
|
|
||||||
tmp="$(mktemp)" || return 1
|
|
||||||
grep -vxF "$url" "$STORAGE_CONF" > "$tmp"
|
|
||||||
mv -f "$tmp" "$STORAGE_CONF"
|
|
||||||
[ -s "$STORAGE_CONF" ] || remove_job
|
|
||||||
echo "$url won't be mounted again. Its password stays in your keychain (Keychain Access)."
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# The SMB servers on the network, other than this Mac: "host|name" per line
|
# <host>[-<folder>], with -2, -3... if that's taken
|
||||||
|
sftp_name() {
|
||||||
|
local base n=2 name
|
||||||
|
base="$(slug "${1%.local}")"
|
||||||
|
[ -n "$2" ] && base="$base-$(slug "$(basename "$2")")"
|
||||||
|
name="$base"
|
||||||
|
while [ -e "/Volumes/$name" ] || [ -e "$HOME/Volumes/$name" ] || grep -qsE "/$name\$" "$STORAGE_CONF"; do
|
||||||
|
name="$base-$n"
|
||||||
|
n=$((n + 1))
|
||||||
|
done
|
||||||
|
echo "$name"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Mount sftp://user@host[:port][/path] and record it. Installs macFUSE and
|
||||||
|
# SSHFS first if they're missing, and has you turn on macFUSE's file system
|
||||||
|
# extension.
|
||||||
|
add_sftp() {
|
||||||
|
local url="$1" backend point
|
||||||
|
if ! backend="$(fuse_backend)"; then
|
||||||
|
echo "Folders over SSH need macOS 26 or later. On earlier versions of macOS, macFUSE"
|
||||||
|
echo "needs its kernel extension, which on Apple silicon means starting up in Recovery"
|
||||||
|
echo "and lowering security. This doesn't do that, but once macFUSE's kernel extension"
|
||||||
|
echo "is running, it uses it."
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
app_ensure macfuse "It lets macOS mount folders from other machines over SSH." || return 1
|
||||||
|
app_ensure sshfs "It mounts folders over SSH (SFTP) with macFUSE." || return 1
|
||||||
|
if [ "$backend" = fskit ] && ! fskit_ready; then
|
||||||
|
echo "Turn on macFUSE's file system extension: System Settings opens at Login Items &"
|
||||||
|
echo "Extensions. Under Extensions, open File System Extensions and turn on macFUSE."
|
||||||
|
open "$LOGIN_ITEMS_PANE"
|
||||||
|
wait_until 300 fskit_ready || { echo "macFUSE's extension is still off."; return 1; }
|
||||||
|
fi
|
||||||
|
|
||||||
|
sftp_parse "$url"
|
||||||
|
echo "Checking that $SFTP_HOST accepts one of your SSH keys..."
|
||||||
|
if ! sftp_key_works "$url"; then
|
||||||
|
echo "$SFTP_HOST didn't accept any of your SSH keys, and the mount can't ask for a password."
|
||||||
|
echo "Add your key to $SFTP_HOST first (e.g. ssh-copy-id $SFTP_USER@$SFTP_HOST), then try again."
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
point="$(sftp_mount_point "$(sftp_name "$SFTP_HOST" "$SFTP_PATH")")" || return 1
|
||||||
|
if ! sftp_mount "$url" "$point"; then
|
||||||
|
echo "SSHFS couldn't mount $url."
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
record "$url" "$point"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Ask who to sign in as and which folder, as CoreDesktop does
|
||||||
|
ask_sftp() {
|
||||||
|
local host="$1" user="${2:-$USER}" path="$3" port=""
|
||||||
|
[[ "$host" == *:* ]] && { port=":${host##*:}"; host="${host%%:*}"; }
|
||||||
|
ask user "User name on $host" "$user"
|
||||||
|
[ -n "$path" ] || read -rp "Folder on $host (Enter for your home folder): " path
|
||||||
|
path="${path#/}"
|
||||||
|
add_sftp "sftp://$user@$host$port${path:+/$path}"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Unmount it and take it out of the list
|
||||||
|
remove_share() {
|
||||||
|
local url="$1" point="$2" tmp
|
||||||
|
case "$url" in
|
||||||
|
smb://*)
|
||||||
|
if point="$(mounted_at "$url")"; then
|
||||||
|
diskutil unmount "$point" > /dev/null 2>&1 || umount "$point" 2> /dev/null \
|
||||||
|
|| echo "Couldn't unmount $point; eject it in Finder."
|
||||||
|
fi ;;
|
||||||
|
sftp://*)
|
||||||
|
sftp_unmount "$point" || echo "Couldn't unmount $point; eject it in Finder." ;;
|
||||||
|
esac
|
||||||
|
tmp="$(mktemp)" || return 1
|
||||||
|
awk -F'|' -v url="$url" '$1 != url' "$STORAGE_CONF" > "$tmp"
|
||||||
|
mv -f "$tmp" "$STORAGE_CONF"
|
||||||
|
[ -s "$STORAGE_CONF" ] || remove_job
|
||||||
|
case "$url" in
|
||||||
|
smb://*) echo "$url won't be mounted again. Its password stays in your keychain (Keychain Access)." ;;
|
||||||
|
*) echo "$url won't be mounted again." ;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
|
# The file servers on the network, other than this Mac: "kind|host|name" per
|
||||||
|
# line. Macs with Remote Login on announce SFTP; Linux machines often do too.
|
||||||
find_servers() {
|
find_servers() {
|
||||||
local own name host
|
local own name type host
|
||||||
own="$(mdns_own_host)"
|
own="$(mdns_own_host)"
|
||||||
mdns_services _smb._tcp | while IFS='|' read -r name _ host _; do
|
mdns_services _smb._tcp _sftp-ssh._tcp | while IFS='|' read -r name type host _; do
|
||||||
[ "$(tr '[:upper:]' '[:lower:]' <<< "$host")" = "$(tr '[:upper:]' '[:lower:]' <<< "$own")" ] && continue
|
[ "$(tr '[:upper:]' '[:lower:]' <<< "$host")" = "$(tr '[:upper:]' '[:lower:]' <<< "$own")" ] && continue
|
||||||
echo "$host|$name"
|
case "$type" in
|
||||||
|
_smb._tcp) echo "smb|$host|$name" ;;
|
||||||
|
_sftp-ssh._tcp) echo "sftp|$host|$name" ;;
|
||||||
|
esac
|
||||||
done | sort -u
|
done | sort -u
|
||||||
}
|
}
|
||||||
|
|
||||||
find_and_add() {
|
find_and_add() {
|
||||||
local found=() line host name choice i
|
local found=() line kind host name choice i
|
||||||
echo "Looking for shared folders on your network..."
|
echo "Looking for shared folders on your network..."
|
||||||
while IFS= read -r line; do
|
while IFS= read -r line; do
|
||||||
found+=("$line")
|
found+=("$line")
|
||||||
done < <(find_servers)
|
done < <(find_servers)
|
||||||
if [ ${#found[@]} -eq 0 ]; then
|
if [ ${#found[@]} -eq 0 ]; then
|
||||||
echo "Nothing found. Windows PCs, NAS boxes and Macs with File Sharing on share folders"
|
echo "Nothing found. Windows PCs, NAS boxes and Macs with File Sharing on share folders"
|
||||||
echo "over SMB, but some don't announce it. Enter the address instead."
|
echo "over SMB, and machines you can ssh to over SFTP, but some don't announce it."
|
||||||
|
echo "Enter the address instead."
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
for i in "${!found[@]}"; do
|
for i in "${!found[@]}"; do
|
||||||
IFS='|' read -r host name <<< "${found[$i]}"
|
IFS='|' read -r kind host name <<< "${found[$i]}"
|
||||||
printf ' %2d) %-26s %s\n' $((i + 1)) "$host" "$name"
|
printf ' %2d) %-26s %-22s %s\n' $((i + 1)) "$host" \
|
||||||
|
"$([ "$kind" = smb ] && echo "SMB shared folders" || echo "SFTP (over SSH)")" "$name"
|
||||||
done
|
done
|
||||||
read -rp "Which? " choice
|
read -rp "Which? " choice
|
||||||
if ! [[ "$choice" =~ ^[0-9]+$ ]] || [ "$choice" -lt 1 ] || [ "$choice" -gt ${#found[@]} ]; then
|
if ! [[ "$choice" =~ ^[0-9]+$ ]] || [ "$choice" -lt 1 ] || [ "$choice" -gt ${#found[@]} ]; then
|
||||||
echo "Choose a number from the list."
|
echo "Choose a number from the list."
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
add_share "smb://${found[$((choice - 1))]%%|*}"
|
IFS='|' read -r kind host _ <<< "${found[$((choice - 1))]}"
|
||||||
|
case "$kind" in
|
||||||
|
smb) add_share "smb://$host" ;;
|
||||||
|
sftp) ask_sftp "$host" ;;
|
||||||
|
esac
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# smb://host[/share] or sftp://[user@]host[:port][/path]
|
||||||
enter_and_add() {
|
enter_and_add() {
|
||||||
local address
|
local address rest user="" host path=""
|
||||||
read -rp "Address, e.g. smb://nas.local/files (or smb://nas.local to choose a share): " address
|
read -rp "Address, e.g. smb://nas.local/files or sftp://me@server.local/srv/data: " address
|
||||||
case "$address" in
|
case "$address" in
|
||||||
"") return 0 ;;
|
"") return 0 ;;
|
||||||
smb://?*) add_share "$address" ;;
|
smb://?*) add_share "$address" ;;
|
||||||
*) echo "Start it with smb://. (Folders over SSH need macFUSE, which this doesn't set up.)"
|
sftp://?*)
|
||||||
|
rest="${address#sftp://}"
|
||||||
|
[[ "$rest" == *@* ]] && { user="${rest%%@*}"; rest="${rest#*@}"; }
|
||||||
|
host="${rest%%/*}"
|
||||||
|
[[ "$rest" == */?* ]] && path="/${rest#*/}"
|
||||||
|
ask_sftp "$host" "$user" "$path" ;;
|
||||||
|
*) echo "Start it with smb:// or sftp://."
|
||||||
return 1 ;;
|
return 1 ;;
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
|
|
||||||
choose_and_remove() {
|
choose_and_remove() {
|
||||||
local entries=() line choice i
|
local entries=() line url point choice i
|
||||||
while IFS= read -r line; do
|
while IFS= read -r line; do
|
||||||
[ -n "$line" ] && entries+=("$line")
|
[ -n "$line" ] && entries+=("$line")
|
||||||
done < "$STORAGE_CONF"
|
done < "$STORAGE_CONF"
|
||||||
for i in "${!entries[@]}"; do
|
for i in "${!entries[@]}"; do
|
||||||
printf ' %2d) %s\n' $((i + 1)) "${entries[$i]}"
|
IFS='|' read -r url point <<< "${entries[$i]}"
|
||||||
|
printf ' %2d) %s\n' $((i + 1)) "$url"
|
||||||
done
|
done
|
||||||
read -rp "Which? " choice
|
read -rp "Which? " choice
|
||||||
if ! [[ "$choice" =~ ^[0-9]+$ ]] || [ "$choice" -lt 1 ] || [ "$choice" -gt ${#entries[@]} ]; then
|
if ! [[ "$choice" =~ ^[0-9]+$ ]] || [ "$choice" -lt 1 ] || [ "$choice" -gt ${#entries[@]} ]; then
|
||||||
echo "Choose a number from the list."
|
echo "Choose a number from the list."
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
remove_share "${entries[$((choice - 1))]}"
|
IFS='|' read -r url point <<< "${entries[$((choice - 1))]}"
|
||||||
|
remove_share "$url" "$point"
|
||||||
}
|
}
|
||||||
|
|
||||||
run_configure() {
|
run_configure() {
|
||||||
local choice url point
|
local choice url point
|
||||||
mkdir -p "$(dirname "$STORAGE_CONF")" && touch "$STORAGE_CONF" || return 1
|
mkdir -p "$(dirname "$STORAGE_CONF")" && touch "$STORAGE_CONF" || return 1
|
||||||
echo "This mounts shared folders from other machines on your network (Windows PCs, NAS"
|
echo "This mounts shared folders from other machines on your network and mounts them"
|
||||||
echo "boxes, Macs with File Sharing on) and mounts them again each time you log in."
|
echo "again each time you log in: SMB shares (Windows PCs, NAS boxes, Macs with File"
|
||||||
|
echo "Sharing on) and, over SSH, any machine you can ssh to."
|
||||||
|
|
||||||
while true; do
|
while true; do
|
||||||
echo
|
echo
|
||||||
|
|||||||
+48
-11
@@ -10,11 +10,15 @@
|
|||||||
#
|
#
|
||||||
# To check an app's Team ID on a Mac where it's installed:
|
# To check an app's Team ID on a Mac where it's installed:
|
||||||
# codesign -dv /Applications/<App>.app 2>&1 | grep TeamIdentifier
|
# codesign -dv /Applications/<App>.app 2>&1 | grep TeamIdentifier
|
||||||
|
# or a package's: pkgutil --check-signature <file>.pkg
|
||||||
|
|
||||||
# app_info <name>: sets APP_TITLE, APP_BUNDLE, APP_TEAM, APP_KIND (dmg or
|
# app_info <name>: sets APP_TITLE, APP_BUNDLE, APP_TEAM, APP_KIND and
|
||||||
# pkg) and APP_URL. Nextcloud's URL changes with each release, so app_url
|
# APP_URL, and APP_PATHS: where it is once installed, separated by colons.
|
||||||
# looks it up.
|
# APP_KIND is dmg (an app to copy out of a disk image), pkg (an installer
|
||||||
|
# package) or dmgpkg (an installer package in a disk image). Some URLs change
|
||||||
|
# with each release, so app_url looks them up.
|
||||||
app_info() {
|
app_info() {
|
||||||
|
APP_BUNDLE="" APP_PATHS=""
|
||||||
case "$1" in
|
case "$1" in
|
||||||
element)
|
element)
|
||||||
APP_TITLE="Element" APP_BUNDLE="Element.app" APP_TEAM="7J4U792NQT" APP_KIND=dmg
|
APP_TITLE="Element" APP_BUNDLE="Element.app" APP_TEAM="7J4U792NQT" APP_KIND=dmg
|
||||||
@@ -25,20 +29,31 @@ app_info() {
|
|||||||
tailscale)
|
tailscale)
|
||||||
APP_TITLE="Tailscale" APP_BUNDLE="Tailscale.app" APP_TEAM="W5364U7YZB" APP_KIND=pkg
|
APP_TITLE="Tailscale" APP_BUNDLE="Tailscale.app" APP_TEAM="W5364U7YZB" APP_KIND=pkg
|
||||||
APP_URL="https://pkgs.tailscale.com/stable/Tailscale-latest-macos.pkg" ;;
|
APP_URL="https://pkgs.tailscale.com/stable/Tailscale-latest-macos.pkg" ;;
|
||||||
|
# Network storage's SFTP folders. Both are made by macFUSE's author.
|
||||||
|
macfuse)
|
||||||
|
APP_TITLE="macFUSE" APP_TEAM="3T5GSNBU6W" APP_KIND=dmgpkg
|
||||||
|
APP_PATHS="/Library/Filesystems/macfuse.fs"
|
||||||
|
APP_URL="https://api.github.com/repos/macfuse/macfuse/releases/latest" ;;
|
||||||
|
sshfs)
|
||||||
|
APP_TITLE="SSHFS" APP_TEAM="3T5GSNBU6W" APP_KIND=pkg
|
||||||
|
APP_PATHS="/usr/local/bin/sshfs"
|
||||||
|
APP_URL="https://macfuse.github.io/" ;;
|
||||||
*) return 1 ;;
|
*) return 1 ;;
|
||||||
esac
|
esac
|
||||||
|
[ -n "$APP_PATHS" ] || APP_PATHS="/Applications/$APP_BUNDLE:$HOME/Applications/$APP_BUNDLE"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Where the app is installed, if it is
|
# Where the app is installed, if it is
|
||||||
app_path() {
|
app_path() {
|
||||||
|
local path IFS=:
|
||||||
app_info "$1" || return 1
|
app_info "$1" || return 1
|
||||||
if [ -d "/Applications/$APP_BUNDLE" ]; then
|
for path in $APP_PATHS; do
|
||||||
echo "/Applications/$APP_BUNDLE"
|
if [ -e "$path" ]; then
|
||||||
elif [ -d "$HOME/Applications/$APP_BUNDLE" ]; then
|
echo "$path"
|
||||||
echo "$HOME/Applications/$APP_BUNDLE"
|
return 0
|
||||||
else
|
fi
|
||||||
return 1
|
done
|
||||||
fi
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
app_installed() {
|
app_installed() {
|
||||||
@@ -47,11 +62,19 @@ app_installed() {
|
|||||||
|
|
||||||
# The download URL for app_info's app
|
# The download URL for app_info's app
|
||||||
app_url() {
|
app_url() {
|
||||||
|
local ext=pkg url
|
||||||
|
case "$APP_KIND" in dmg|dmgpkg) ext=dmg ;; esac
|
||||||
case "$APP_URL" in
|
case "$APP_URL" in
|
||||||
https://api.github.com/*)
|
https://api.github.com/*)
|
||||||
curl -sf --max-time 30 "$APP_URL" \
|
curl -sf --max-time 30 "$APP_URL" \
|
||||||
| json_get 'd.assets.map(function (x) { return x.browser_download_url; })
|
| json_get 'd.assets.map(function (x) { return x.browser_download_url; })
|
||||||
.filter(function (u) { return /\.pkg$/.test(u); })[0]' ;;
|
.filter(function (u) { return u.slice(-a[0].length - 1) === "." + a[0]; })[0]' "$ext" ;;
|
||||||
|
# SSHFS' macOS package isn't in its latest GitHub release; macFUSE's site
|
||||||
|
# links the current one
|
||||||
|
https://macfuse.github.io/)
|
||||||
|
url="$(curl -sf --max-time 30 "$APP_URL" \
|
||||||
|
| grep -oE 'https://github\.com/libfuse/sshfs/releases/download/[^"]+\.pkg' | head -n 1)"
|
||||||
|
echo "${url:-https://github.com/libfuse/sshfs/releases/download/sshfs-3.7.5/sshfs-3.7.5.pkg}" ;;
|
||||||
*) echo "$APP_URL" ;;
|
*) echo "$APP_URL" ;;
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
@@ -110,6 +133,20 @@ install_dmg() {
|
|||||||
return $status
|
return $status
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Install the package in a downloaded .dmg (macFUSE's), once it's checked
|
||||||
|
install_dmgpkg() {
|
||||||
|
local dmg="$1" mount="$2/mount" pkg status=1
|
||||||
|
hdiutil attach -nobrowse -readonly -noautoopen -mountpoint "$mount" "$dmg" > /dev/null || return 1
|
||||||
|
pkg="$(find "$mount" -maxdepth 2 -name '*.pkg' | head -n 1)"
|
||||||
|
if [ -z "$pkg" ]; then
|
||||||
|
echo "The download doesn't have an installer package in it."
|
||||||
|
else
|
||||||
|
install_pkg "$pkg" && status=0
|
||||||
|
fi
|
||||||
|
hdiutil detach -quiet "$mount" || hdiutil detach -quiet -force "$mount"
|
||||||
|
return $status
|
||||||
|
}
|
||||||
|
|
||||||
# Download and install an app
|
# Download and install an app
|
||||||
app_install() {
|
app_install() {
|
||||||
local name="$1" url tmp status
|
local name="$1" url tmp status
|
||||||
|
|||||||
@@ -0,0 +1,117 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
#
|
||||||
|
# Purpose : Folders from other machines over SFTP, mounted with SSHFS on
|
||||||
|
# macFUSE. Sourced by configure.d/60-storage.sh and
|
||||||
|
# system/storage-mount.
|
||||||
|
#
|
||||||
|
# macOS can't mount SFTP folders itself, so this needs macFUSE and SSHFS
|
||||||
|
# (configure storage offers to install them). On macOS 26 and later, macFUSE
|
||||||
|
# mounts through FSKit, in user space; you turn its file system extension on
|
||||||
|
# once in System Settings. On earlier macOS it needs its kernel extension,
|
||||||
|
# which on Apple silicon means lowering security in Recovery: this uses it if
|
||||||
|
# you've done that, but doesn't do it for you.
|
||||||
|
#
|
||||||
|
# Like CoreDesktop's sftp-mount, it runs as you and uses your SSH keys (from
|
||||||
|
# Bitwarden's SSH agent while it runs one, otherwise macOS' own agent and
|
||||||
|
# ~/.ssh), and never asks for a password, so the server has to accept a key.
|
||||||
|
|
||||||
|
SSHFS="/usr/local/bin/sshfs"
|
||||||
|
BITWARDEN_SSH_AGENT="$HOME/Library/Containers/com.bitwarden.desktop/Data/.bitwarden-ssh-agent.sock"
|
||||||
|
|
||||||
|
# Which macFUSE backend mounts here: fskit or kernel. Fails if neither can.
|
||||||
|
fuse_backend() {
|
||||||
|
if [ "$(sw_vers -productVersion | cut -d. -f1)" -ge 26 ]; then
|
||||||
|
echo fskit
|
||||||
|
elif kmutil showloaded --list-only 2> /dev/null | grep -q io.macfuse.filesystems.macfuse \
|
||||||
|
|| kextstat 2> /dev/null | grep -q io.macfuse.filesystems.macfuse; then
|
||||||
|
echo kernel
|
||||||
|
else
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Whether you've turned on macFUSE's file system extension: 0 yes, 1 no, 2
|
||||||
|
# can't tell. pluginkit marks an extension you've turned on with "+".
|
||||||
|
fskit_enabled() {
|
||||||
|
local line
|
||||||
|
line="$(pluginkit -m -A -D -p com.apple.fskit.fsmodule 2> /dev/null | grep -i macfuse | head -n 1)"
|
||||||
|
[ -n "$line" ] || return 2
|
||||||
|
[[ "$line" == +* ]]
|
||||||
|
}
|
||||||
|
|
||||||
|
# Ready unless pluginkit says it's off
|
||||||
|
fskit_ready() {
|
||||||
|
fskit_enabled
|
||||||
|
[ $? -ne 1 ]
|
||||||
|
}
|
||||||
|
|
||||||
|
# sftp://[user@]host[:port][/path] -> SFTP_USER, SFTP_HOST, SFTP_PORT and
|
||||||
|
# SFTP_PATH (empty for your home folder on the server)
|
||||||
|
sftp_parse() {
|
||||||
|
local rest="${1#sftp://}" hostport
|
||||||
|
SFTP_USER="" SFTP_PATH="" SFTP_PORT=22
|
||||||
|
if [[ "$rest" == *@* ]]; then
|
||||||
|
SFTP_USER="${rest%%@*}"
|
||||||
|
rest="${rest#*@}"
|
||||||
|
fi
|
||||||
|
hostport="${rest%%/*}"
|
||||||
|
[[ "$rest" == */?* ]] && SFTP_PATH="/${rest#*/}"
|
||||||
|
SFTP_HOST="${hostport%%:*}"
|
||||||
|
[[ "$hostport" == *:* ]] && SFTP_PORT="${hostport##*:}"
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
use_ssh_agent() {
|
||||||
|
[ -S "$BITWARDEN_SSH_AGENT" ] && export SSH_AUTH_SOCK="$BITWARDEN_SSH_AGENT"
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
# Whether the server takes one of your keys. Run in a terminal, ssh asks to
|
||||||
|
# accept the server's key the first time, which the mount itself can't.
|
||||||
|
sftp_key_works() {
|
||||||
|
sftp_parse "$1"
|
||||||
|
use_ssh_agent
|
||||||
|
ssh -p "$SFTP_PORT" -o ConnectTimeout=10 -o PasswordAuthentication=no \
|
||||||
|
-o KbdInteractiveAuthentication=no "$SFTP_USER@$SFTP_HOST" true
|
||||||
|
}
|
||||||
|
|
||||||
|
# Where a folder mounts: /Volumes/<name> through FSKit, which makes the
|
||||||
|
# folder itself; with the kernel extension, ~/Volumes/<name>, as only root
|
||||||
|
# can make folders in /Volumes
|
||||||
|
sftp_mount_point() {
|
||||||
|
local backend
|
||||||
|
backend="$(fuse_backend)" || return 1
|
||||||
|
if [ "$backend" = fskit ]; then echo "/Volumes/$1"; else echo "$HOME/Volumes/$1"; fi
|
||||||
|
}
|
||||||
|
|
||||||
|
sftp_mounted() {
|
||||||
|
mount | grep -qF " on $1 ("
|
||||||
|
}
|
||||||
|
|
||||||
|
# sftp_mount <url> <mount point>. SSHFS goes to the background once it's
|
||||||
|
# mounted. reconnect and ServerAlive* bring it back after the network drops
|
||||||
|
# (e.g. sleep); idmap=user shows your files on the server as yours here.
|
||||||
|
sftp_mount() {
|
||||||
|
local url="$1" point="$2" backend opts
|
||||||
|
backend="$(fuse_backend)" || return 1
|
||||||
|
sftp_parse "$url"
|
||||||
|
use_ssh_agent
|
||||||
|
opts="volname=$(basename "$point"),port=$SFTP_PORT,reconnect,ServerAliveInterval=15,ServerAliveCountMax=3"
|
||||||
|
opts="$opts,BatchMode=yes,ConnectTimeout=15,idmap=user"
|
||||||
|
if [ "$backend" = fskit ]; then
|
||||||
|
opts="$opts,backend=fskit"
|
||||||
|
else
|
||||||
|
mkdir -p "$point" || return 1
|
||||||
|
opts="$opts,defer_permissions,noappledouble"
|
||||||
|
fi
|
||||||
|
"$SSHFS" "$SFTP_USER@$SFTP_HOST:$SFTP_PATH" "$point" -o "$opts"
|
||||||
|
}
|
||||||
|
|
||||||
|
sftp_unmount() {
|
||||||
|
local point="$1"
|
||||||
|
if sftp_mounted "$point"; then
|
||||||
|
umount "$point" 2> /dev/null || diskutil unmount force "$point" > /dev/null 2>&1 || return 1
|
||||||
|
fi
|
||||||
|
case "$point" in "$HOME/Volumes/"*) rmdir "$point" 2> /dev/null ;; esac
|
||||||
|
return 0
|
||||||
|
}
|
||||||
@@ -57,6 +57,7 @@ Each scenario runs on a fresh clone of Cirrus Labs' **vanilla** macOS image (def
|
|||||||
| `60-backup` | restic and rclone download. A local WebDAV server stands in for Nextcloud. The Federated Backup app is built and answers whether it has Full Disk Access. launchd runs a backup, a snapshot appears, a file restores from it, and a second run the same day does nothing. Turning backups off removes the app and the job. |
|
| `60-backup` | restic and rclone download. A local WebDAV server stands in for Nextcloud. The Federated Backup app is built and answers whether it has Full Disk Access. launchd runs a backup, a snapshot appears, a file restores from it, and a second run the same day does nothing. Turning backups off removes the app and the job. |
|
||||||
| `70-apps` *(all)* | With Gatekeeper on: an un-notarized app is turned down, and a package signed by the wrong Team ID is refused. Element, Nextcloud and Tailscale download and install, and their Team IDs match `apps.sh`. Nextcloud opens with the Core's address. |
|
| `70-apps` *(all)* | With Gatekeeper on: an un-notarized app is turned down, and a package signed by the wrong Team ID is refused. Element, Nextcloud and Tailscale download and install, and their Team IDs match `apps.sh`. Nextcloud opens with the Core's address. |
|
||||||
| `80-storage` | The launchd job is added with the first share and removed with the last; a share whose server can't be reached is skipped quickly without asking |
|
| `80-storage` | The launchd job is added with the first share and removed with the last; a share whose server can't be reached is skipped quickly without asking |
|
||||||
|
| `85-sftp` | macFUSE and SSHFS install, with their Team IDs checked; FSKit is chosen on macOS 26. Then it tries to turn on macFUSE's extension with `pluginkit`. If that works, the VM mounts a folder from itself over SSH, a file reads and writes through the mount, and storage-mount mounts it again after it's unmounted. |
|
||||||
|
|
||||||
## What still needs a person
|
## What still needs a person
|
||||||
|
|
||||||
@@ -64,6 +65,7 @@ macOS deliberately allows these only with a click, so test them by hand on a VM
|
|||||||
|
|
||||||
- **Installing the profile:** in System Settings > Profiles, choose "Federated Core (...)", then Install. Then check Mail, Calendar and Contacts against a real Core. `configure core` notices the profile was installed.
|
- **Installing the profile:** in System Settings > Profiles, choose "Federated Core (...)", then Install. Then check Mail, Calendar and Contacts against a real Core. `configure core` notices the profile was installed.
|
||||||
- **Full Disk Access for Federated Backup:** after granting it, `configure backup` says it can read all your files, and the backup log no longer has permission errors for Documents and Desktop.
|
- **Full Disk Access for Federated Backup:** after granting it, `configure backup` says it can read all your files, and the backup log no longer has permission errors for Documents and Desktop.
|
||||||
|
- **Turning on macFUSE's file system extension**, if `85-sftp` couldn't do it with `pluginkit`: then mount an SFTP folder with `configure storage`.
|
||||||
- **Mounting a real SMB share:** the sign-in window, "Remember this password in my keychain", and whether `mount volume "smb://host"` without a share offers a list of shares.
|
- **Mounting a real SMB share:** the sign-in window, "Remember this password in my keychain", and whether `mount volume "smb://host"` without a share offers a list of shares.
|
||||||
- **Tailscale's VPN approval**, and **Nextcloud's sign-in** in the browser.
|
- **Tailscale's VPN approval**, and **Nextcloud's sign-in** in the browser.
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,83 @@
|
|||||||
|
# shellcheck shell=bash
|
||||||
|
DESCRIPTION="SFTP folders: macFUSE and SSHFS install, and the VM mounts a folder from itself over SSH"
|
||||||
|
TIER=quick
|
||||||
|
|
||||||
|
source "$CONNECTOR/configure.d/60-storage.sh"
|
||||||
|
SOURCE_DIR="$HOME/sftp-source"
|
||||||
|
URL="sftp://$USER@localhost$SOURCE_DIR"
|
||||||
|
|
||||||
|
job_loaded() {
|
||||||
|
launchctl print "gui/$(id -u)/$LABEL" > /dev/null 2>&1
|
||||||
|
}
|
||||||
|
|
||||||
|
# The id of macFUSE's file system extension, as pluginkit lists it
|
||||||
|
fsmodule_id() {
|
||||||
|
pluginkit -m -A -D -p com.apple.fskit.fsmodule 2> /dev/null | grep -i macfuse | head -n 1 \
|
||||||
|
| sed -E 's/^[-+=!? ]*//; s/[[:space:]]*\(.*$//; s/[[:space:]].*$//'
|
||||||
|
}
|
||||||
|
|
||||||
|
point_of() {
|
||||||
|
awk -F'|' -v url="$URL" '$1 == url { print $2 }' "$STORAGE_CONF"
|
||||||
|
}
|
||||||
|
|
||||||
|
reads_through_mount() {
|
||||||
|
[ "$(cat "$(point_of)/hello.txt")" = "hello over sftp" ]
|
||||||
|
}
|
||||||
|
|
||||||
|
writes_through_mount() {
|
||||||
|
echo written > "$(point_of)/from-mount.txt" && [ "$(cat "$SOURCE_DIR/from-mount.txt")" = written ]
|
||||||
|
}
|
||||||
|
|
||||||
|
remounts() {
|
||||||
|
local point
|
||||||
|
point="$(point_of)"
|
||||||
|
sftp_unmount "$point" || return 1
|
||||||
|
sftp_mounted "$point" && return 1
|
||||||
|
bash "$STORAGE_MOUNT"
|
||||||
|
sleep 3
|
||||||
|
sftp_mounted "$point"
|
||||||
|
}
|
||||||
|
|
||||||
|
scenario() {
|
||||||
|
local backend id
|
||||||
|
check "fuse_backend picks one" fuse_backend
|
||||||
|
backend="$(fuse_backend)"
|
||||||
|
[ -n "$backend" ] || { skip "This macOS can't mount over SFTP without macFUSE's kernel extension"; return; }
|
||||||
|
check_eq "it's FSKit on macOS 26 and later" fskit "$backend"
|
||||||
|
|
||||||
|
step "Installing macFUSE and SSHFS (Team IDs checked)"
|
||||||
|
check "app_install macfuse" app_install macfuse
|
||||||
|
check "app_install sshfs" app_install sshfs
|
||||||
|
check "sshfs runs" "$SSHFS" --version
|
||||||
|
|
||||||
|
step "macFUSE's file system extension"
|
||||||
|
id="$(fsmodule_id)"
|
||||||
|
if [ -z "$id" ]; then
|
||||||
|
skip "pluginkit doesn't list macFUSE's extension, so fskit_enabled can't tell whether it's on"
|
||||||
|
else
|
||||||
|
check "pluginkit lists it ($id)" true
|
||||||
|
fskit_enabled || pluginkit -e use -i "$id" 2> /dev/null
|
||||||
|
sleep 2
|
||||||
|
fi
|
||||||
|
if ! fskit_ready; then
|
||||||
|
skip "Turning macFUSE's extension on needs a click in System Settings: check mounting by hand"
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
|
step "A folder from this Mac, over SSH"
|
||||||
|
mkdir -p "$HOME/.ssh" "$SOURCE_DIR"
|
||||||
|
echo "hello over sftp" > "$SOURCE_DIR/hello.txt"
|
||||||
|
[ -f "$HOME/.ssh/id_ed25519" ] || ssh-keygen -q -t ed25519 -N '' -f "$HOME/.ssh/id_ed25519"
|
||||||
|
cat "$HOME/.ssh/id_ed25519.pub" >> "$HOME/.ssh/authorized_keys"
|
||||||
|
ssh-keyscan -H localhost >> "$HOME/.ssh/known_hosts" 2> /dev/null
|
||||||
|
mkdir -p "$CONF_DIR"
|
||||||
|
: > "$STORAGE_CONF"
|
||||||
|
check "sftp_key_works" sftp_key_works "$URL"
|
||||||
|
check "add_sftp mounts it and adds it to the list" add_sftp "$URL"
|
||||||
|
check "launchd has the job" job_loaded
|
||||||
|
check "a file reads through the mount" reads_through_mount
|
||||||
|
check "a file written through the mount lands on the server" writes_through_mount
|
||||||
|
check "storage-mount mounts it again after it's unmounted" remounts
|
||||||
|
check "remove_share" remove_share "$URL" "$(point_of)"
|
||||||
|
check_not "it's no longer in the list" grep -qF "$URL" "$STORAGE_CONF"
|
||||||
|
}
|
||||||
+41
-13
@@ -3,43 +3,71 @@
|
|||||||
# Purpose : Mount the shared folders `configure storage` added, at login and
|
# Purpose : Mount the shared folders `configure storage` added, at login and
|
||||||
# whenever the network changes (launchd starts this then).
|
# whenever the network changes (launchd starts this then).
|
||||||
#
|
#
|
||||||
# A share whose server can't be reached, e.g. away from home, is skipped
|
# A folder whose server can't be reached, e.g. away from home, is skipped
|
||||||
# quietly. macOS signs in with the password you saved in your keychain when
|
# quietly. For an SMB share, macOS signs in with the password you saved in
|
||||||
# you added the share. If it can't, it asks; if you cancel, this doesn't ask
|
# your keychain when you added it; if it can't, it asks. An SFTP folder signs
|
||||||
# again for an hour.
|
# in with your SSH keys and never asks. Either way, after a failure this
|
||||||
|
# doesn't try that folder again for an hour.
|
||||||
#
|
#
|
||||||
# Usage: storage-mount [--list] (--list: show each share and whether it's mounted)
|
# Each line of the list is "<url>|<mount point>": smb://user@host/share or
|
||||||
|
# sftp://user@host[:port][/path]. SMB lines may lack the mount point, as
|
||||||
|
# macOS chooses it.
|
||||||
|
#
|
||||||
|
# Usage: storage-mount [--list] (--list: show each folder and where it's mounted now)
|
||||||
|
|
||||||
# Wrapped in { ...; exit; } so bash reads the whole script up front
|
# Wrapped in { ...; exit; } so bash reads the whole script up front
|
||||||
{
|
{
|
||||||
|
|
||||||
|
CONNECTOR="$(cd "$(dirname "$0")/.." && pwd)"
|
||||||
CONF_DIR="$HOME/Library/Application Support/Federated Connector"
|
CONF_DIR="$HOME/Library/Application Support/Federated Connector"
|
||||||
STORAGE_CONF="$CONF_DIR/storage"
|
STORAGE_CONF="$CONF_DIR/storage"
|
||||||
FAILED_DIR="${TMPDIR:-/tmp}/federated-storage-failed"
|
FAILED_DIR="${TMPDIR:-/tmp}/federated-storage-failed"
|
||||||
RETRY_AFTER=3600
|
RETRY_AFTER=3600
|
||||||
|
|
||||||
source "$(cd "$(dirname "$0")/.." && pwd)/configure.d/lib/smb.sh" || exit 1
|
source "$CONNECTOR/configure.d/lib/smb.sh" || exit 1
|
||||||
|
source "$CONNECTOR/configure.d/lib/sftp.sh" || exit 1
|
||||||
|
|
||||||
|
# Where it's mounted now, if it is
|
||||||
|
mounted_now() {
|
||||||
|
case "$1" in
|
||||||
|
smb://*) mounted_at "$1" ;;
|
||||||
|
sftp://*) sftp_mounted "$2" && echo "$2" ;;
|
||||||
|
*) return 1 ;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
|
mount_one() {
|
||||||
|
case "$1" in
|
||||||
|
smb://*) mount_share "$1" ;;
|
||||||
|
sftp://*) sftp_mount "$1" "$2" > /dev/null 2>&1 ;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
[ -f "$STORAGE_CONF" ] || exit 0
|
[ -f "$STORAGE_CONF" ] || exit 0
|
||||||
|
|
||||||
if [ "$1" = --list ]; then
|
if [ "$1" = --list ]; then
|
||||||
while IFS= read -r url; do
|
while IFS='|' read -r url point; do
|
||||||
[ -n "$url" ] || continue
|
[ -n "$url" ] || continue
|
||||||
if point="$(mounted_at "$url")"; then echo "$url|$point"; else echo "$url|"; fi
|
echo "$url|$(mounted_now "$url" "$point")"
|
||||||
done < "$STORAGE_CONF"
|
done < "$STORAGE_CONF"
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
mkdir -p "$FAILED_DIR"
|
mkdir -p "$FAILED_DIR"
|
||||||
while IFS= read -r url; do
|
while IFS='|' read -r url point; do
|
||||||
[ -n "$url" ] || continue
|
[ -n "$url" ] || continue
|
||||||
mounted_at "$url" > /dev/null && continue
|
mounted_now "$url" "$point" > /dev/null && continue
|
||||||
nc -z -G 3 "$(host_of "$url")" 445 > /dev/null 2>&1 || continue
|
case "$url" in
|
||||||
marker="$FAILED_DIR/$(share_key "$url" | tr '/ ' '__')"
|
smb://*) host="$(host_of "$url")" port=445 ;;
|
||||||
|
sftp://*) sftp_parse "$url"; host="$SFTP_HOST" port="$SFTP_PORT" ;;
|
||||||
|
*) continue ;;
|
||||||
|
esac
|
||||||
|
nc -z -G 3 "$host" "$port" > /dev/null 2>&1 || continue
|
||||||
|
marker="$FAILED_DIR/$(echo "$url" | tr -c '[:alnum:]._-' '_')"
|
||||||
if [ -f "$marker" ] && [ $(($(date +%s) - $(stat -f %m "$marker"))) -lt $RETRY_AFTER ]; then
|
if [ -f "$marker" ] && [ $(($(date +%s) - $(stat -f %m "$marker"))) -lt $RETRY_AFTER ]; then
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
if mount_share "$url"; then
|
if mount_one "$url" "$point"; then
|
||||||
rm -f "$marker"
|
rm -f "$marker"
|
||||||
else
|
else
|
||||||
touch "$marker"
|
touch "$marker"
|
||||||
|
|||||||
Reference in New Issue
Block a user