Skip to content

Commit

Permalink
add config to readme, update error output in switch command
Browse files Browse the repository at this point in the history
  • Loading branch information
hertg committed Sep 12, 2022
1 parent 1ff2778 commit 022fcc4
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 3 deletions.
33 changes: 33 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,39 @@ Use "egpu-switcher [command] --help" for more information about a command.

---

## Configuration

The config file is created automatically and can be found at `/etc/egpu-switcher/config.yaml`.
Below you can see an example of a configuration file, annotated with some notes.

```yaml
# the 'egpu' config is generated by 'egpu-switcher config'.
# you probably shouldn't change this manually.
egpu:
driver: amdgpu
id: 1153611719250962689

# OPTIONAL: how many times 'egpu-switcher switch auto' should retry finding the egpu.
# this can be helpful if the egpu takes some time to connect on your machine,
# the following values are the default, if this config is omitted.
detection:
retries: 6
interval: 500 # milliseconds

# OPTIONAL: if you want to execute a script after switching to egpu/internal.
# the values must be absolute paths to a shell script, this script will
# then be run with '/bin/sh $script'.
#
# it is required that the script is owned by root (uid 0)
# and has a permission of -rwx------ (0700), in order to
# prevent potential privilege escalation.
hooks:
internal: /home/michael/tmp/internal.sh
egpu: /home/michael/tmp/egpu.sh
```
---
## Troubleshooting
If you run into problems, please have a look at
Expand Down
6 changes: 3 additions & 3 deletions cmd/switch.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ func switchInternal() error {
}
if post := viper.GetString("hooks.internal"); post != "" {
if err := runHook(post); err != nil {
logger.Error("egpu hook error: %s", err)
logger.Error("internal hook error: %s", err)
}
}
return nil
Expand All @@ -174,7 +174,7 @@ func switchAuto(gpu *pci.GPU) error {

func runHook(script string) error {
if !permissionCheck(script) {
return fmt.Errorf("hook scripts need to be sufficiently protected because they are run as root")
return fmt.Errorf("hook %s will not be executed", script)
}
cmd := exec.Command("/bin/sh", script)
err := cmd.Run()
Expand All @@ -187,7 +187,7 @@ func runHook(script string) error {
func permissionCheck(file string) bool {
info, err := os.Stat(file)
if err != nil {
logger.Debug("unable to get info about %s: %s", file, err)
logger.Error("%s", err)
return false
}
if stat, ok := info.Sys().(*syscall.Stat_t); ok {
Expand Down

0 comments on commit 022fcc4

Please sign in to comment.