diff --git a/config/apx.json b/config/apx.json index f7d89121..f190a0f3 100644 --- a/config/apx.json +++ b/config/apx.json @@ -1,5 +1,5 @@ { "apxPath": "/usr/share/apx", - "distroboxpath": "/usr/share/apx/distrobox/distrobox", + "distroboxPath": "/usr/share/apx/distrobox/distrobox", "storageDriver": "overlay" -} \ No newline at end of file +} diff --git a/settings/config.go b/settings/config.go index 2c41d55d..20670f58 100644 --- a/settings/config.go +++ b/settings/config.go @@ -12,6 +12,7 @@ package settings import ( "fmt" "os" + "os/exec" "path/filepath" "github.com/spf13/viper" @@ -64,9 +65,23 @@ func GetApxDefaultConfig() (*Config, error) { // fmt.Printf("Using config file: %s\n\n", viper.ConfigFileUsed()) // } + distroboxPath := viper.GetString("distroboxPath") + + _, err = os.Stat(distroboxPath) + if err != nil { + if os.IsNotExist(err) { + path, err := exec.LookPath("distrobox") + if err != nil { + fmt.Printf("Unable to find distrobox in PATH.\n") + } else { + distroboxPath = path + } + } + } + Cnf := NewApxConfig( viper.GetString("apxPath"), - viper.GetString("distroboxPath"), + distroboxPath, viper.GetString("storageDriver"), ) return Cnf, nil