Fix init if devices directory does not exist/is empty

This commit is contained in:
2024-08-13 20:21:11 -04:00
parent b1fc8e3c4d
commit be46b0d6b2
5 changed files with 25 additions and 17 deletions
+5 -8
View File
@@ -9,7 +9,6 @@ import (
"time"
"github.com/rwinkhart/libmutton/core"
"golang.org/x/crypto/ssh"
)
// DeviceIDGen generates a new client device ID and registers it with the server (will replace existing one).
@@ -34,14 +33,12 @@ func DeviceIDGen(oldDeviceID string) (string, string) {
// also removes the old device ID file (remotely)
// manualSync is true so the user is alerted if device ID registration fails
sshClient, _, _ := GetSSHClient(true)
defer func(sshClient *ssh.Client) {
err = sshClient.Close()
if err != nil {
fmt.Println(core.AnsiError+"Init failed - Unable to close SSH client:", err.Error()+core.AnsiReset)
os.Exit(104)
}
}(sshClient)
sshEntryRootSSHIsWindows := strings.Split(GetSSHOutput(sshClient, "libmuttonserver register", newDeviceID+"\n"+oldDeviceID), FSSpace)
err = sshClient.Close()
if err != nil {
fmt.Println(core.AnsiError+"Init failed - Unable to close SSH client:", err.Error()+core.AnsiReset)
os.Exit(104)
}
// remove old device ID file (locally; may not exist)
err = os.RemoveAll(core.ConfigDir + core.PathSeparator + "devices" + core.PathSeparator + oldDeviceID)