2023-01-13 19:23:36 +01:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os/user"
|
2023-01-14 12:11:10 +01:00
|
|
|
"runtime"
|
2023-01-13 19:23:36 +01:00
|
|
|
"strconv"
|
|
|
|
|
|
|
|
"git.milar.in/milarin/envvars/v2"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
DownloadPath = envvars.String("DOWNLOAD_PATH", "")
|
|
|
|
|
2023-01-14 12:11:10 +01:00
|
|
|
ThreadCount = envvars.Int("THREADS", runtime.NumCPU())
|
|
|
|
|
2023-01-15 15:55:47 +01:00
|
|
|
DeleteLowPriorityFiles = envvars.Bool("DELETE_LOW_PRIORITY_FILES", false)
|
|
|
|
|
2023-01-13 19:23:36 +01:00
|
|
|
Uid = envvars.Object("UID", 1000, func(s string) (int, error) {
|
|
|
|
if uid, err := strconv.Atoi(s); err == nil {
|
|
|
|
return uid, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
usr, err := user.Lookup(s)
|
|
|
|
if err != nil {
|
|
|
|
return 0, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return strconv.Atoi(usr.Uid)
|
|
|
|
})
|
|
|
|
|
|
|
|
Gid = envvars.Object("GID", 1000, func(s string) (int, error) {
|
|
|
|
if gid, err := strconv.Atoi(s); err == nil {
|
|
|
|
return gid, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
grp, err := user.LookupGroup(s)
|
|
|
|
if err != nil {
|
|
|
|
return 0, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return strconv.Atoi(grp.Gid)
|
|
|
|
})
|
|
|
|
)
|