mirror of
https://github.com/QuilibriumNetwork/ceremonyclient.git
synced 2026-02-21 18:37:26 +08:00
* 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>
92 lines
2.2 KiB
Go
92 lines
2.2 KiB
Go
package utils
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"path/filepath"
|
|
|
|
"gopkg.in/yaml.v2"
|
|
)
|
|
|
|
var ClientConfigDir = filepath.Join(os.Getenv("HOME"), ".quilibrium")
|
|
var ClientConfigFile = string(ReleaseTypeQClient) + "-config.yaml"
|
|
var ClientConfigPath = filepath.Join(ClientConfigDir, ClientConfigFile)
|
|
|
|
func CreateDefaultConfig() {
|
|
configPath := GetConfigPath()
|
|
|
|
fmt.Printf("Creating default config: %s\n", configPath)
|
|
SaveClientConfig(&ClientConfig{
|
|
DataDir: ClientDataPath,
|
|
SymlinkPath: DefaultQClientSymlinkPath,
|
|
SignatureCheck: true,
|
|
})
|
|
|
|
sudoUser, err := GetCurrentSudoUser()
|
|
if err != nil {
|
|
fmt.Println("Error getting current sudo user")
|
|
os.Exit(1)
|
|
}
|
|
ChownPath(GetUserQuilibriumDir(), sudoUser, true)
|
|
}
|
|
|
|
// LoadClientConfig loads the client configuration from the config file
|
|
func LoadClientConfig() (*ClientConfig, error) {
|
|
configPath := GetConfigPath()
|
|
|
|
// Create default config if it doesn't exist
|
|
if _, err := os.Stat(configPath); os.IsNotExist(err) {
|
|
config := &ClientConfig{
|
|
DataDir: ClientDataPath,
|
|
SymlinkPath: filepath.Join(ClientDataPath, "current"),
|
|
SignatureCheck: true,
|
|
}
|
|
if err := SaveClientConfig(config); err != nil {
|
|
return nil, err
|
|
}
|
|
return config, nil
|
|
}
|
|
|
|
// Read existing config
|
|
data, err := os.ReadFile(configPath)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
config := &ClientConfig{}
|
|
if err := yaml.Unmarshal(data, config); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return config, nil
|
|
}
|
|
|
|
// SaveClientConfig saves the client configuration to the config file
|
|
func SaveClientConfig(config *ClientConfig) error {
|
|
data, err := yaml.Marshal(config)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
// Ensure the config directory exists
|
|
if err := os.MkdirAll(GetConfigDir(), 0755); err != nil {
|
|
return fmt.Errorf("failed to create config directory: %w", err)
|
|
}
|
|
|
|
return os.WriteFile(GetConfigPath(), data, 0644)
|
|
}
|
|
|
|
// GetConfigPath returns the path to the client configuration file
|
|
func GetConfigPath() string {
|
|
return filepath.Join(GetConfigDir(), ClientConfigFile)
|
|
}
|
|
|
|
func GetConfigDir() string {
|
|
return filepath.Join(GetUserQuilibriumDir())
|
|
}
|
|
|
|
// IsClientConfigured checks if the client is configured
|
|
func IsClientConfigured() bool {
|
|
return FileExists(ClientConfigPath)
|
|
}
|