update config

parent 6246bbc3
...@@ -3,6 +3,7 @@ package config ...@@ -3,6 +3,7 @@ package config
import ( import (
"os" "os"
"path/filepath" "path/filepath"
"ximperconf/utils"
) )
type CreateEnv struct { type CreateEnv struct {
...@@ -22,6 +23,7 @@ type RepoEnv struct { ...@@ -22,6 +23,7 @@ type RepoEnv struct {
type Environment struct { type Environment struct {
Version string Version string
IsRoot bool
Create *CreateEnv Create *CreateEnv
Hyprland *HyprEnv Hyprland *HyprEnv
Repo *RepoEnv Repo *RepoEnv
...@@ -31,46 +33,24 @@ var Env Environment ...@@ -31,46 +33,24 @@ var Env Environment
func InitConfig() error { func InitConfig() error {
Env.Version = "0.1.0" Env.Version = "0.1.0"
Env.IsRoot = os.Geteuid() == 0
if _, err := os.Stat("/usr/bin/Hyprland"); os.IsNotExist(err) {
Env.Hyprland = nil
} else {
Env.Hyprland = &HyprEnv{}
}
home, _ := os.UserHomeDir()
Env.Create = &CreateEnv{ Env.Create = &CreateEnv{
Config: "/etc/ximperdistro/ximperconf/profiles.yaml", Config: "/etc/ximperdistro/ximperconf/profiles.yaml",
} }
if Env.Hyprland != nil { if utils.FileExists("/usr/bin/hyprland") {
userModulesPath := filepath.Join(home, ".config", "hypr") home, _ := os.UserHomeDir()
systemModulesPath := "/etc/ximperdistro/hyprland/hypr" userModules := filepath.Join(home, ".config", "hypr")
confPath := filepath.Join(userModulesPath, "hyprland.conf") systemModules := "/etc/ximperdistro/hyprland/hypr"
pluginsPath := "/usr/lib64/hyprland" pluginsDir := "/usr/lib64/hyprland"
confFile := filepath.Join(userModules, "hyprland.conf")
if _, err := os.Stat(userModulesPath); os.IsNotExist(err) {
_ = os.MkdirAll(userModulesPath, 0755) Env.Hyprland = &HyprEnv{
} Config: confFile,
Env.Hyprland.UserModulesDir = userModulesPath UserModulesDir: userModules,
SystemModulesDir: optionalPath(systemModules),
if _, err := os.Stat(systemModulesPath); os.IsNotExist(err) { PluginsDir: optionalPath(pluginsDir),
Env.Hyprland.SystemModulesDir = ""
} else {
Env.Hyprland.SystemModulesDir = systemModulesPath
}
if _, err := os.Stat(pluginsPath); os.IsNotExist(err) {
Env.Hyprland.PluginsDir = ""
} else {
Env.Hyprland.PluginsDir = pluginsPath
}
if _, err := os.Stat(confPath); err == nil {
Env.Hyprland.Config = confPath
} else {
Env.Hyprland.Config = ""
} }
} }
...@@ -80,3 +60,10 @@ func InitConfig() error { ...@@ -80,3 +60,10 @@ func InitConfig() error {
return nil return nil
} }
func optionalPath(path string) string {
if utils.FileExists(path) {
return path
}
return ""
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment