From d7242fee96b32b6b1ba4cec6952b143019b59b78 Mon Sep 17 00:00:00 2001 From: Randall Winkhart Date: Sat, 7 Feb 2026 15:05:15 -0500 Subject: [PATCH] Native support for iOS dirs; bind SSH dir to variable --- core/init.go | 4 ++-- global/2globals_IOS.go | 27 +++++++++++++++++++++++++++ global/2globals_UNIX.go | 3 ++- global/2globals_WIN.go | 1 + syncclient/client.go | 2 +- 5 files changed, 33 insertions(+), 4 deletions(-) create mode 100644 global/2globals_IOS.go diff --git a/core/init.go b/core/init.go index 52fdb9e..d57256d 100644 --- a/core/init.go +++ b/core/init.go @@ -46,7 +46,7 @@ func LibmuttonInit(inputCB func(prompt string) string, rcwPassword []byte, appen } } else { // ensure ssh key file exists (and is a file) - fallbackSSHKey := back.Home + global.PathSeparator + ".ssh" + global.PathSeparator + "id_ed25519" + fallbackSSHKey := global.SSHDir + global.PathSeparator + "id_ed25519" sshKeyPath := cmp.Or(back.ExpandPathWithHome(inputCB("SSH private identity file path (falls back to \""+fallbackSSHKey+"\"):")), fallbackSSHKey) _, err := back.TargetIsFile(sshKeyPath, true) if err != nil { @@ -70,7 +70,7 @@ func LibmuttonInit(inputCB func(prompt string) string, rcwPassword []byte, appen return errors.New("unable to initialize libmutton directories: " + err.Error()) } //// write config file - //// temporarily leave sshEntryRootPath, sshAgeDirPath, and sshIsWindows as nil to pass initial device ID registration + //// temporarily leave sshEntryRootPath, sshAgeDirPath, and sshIsWindows as nil/default to pass initial device ID registration newCfg.Libmutton.OfflineMode = &forceOfflineMode // forceOfflineMode must be false to reach this point, so we can avoid the extra declaration newCfg.Libmutton.SSHUser = &sshUser newCfg.Libmutton.SSHIP = &sshIP diff --git a/global/2globals_IOS.go b/global/2globals_IOS.go new file mode 100644 index 0000000..84e3cb4 --- /dev/null +++ b/global/2globals_IOS.go @@ -0,0 +1,27 @@ +//go:build ios + +package global + +import ( + "path/filepath" + + "github.com/rwinkhart/go-boilerplate/back" +) + +func init() { + // get the app's Library/Application Support directory (private, not backed up by iCloud) + back.Home = filepath.Join(back.Home, "Library", "Application Support", "libmutton-ios") +} + +var ( + EntryRoot = back.Home + "/entries" // Path to libmutton entry directory + CfgDir = back.Home + "/config" // Path to libmutton configuration directory + CfgPath = CfgDir + "/libmuttoncfg.json" // Path to libmutton configuration file + AgeDir = CfgDir + "/age" // Path to libmutton password age directory + SSHDir = back.Home + "/ssh" // Path to SSH directory +) + +const ( + PathSeparator = "/" // Platform-specific path separator + IsWindows = false // Platform indicator +) diff --git a/global/2globals_UNIX.go b/global/2globals_UNIX.go index 4afaac0..eaf72c5 100644 --- a/global/2globals_UNIX.go +++ b/global/2globals_UNIX.go @@ -1,4 +1,4 @@ -//go:build !windows +//go:build !windows && !ios && !android package global @@ -9,6 +9,7 @@ var ( CfgDir = back.Home + "/.config/libmutton" // Path to libmutton configuration directory CfgPath = CfgDir + "/libmuttoncfg.json" // Path to libmutton configuration file AgeDir = CfgDir + "/age" // Path to libmutton password age directory + SSHDir = back.Home + "/.ssh" // Path to SSH directory ) const ( diff --git a/global/2globals_WIN.go b/global/2globals_WIN.go index 641f858..6704cab 100644 --- a/global/2globals_WIN.go +++ b/global/2globals_WIN.go @@ -9,6 +9,7 @@ var ( CfgDir = back.Home + "\\AppData\\Local\\libmutton\\config" // Path to libmutton configuration directory CfgPath = CfgDir + "\\libmuttoncfg.json" // Path to libmutton configuration file AgeDir = CfgDir + "\\age" // Path to libmutton password age directory + SSHDir = back.Home + "\\.ssh" // Path to SSH directory ) const ( diff --git a/syncclient/client.go b/syncclient/client.go index 173d286..a8298a4 100644 --- a/syncclient/client.go +++ b/syncclient/client.go @@ -60,7 +60,7 @@ func GetSSHClient() (*ssh.Client, bool, *bool, *string, *string, error) { // read known hosts file var hostKeyCallback ssh.HostKeyCallback - hostKeyCallback, err = knownhosts.New(back.Home + global.PathSeparator + ".ssh" + global.PathSeparator + "known_hosts") + hostKeyCallback, err = knownhosts.New(global.SSHDir + global.PathSeparator + "known_hosts") if err != nil { return nil, false, nil, nil, nil, errors.New("unable to read known hosts file: " + err.Error()) }