mirror of https://github.com/tailscale/tailscale/
cmd/tailscale,ipn:add support for automounting TailFS shares on MacOS
This adds two flags to the "tailscale set" command. --automount-enabled enables automatically mounting TailFS shares --automount-path optionally specifies the path at which to automount If --automount-path is not set, TailFS will be mounted at /Volumes/tailscale. The mount is owned by whatever user invoked "tailscale set" and has mode 0700 set (read,write,execute only by owning user). By default, automounting is not enabled. Updates tailscale/corp#16827 Signed-off-by: Percy Wegmann <percy@tailscale.com>oxtoacart/automount
parent
15b2c674bf
commit
3985947437
@ -0,0 +1,12 @@
|
||||
// Copyright (c) Tailscale Inc & AUTHORS
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
package tailfs
|
||||
|
||||
import "tailscale.com/version"
|
||||
|
||||
// AutomountSupported reports whether TailFS automounting is supported on this
|
||||
// system.
|
||||
func AutomountSupported() bool {
|
||||
return DefaultAutomountPath() != "" && !version.IsSandboxedMacOS()
|
||||
}
|
@ -0,0 +1,62 @@
|
||||
// Copyright (c) Tailscale Inc & AUTHORS
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
//go:build darwin
|
||||
|
||||
package tailfs
|
||||
|
||||
import (
|
||||
"log"
|
||||
"os"
|
||||
"os/exec"
|
||||
"os/user"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// DefaultAutomountPath returns the default automount path. If blank, that
|
||||
// means TailFS is disabled on this platform.
|
||||
func DefaultAutomountPath() string {
|
||||
return "/Volumes/tailscale"
|
||||
}
|
||||
|
||||
func MountShares(location string, username string) {
|
||||
u, err := user.Lookup(username)
|
||||
if err != nil {
|
||||
log.Printf("warning: error looking up user %q, won't automount shares: %s", username, err)
|
||||
return
|
||||
}
|
||||
uid, err := strconv.Atoi(u.Uid)
|
||||
if err != nil {
|
||||
log.Printf("warning: failed to parse uid %q, won't automount shares: %s", u.Uid, err)
|
||||
}
|
||||
gid, err := strconv.Atoi(u.Gid)
|
||||
if err != nil {
|
||||
log.Printf("warning: failed to parse gid %q, won't automount shares: %s", u.Gid, err)
|
||||
}
|
||||
|
||||
location = filepath.Clean(location)
|
||||
err = os.MkdirAll(location, 0700)
|
||||
if err != nil {
|
||||
log.Printf("warning: can't make automount location %q: %s", location, err)
|
||||
return
|
||||
}
|
||||
|
||||
err = os.Chown(location, uid, gid)
|
||||
if err != nil {
|
||||
log.Printf("warning: failed to chown automount location, won't automount shares: %s", err)
|
||||
}
|
||||
|
||||
out, err := exec.Command("sudo", "-u", username, "mount", "-t", "webdav", "http://100.100.100.100:8080", location).CombinedOutput()
|
||||
if err != nil {
|
||||
log.Printf("warning: can't automount shares at %q: %s", location, out)
|
||||
}
|
||||
}
|
||||
|
||||
func UnmountShares(location string) {
|
||||
location = filepath.Clean(location)
|
||||
out, err := exec.Command("diskutil", "umount", location).CombinedOutput()
|
||||
if err != nil {
|
||||
log.Printf("warning: can't unmount shares from %q: %s", location, out)
|
||||
}
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
// Copyright (c) Tailscale Inc & AUTHORS
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
//go:build !darwin
|
||||
|
||||
package tailfs
|
||||
|
||||
// DefaultAutomountPath returns the default automount path. If blank, that
|
||||
// means TailFS is disabled on this platform.
|
||||
func DefaultAutomountPath() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func MountShares(location string, username string) {
|
||||
// Do nothing.
|
||||
}
|
||||
|
||||
func UnmountShares(location string) {
|
||||
// Do nothing.
|
||||
}
|
Loading…
Reference in New Issue