mirror of
https://github.com/QuilibriumNetwork/ceremonyclient.git
synced 2026-02-21 10:27: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>
101 lines
2.9 KiB
Go
101 lines
2.9 KiB
Go
package cmd
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
|
|
"github.com/spf13/cobra"
|
|
"source.quilibrium.com/quilibrium/monorepo/client/utils"
|
|
)
|
|
|
|
var symlinkPath = "/usr/local/bin/qclient"
|
|
|
|
var linkCmd = &cobra.Command{
|
|
Use: "link",
|
|
Short: "Create a symlink to qclient in PATH",
|
|
Long: `Create a symlink to the qclient binary in the directory /usr/local/bin/.
|
|
|
|
Example: qclient link`,
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
// Get the path to the current executable
|
|
execPath, err := os.Executable()
|
|
if err != nil {
|
|
return fmt.Errorf("failed to get executable path: %w", err)
|
|
}
|
|
|
|
IsSudo := utils.IsSudo()
|
|
if IsSudo {
|
|
fmt.Println("Running as sudo, creating symlink at /usr/local/bin/qclient")
|
|
} else {
|
|
fmt.Println("Cannot create symlink at /usr/local/bin/qclient, please run this command with sudo")
|
|
os.Exit(1)
|
|
}
|
|
|
|
// Check if the current executable is in the expected location
|
|
expectedPrefix := utils.ClientDataPath
|
|
|
|
// Check if the current executable is in the expected location
|
|
if !strings.HasPrefix(execPath, expectedPrefix) {
|
|
fmt.Printf("Current executable is not in the expected location: %s\n", execPath)
|
|
fmt.Printf("Expected location should start with: %s\n", expectedPrefix)
|
|
|
|
// Ask user if they want to move it
|
|
fmt.Print("Would you like to move the executable to the standard location? (y/n): ")
|
|
var response string
|
|
fmt.Scanln(&response)
|
|
|
|
if strings.ToLower(response) == "y" || strings.ToLower(response) == "yes" {
|
|
if err := moveExecutableToStandardLocation(execPath); err != nil {
|
|
return fmt.Errorf("failed to move executable: %w", err)
|
|
}
|
|
// Update execPath to the new location
|
|
execPath, err = os.Executable()
|
|
if err != nil {
|
|
return fmt.Errorf("failed to get new executable path: %w", err)
|
|
}
|
|
} else {
|
|
fmt.Println("Continuing with current location...")
|
|
}
|
|
}
|
|
|
|
// Create the symlink (handles existing symlinks)
|
|
if err := utils.CreateSymlink(execPath, symlinkPath); err != nil {
|
|
return err
|
|
}
|
|
|
|
fmt.Printf("Symlink created at %s\n", symlinkPath)
|
|
return nil
|
|
},
|
|
}
|
|
|
|
func moveExecutableToStandardLocation(execPath string) error {
|
|
// Get the directory of the current executable
|
|
version, err := GetVersionInfo(false)
|
|
if err != nil {
|
|
return fmt.Errorf("failed to get version info: %w", err)
|
|
}
|
|
destDir := filepath.Join(utils.ClientDataPath, "bin", version.Version)
|
|
|
|
// Create the standard location directory if it doesn't exist
|
|
currentUser, err := utils.GetCurrentSudoUser()
|
|
if err != nil {
|
|
return fmt.Errorf("failed to get current user: %w", err)
|
|
}
|
|
if err := utils.ValidateAndCreateDir(destDir, currentUser); err != nil {
|
|
return fmt.Errorf("failed to create directory: %w", err)
|
|
}
|
|
|
|
// Move the executable to the standard location
|
|
if err := os.Rename(execPath, filepath.Join(destDir, StandardizedQClientFileName)); err != nil {
|
|
return fmt.Errorf("failed to move executable: %w", err)
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func init() {
|
|
rootCmd.AddCommand(linkCmd)
|
|
}
|