From 58dde7ed5d31cf6f8f4e56d8e0a5a45496dbb2a9 Mon Sep 17 00:00:00 2001 From: Randall Winkhart Date: Thu, 8 Aug 2024 17:41:22 -0400 Subject: [PATCH] Move libmuttonserver.go to github.com/rwinkhart/libmutton --- libmuttonserver.go | 92 ---------------------------------------------- 1 file changed, 92 deletions(-) delete mode 100644 libmuttonserver.go diff --git a/libmuttonserver.go b/libmuttonserver.go deleted file mode 100644 index 235ce0e..0000000 --- a/libmuttonserver.go +++ /dev/null @@ -1,92 +0,0 @@ -package main - -import ( - "bufio" - "fmt" - "os" - "strconv" - "strings" - - "github.com/rwinkhart/MUTN/src/cli" - "github.com/rwinkhart/libmutton/core" - "github.com/rwinkhart/libmutton/sync" -) - -func main() { - args := os.Args - if len(args) < 2 { - helpServer() - } - - // check if stdin was provided - stdinInfo, _ := os.Stdin.Stat() - stdinPresent := stdinInfo.Mode()&os.ModeNamedPipe != 0 - - var stdin []string - if stdinPresent { - // read stdin, appending each line to the stdin slice - scanner := bufio.NewScanner(os.Stdin) - for scanner.Scan() { - stdin = append(stdin, scanner.Text()) - } - } - - switch args[1] { - case "fetch": - // print all information needed for syncing to stdout for interpretation by the client - // stdin[0] is expected to be the device ID - sync.GetRemoteDataFromServer(stdin[0]) - case "rename": - // move an entry to a new location before using fallthrough to add its previous iteration to the deletions directory - // stdin[0] is evaluated after fallthrough - // stdin[1] is expected to be the OLD incomplete target location with FSPath representing path separators - always pass in UNIX format - // stdin[2] is expected to be the NEW incomplete target location with FSPath representing path separators - always pass in UNIX format - sync.RenameLocal(strings.ReplaceAll(stdin[1], sync.FSPath, "/"), strings.ReplaceAll(stdin[2], sync.FSPath, "/"), true) - fallthrough // fallthrough to add the old entry to the deletions directory - case "shear": - // shear an entry from the server and add it to the deletions directory - // stdin[0] is expected to be the device ID - // stdin[1] is expected to be the incomplete target location with FSPath representing path separators - always pass in UNIX format - sync.ShearLocal(strings.ReplaceAll(stdin[1], sync.FSPath, "/"), stdin[0]) - case "addfolder": - // add a new folder to the server - // stdin[0] is expected to be the incomplete target location with FSPath representing path separators - always pass in UNIX format - sync.AddFolderLocal(strings.ReplaceAll(stdin[0], sync.FSPath, "/")) - case "register": - // register a new device ID - // stdin[0] is expected to be the device ID - _, _ = os.Create(core.ConfigDir + core.PathSeparator + "devices" + core.PathSeparator + stdin[0]) // error ignored; failure unlikely to occur if init was successful; "register" is not a user-facing argument and thus the error would not be visible - // print EntryRoot and bool indicating OS type to stdout for client to store in config - fmt.Print(core.EntryRoot + sync.FSSpace + strconv.FormatBool(core.IsWindows)) - case "init": - // create the necessary directories for libmuttonserver to function - core.DirInit(false) - _ = os.MkdirAll(core.ConfigDir+core.PathSeparator+"deletions", 0700) // error ignored; failure would have occurred by this point in core.DirInit - fmt.Println("libmuttonserver directories initialized") - case "version": - versionServer() - default: - helpServer() - } -} - -func helpServer() { - fmt.Print(cli.AnsiBold + "\nlibmuttonserver | Copyright (c) 2024 Randall Winkhart\n" + core.AnsiReset + ` -This software exists under the MIT license; you may redistribute it under certain conditions. -This program comes with absolutely no warranty; type "libmuttonserver version" for details. - -` + cli.AnsiBold + "Usage:" + core.AnsiReset + ` libmuttonserver - -` + cli.AnsiBold + "Arguments (user):" + core.AnsiReset + ` - help Bring up this menu - version Display version and license information - init Create the necessary directories for libmuttonserver to function` + "\n\n") - os.Exit(0) -} - -func versionServer() { - cli.MITLicense() - fmt.Print(cli.AnsiBold + "\n\n libmuttonserver" + core.AnsiReset + " Version " + core.LibmuttonVersion + ` - - Copyright (c) 2024 Randall Winkhart` + "\n\n") -}