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>
67 lines
1.4 KiB
Go
67 lines
1.4 KiB
Go
package utils
|
|
|
|
import (
|
|
"bytes"
|
|
"fmt"
|
|
"os"
|
|
"os/exec"
|
|
"os/user"
|
|
"path/filepath"
|
|
"runtime"
|
|
"strings"
|
|
)
|
|
|
|
// GetSystemInfo determines and validates the OS and architecture
|
|
func GetSystemInfo() (string, string, error) {
|
|
osType := runtime.GOOS
|
|
arch := runtime.GOARCH
|
|
|
|
// Check if OS type is supported
|
|
if osType != "darwin" && osType != "linux" {
|
|
return "", "", fmt.Errorf("unsupported operating system: %s", osType)
|
|
}
|
|
|
|
// Map Go architecture names to Quilibrium architecture names
|
|
if arch == "amd64" {
|
|
arch = "amd64"
|
|
} else if arch == "arm64" {
|
|
arch = "arm64"
|
|
} else {
|
|
return "", "", fmt.Errorf("unsupported architecture: %s", arch)
|
|
}
|
|
|
|
return osType, arch, nil
|
|
}
|
|
|
|
func GetCurrentSudoUser() (*user.User, error) {
|
|
if os.Geteuid() != 0 {
|
|
return user.Current()
|
|
}
|
|
|
|
cmd := exec.Command("sh", "-c", "env | grep SUDO_USER | cut -d= -f2 | cut -d\\n -f1")
|
|
var out bytes.Buffer
|
|
var stderr bytes.Buffer
|
|
cmd.Stdout = &out
|
|
cmd.Stderr = &stderr
|
|
err := cmd.Run()
|
|
if err != nil {
|
|
return nil, fmt.Errorf("failed to get current sudo user: %v", err)
|
|
}
|
|
|
|
userLookup, err := user.Lookup(strings.TrimSpace(out.String()))
|
|
if err != nil {
|
|
return nil, fmt.Errorf("failed to get current sudo user: %v", err)
|
|
}
|
|
return userLookup, nil
|
|
}
|
|
|
|
func GetUserQuilibriumDir() string {
|
|
sudoUser, err := GetCurrentSudoUser()
|
|
if err != nil {
|
|
fmt.Println("Error getting current sudo user")
|
|
os.Exit(1)
|
|
}
|
|
|
|
return filepath.Join(sudoUser.HomeDir, ".quilibrium")
|
|
}
|