51 lines
991 B
Go
51 lines
991 B
Go
package torrent
|
|
|
|
import (
|
|
"fmt"
|
|
"os/exec"
|
|
|
|
"github.com/debridmediamanager/zurg/internal/config"
|
|
"go.uber.org/zap"
|
|
)
|
|
|
|
type ScriptExecutor struct {
|
|
Script string
|
|
Args []string
|
|
}
|
|
|
|
func (se *ScriptExecutor) Execute() error {
|
|
if se.Script == "" {
|
|
return nil
|
|
}
|
|
|
|
// Prepare the command
|
|
cmd := exec.Command("/bin/sh", "-c", se.Script)
|
|
cmd.Args = append(cmd.Args, se.Args...)
|
|
|
|
// Start the command and immediately return, not caring about its state
|
|
err := cmd.Start()
|
|
if err != nil {
|
|
return fmt.Errorf("error starting script: %v", err)
|
|
}
|
|
|
|
// Detach the process
|
|
go func() {
|
|
cmd.Wait()
|
|
}()
|
|
|
|
return nil
|
|
}
|
|
|
|
func OnLibraryUpdateHook(paths []string, config config.ConfigInterface, log *zap.SugaredLogger) {
|
|
executor := &ScriptExecutor{
|
|
Script: config.GetOnLibraryUpdate(),
|
|
Args: paths,
|
|
}
|
|
err := executor.Execute()
|
|
if err != nil {
|
|
log.Errorf("Failed to execute hook on_library_update: %v", err)
|
|
return
|
|
}
|
|
// No need to log the output since we're not capturing it
|
|
}
|