Implement initial server-side shearing logic

This commit is contained in:
2024-05-16 16:35:05 -04:00
parent 043a17de59
commit bb67446653
3 changed files with 23 additions and 3 deletions
+20 -1
View File
@@ -1,9 +1,28 @@
package main
import (
"fmt"
"github.com/rwinkhart/MUTN/src/backend"
"github.com/rwinkhart/MUTN/src/sync"
"os"
"strings"
)
func main() {
sync.GetRemoteDataFromServer()
args := os.Args
if len(args) < 2 {
fmt.Println(backend.AnsiError + "No arguments supplied" + backend.AnsiReset) // TODO add server help menu
os.Exit(0)
}
switch args[1] {
case "fetch":
sync.GetRemoteDataFromServer()
case "shear":
deviceIDTargetLocation := strings.Split(args[2], "\x1d")
targetLocationIncomplete := strings.ReplaceAll(strings.ReplaceAll(deviceIDTargetLocation[1], "\x1f", " "), "\x1e", backend.PathSeparator)
sync.Shear(targetLocationIncomplete, deviceIDTargetLocation[0])
default:
fmt.Println(backend.AnsiError + "Invalid argument" + backend.AnsiReset) // TODO add server help menu
}
}
+1 -1
View File
@@ -45,7 +45,7 @@ func main() {
case "add":
cli.AddEntry(targetLocation, true, 0)
case "shear":
backend.Shear(targetLocation)
sync.Shear(args[1], "") // pass the incomplete path for cleaner formatting in server deletions directory
default:
cli.HelpMain()
}
+2 -1
View File
@@ -34,6 +34,7 @@ func TempInitCli() {
deviceIDPrefix, _ := os.Hostname()
deviceIDSuffix := backend.StringGen(rand.Intn(48)+48, true, 0.2)
deviceID := deviceIDPrefix + "-" + deviceIDSuffix
os.Create(backend.ConfigDir + backend.PathSeparator + "devices" + backend.PathSeparator + deviceID) // TODO remove existing device ID file if it exists, copy device ID to server
// necessary SSH info
sshUser := input("Remote SSH username:")
@@ -42,7 +43,7 @@ func TempInitCli() {
sshIdentity := input("SSH private identity file path:") // TODO implement generator and selector
// write config file
backend.TempInit(map[string]string{"textEditor": textEditor, "gpgID": gpgID, "deviceID": deviceID, "sshUser": sshUser, "sshIP": sshIP, "sshPort": sshPort, "sshIdentity": sshIdentity})
backend.TempInit(map[string]string{"textEditor": textEditor, "gpgID": gpgID, "sshUser": sshUser, "sshIP": sshIP, "sshPort": sshPort, "sshIdentity": sshIdentity})
} else {
// write config file
backend.TempInit(map[string]string{"textEditor": textEditor, "gpgID": gpgID})