initial
This commit is contained in:
106
config/config.go
Executable file
106
config/config.go
Executable file
@@ -0,0 +1,106 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"local/args"
|
||||
"local/logb"
|
||||
"os"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/ncw/rclone/fs/config"
|
||||
)
|
||||
|
||||
var (
|
||||
refresh = &sync.Mutex{}
|
||||
ArloUser string
|
||||
ArloPass string
|
||||
ArloCapacity int64
|
||||
ArloBPS int64
|
||||
RCloneConfig string
|
||||
RCloneName string
|
||||
MonitorInterval time.Duration
|
||||
DryRun bool
|
||||
ArchiveLength time.Duration
|
||||
)
|
||||
|
||||
func dump() {
|
||||
logb.Infof(`CONFIG:
|
||||
ArloUser %v
|
||||
ArloPass %v
|
||||
ArloCapacity %v
|
||||
ArloBPS %v
|
||||
RCloneConfig %v
|
||||
RCloneName %v
|
||||
MonitorInterval %v
|
||||
DryRun %v
|
||||
ArchiveLength %v
|
||||
`,
|
||||
ArloUser,
|
||||
ArloPass,
|
||||
ArloCapacity,
|
||||
ArloBPS,
|
||||
RCloneConfig,
|
||||
RCloneName,
|
||||
MonitorInterval,
|
||||
DryRun,
|
||||
ArchiveLength,
|
||||
)
|
||||
}
|
||||
|
||||
func init() {
|
||||
if err := Refresh(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
func Refresh() error {
|
||||
defer dump()
|
||||
if strings.Contains(fmt.Sprint(os.Args), "-test") {
|
||||
return nil
|
||||
}
|
||||
refresh.Lock()
|
||||
defer refresh.Unlock()
|
||||
|
||||
configFiles := []string{}
|
||||
as := args.NewArgSet()
|
||||
as.Append(args.STRING, "c", "path to config", "")
|
||||
as.Parse()
|
||||
if c := as.Get("c").GetString(); c != "" {
|
||||
configFiles = []string{c}
|
||||
}
|
||||
|
||||
as = args.NewArgSet(configFiles...)
|
||||
as.Append(args.STRING, "c", "path to config", "")
|
||||
as.Append(args.STRING, "arlouser", "username for arlo.com", "squeaky2x3@gmail.com")
|
||||
as.Append(args.STRING, "arlopass", "password for arlo.com", "LetMe!23In")
|
||||
as.Append(args.STRING, "rcname", "key:prefix/path for rclone", "drive:/projects/arlo/stash")
|
||||
as.Append(args.STRING, "rcconf", "path to rclone config", "./rclone.config")
|
||||
as.Append(args.INT, "arlomb", "arlo MB storage cap before prune", 800)
|
||||
as.Append(args.INT, "arlobps", "arlo BPS for videos", 70*1000)
|
||||
as.Append(args.DURATION, "interval", "interval between remote storage checks", time.Hour)
|
||||
as.Append(args.BOOL, "dry", "dry run reads from remotes only", false)
|
||||
as.Append(args.DURATION, "archive", "duration to retain videos", time.Hour*24*30)
|
||||
if err := as.Parse(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
ArloUser = as.Get("arlouser").GetString()
|
||||
ArloPass = as.Get("arlopass").GetString()
|
||||
ArloCapacity = int64(as.Get("arlomb").GetInt()) * 1024 * 1024
|
||||
ArloBPS = int64(as.Get("arlobps").GetInt())
|
||||
|
||||
RCloneName = as.Get("rcname").GetString()
|
||||
RCloneConfig = as.Get("rcconf").GetString()
|
||||
|
||||
os.Setenv("RCLONE_CONFIG", RCloneConfig)
|
||||
config.ConfigPath = RCloneConfig
|
||||
config.LoadConfig()
|
||||
|
||||
MonitorInterval = as.Get("interval").GetDuration()
|
||||
DryRun = as.Get("dry").GetBool()
|
||||
ArchiveLength = as.Get("archive").GetDuration()
|
||||
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user