ceremonyclient/client/cmd/node/nodeconfig/import.go
Tyler Sturos 9cfbdef12c
Feat/2.1 qclient refactor and node install (#429)
* initial auto-update

* working link, update, and testing docker container and scripts

* refactor packages/folders

* move files to proper folders

* fix typos

Closes #421

* optimize rpm imports

* optimize channel imports

* Refactor split command to allow testing of split operations

Closes #338

* modify split and test for folder changes

* remove alias

* fix docker warning about FROM and AS being in different letter case

Closes #422

* QClient Account Command

* Display transaction details and confirmation prompts for transfer and merge commands

* build qclient docker improvements

* update build args for mpfr.so.6

* update install and node commands

* remove NodeConfig check for qclient node commands

* udpate

* working node commands

* update commands

* move utils and rename package

---------

Co-authored-by: Vasyl Tretiakov <vasyl.tretiakov@gmail.com>
Co-authored-by: littleblackcloud <163544315+littleblackcloud@users.noreply.github.com>
Co-authored-by: 0xOzgur <29779769+0xOzgur@users.noreply.github.com>
Co-authored-by: Cassandra Heart <7929478+CassOnMars@users.noreply.github.com>
2025-04-11 21:43:20 -05:00

79 lines
2.2 KiB
Go

package nodeconfig
import (
"fmt"
"os"
"path/filepath"
"github.com/spf13/cobra"
"source.quilibrium.com/quilibrium/monorepo/client/utils"
)
var importCmd = &cobra.Command{
Use: "import [name] [source_directory]",
Short: "Import config.yml and keys.yml from a source directory",
Long: `Import config.yml and keys.yml from a source directory to the QuilibriumRoot config folder.
Example:
qclient node config import mynode /path/to/source
This will copy config.yml and keys.yml from /path/to/source to /home/quilibrium/configs/mynode/`,
Args: cobra.ExactArgs(2),
Run: func(cmd *cobra.Command, args []string) {
name := args[0]
sourceDir := args[1]
// Check if source directory exists
if _, err := os.Stat(sourceDir); os.IsNotExist(err) {
fmt.Printf("Source directory does not exist: %s\n", sourceDir)
os.Exit(1)
}
if !HasConfigFiles(sourceDir) {
fmt.Printf("Source directory does not contain both config.yml and keys.yml files: %s\n", sourceDir)
os.Exit(1)
}
// Create target directory in the standard location
targetDir := filepath.Join(ConfigDirs, name)
if err := utils.ValidateAndCreateDir(targetDir, NodeUser); err != nil {
fmt.Printf("Failed to create target directory: %s\n", err)
os.Exit(1)
}
// Define source file paths
sourceConfigPath := filepath.Join(sourceDir, "config.yml")
sourceKeysPath := filepath.Join(sourceDir, "keys.yml")
// Copy config.yml
targetConfigPath := filepath.Join(targetDir, "config.yml")
if err := utils.CopyFile(sourceConfigPath, targetConfigPath); err != nil {
fmt.Printf("Failed to copy config.yml: %s\n", err)
os.Exit(1)
}
// Copy keys.yml
targetKeysPath := filepath.Join(targetDir, "keys.yml")
if err := utils.CopyFile(sourceKeysPath, targetKeysPath); err != nil {
fmt.Printf("Failed to copy keys.yml: %s\n", err)
os.Exit(1)
}
if SetDefault {
// Create the symlink
if err := utils.CreateSymlink(targetDir, NodeConfigToRun); err != nil {
fmt.Printf("Failed to create symlink: %s\n", err)
os.Exit(1)
}
fmt.Printf("Successfully imported config files to %s and symlinked to default\n", name)
} else {
fmt.Printf("Successfully imported config files to %s\n", targetDir)
}
},
}
func init() {
}