forked from owncast/owncast
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathverifyInstall.go
66 lines (50 loc) · 1.79 KB
/
verifyInstall.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package config
import (
"errors"
"fmt"
"os"
"os/exec"
"strings"
log "github.com/sirupsen/logrus"
"golang.org/x/mod/semver"
)
// VerifyFFMpegPath verifies that the path exists, is a file, and is executable.
func VerifyFFMpegPath(path string) error {
stat, err := os.Stat(path)
if os.IsNotExist(err) {
return errors.New("ffmpeg path does not exist")
}
if err != nil {
return fmt.Errorf("error while verifying the ffmpeg path: %s", err.Error())
}
if stat.IsDir() {
return errors.New("ffmpeg path can not be a folder")
}
mode := stat.Mode()
//source: https://stackoverflow.com/a/60128480
if mode&0111 == 0 {
return errors.New("ffmpeg path is not executable")
}
cmd := exec.Command(path)
out, _ := cmd.CombinedOutput()
response := string(out)
if response == "" {
return fmt.Errorf("unable to determine the version of your ffmpeg installation at %s you may experience issues with video", path)
}
responseComponents := strings.Split(response, " ")
if len(responseComponents) < 3 {
log.Debugf("unable to determine the version of your ffmpeg installation at %s you may experience issues with video", path)
return nil
}
fullVersionString := responseComponents[2]
versionString := "v" + strings.Split(fullVersionString, "-")[0]
// Some builds of ffmpeg have weird build numbers that we can't parse
if !semver.IsValid(versionString) {
log.Debugf("unable to determine if ffmpeg version %s is recent enough. if you experience issues with video you may want to look into updating", fullVersionString)
return nil
}
if semver.Compare(versionString, FfmpegSuggestedVersion) == -1 {
return fmt.Errorf("your %s version of ffmpeg at %s may be older than the suggested version of %s you may experience issues with video", versionString, path, FfmpegSuggestedVersion)
}
return nil
}