From fb2120c94ebc69f7ac8e15163f1e27b2c8057d9a Mon Sep 17 00:00:00 2001 From: Randall Winkhart Date: Sun, 6 Jul 2025 11:29:41 -0400 Subject: [PATCH] Allow setting custom device ID prefix --- core/init.go | 2 +- synccycles/init.go | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/core/init.go b/core/init.go index 1eb4a74..f6900f2 100644 --- a/core/init.go +++ b/core/init.go @@ -74,7 +74,7 @@ func LibmuttonInit(inputCB func(prompt string) string, clientSpecificIniData [][ return errors.New("unable to write config file: " + err.Error()) } // generate and register device ID - sshEntryRoot, sshIsWindows, err := synccycles.DeviceIDGen(oldDeviceID) + sshEntryRoot, sshIsWindows, err := synccycles.DeviceIDGen(oldDeviceID, "") if err != nil { return errors.New("unable to generate device ID: " + err.Error()) } diff --git a/synccycles/init.go b/synccycles/init.go index b01e1c9..4c1087f 100644 --- a/synccycles/init.go +++ b/synccycles/init.go @@ -16,12 +16,14 @@ import ( // DeviceIDGen generates a new client device ID and registers it with the server (will replace existing one). // Device IDs are only needed for online synchronization. // Device IDs are guaranteed unique as the current UNIX time is appended to them. +// Leave prefix empty to use the current hostname as the prefix. // Returns: the remote EntryRoot and OS type indicator. -func DeviceIDGen(oldDeviceID string) (string, string, error) { +func DeviceIDGen(oldDeviceID, prefix string) (string, string, error) { // generate new device ID - deviceIDPrefix, _ := os.Hostname() - deviceIDSuffix := StringGen(rand.Intn(32)+48, 0.2, 1) + "-" + strconv.FormatInt(time.Now().Unix(), 10) - newDeviceID := deviceIDPrefix + "-" + deviceIDSuffix + if prefix == "" { + prefix, _ = os.Hostname() + } + newDeviceID := prefix + "-" + StringGen(rand.Intn(32)+48, 0.2, 1) + "-" + strconv.FormatInt(time.Now().Unix(), 10) // create new device ID file (locally) newDeviceIDPath := global.ConfigDir + global.PathSeparator + "devices" + global.PathSeparator + newDeviceID