Better way to find home dir even if sudo is used.
This commit is contained in:
parent
913fbdb690
commit
48490673ea
@ -19,6 +19,10 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func CmdNew(c *cli.Context) error {
|
func CmdNew(c *cli.Context) error {
|
||||||
|
if os.Getuid() != 0 {
|
||||||
|
golog.Fatalf("You need to run this command as root.")
|
||||||
|
}
|
||||||
|
|
||||||
name := strings.TrimSpace(c.String("name"))
|
name := strings.TrimSpace(c.String("name"))
|
||||||
domain := strings.TrimSpace(c.String("domain"))
|
domain := strings.TrimSpace(c.String("domain"))
|
||||||
customProjectPath := strings.TrimSpace(c.String("custom-path"))
|
customProjectPath := strings.TrimSpace(c.String("custom-path"))
|
||||||
|
@ -2,6 +2,7 @@ package hoster_cli
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
|
"os/user"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"gitea.codeblob.work/pk/hoster/cmd/hoster_cli/commands"
|
"gitea.codeblob.work/pk/hoster/cmd/hoster_cli/commands"
|
||||||
@ -12,17 +13,12 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func Execute() {
|
func Execute() {
|
||||||
homeDir, err := os.UserHomeDir()
|
conf.LoadConfig(filepath.Join(findHomeDir(), ".hoster.yml"))
|
||||||
if err != nil {
|
|
||||||
golog.Fatalf("Error getting home directory: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
conf.LoadConfig(filepath.Join(homeDir, ".hoster.yml"))
|
|
||||||
|
|
||||||
app := &cli.App{
|
app := &cli.App{
|
||||||
Name: "hoster",
|
Name: "hoster",
|
||||||
Usage: "Hoster",
|
Usage: "Hoster",
|
||||||
Version: "1.0.8",
|
Version: "1.0.9",
|
||||||
Commands: []*cli.Command{
|
Commands: []*cli.Command{
|
||||||
{
|
{
|
||||||
Name: "new",
|
Name: "new",
|
||||||
@ -60,3 +56,27 @@ func Execute() {
|
|||||||
golog.Fatal(err)
|
golog.Fatal(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func findHomeDir() string {
|
||||||
|
if os.Getuid() == 0 {
|
||||||
|
username := os.Getenv("SUDO_USER")
|
||||||
|
|
||||||
|
if username == "" {
|
||||||
|
golog.Fatalf("SUDO_USER environment variable is not set.")
|
||||||
|
}
|
||||||
|
|
||||||
|
u, err := user.Lookup(username)
|
||||||
|
if err != nil {
|
||||||
|
golog.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return u.HomeDir
|
||||||
|
}
|
||||||
|
|
||||||
|
dir, err := os.UserHomeDir()
|
||||||
|
if err != nil {
|
||||||
|
golog.Fatalf("Error getting home directory: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return dir
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user