internal/router: change default config directory on EdgeOS

So ctrld's own files will survive firmware upgrades.
This commit is contained in:
Cuong Manh Le
2024-07-17 14:21:14 +07:00
committed by Cuong Manh Le
parent c24589a5be
commit b3eebb19b6

View File

@@ -7,6 +7,7 @@ import (
"os"
"os/exec"
"path/filepath"
"strings"
"sync/atomic"
"github.com/kardianos/service"
@@ -164,6 +165,16 @@ func HomeDir() (string, error) {
return "", err
}
return filepath.Dir(exe), nil
case edgeos.Name:
exe, err := os.Executable()
if err != nil {
return "", err
}
// Using binary directory as home dir if it is located in /config.
// Otherwise, fallback to old behavior for compatibility.
if strings.HasPrefix(exe, "/config/") {
return filepath.Dir(exe), nil
}
}
return "", nil
}