added ability to set binary locations for restic or borg

This commit is contained in:
Paul Wilde 2024-08-24 22:32:10 +01:00
parent a57127fcff
commit e5ad7ed1d4
6 changed files with 40 additions and 4 deletions

View file

@ -5,6 +5,7 @@ import ../model/command_type
import ../utils/run import ../utils/run
export run export run
proc genCommand*(cmd: string, repo: string, further_args: seq[string]): string = proc genCommand*(cmd: string, repo: string, further_args: seq[string]): string =
let args = further_args.join(" ") let args = further_args.join(" ")
let cmd = fmt"{BORG_BIN} {cmd} {repo} {args}" let cmd = fmt"{BORG_BIN} {cmd} {repo} {args}"

View file

@ -1,10 +1,12 @@
import parsetoml import parsetoml
import ../model/config_type import ../model/config_type
import ../model/command_type
import ../model/encryption_type import ../model/encryption_type
import notifier_config import notifier_config
import actions_config import actions_config
import maintenance_config import maintenance_config
export config_type export config_type
proc parseSourceDirectories*(in_conf: TomlValueRef): seq[string] = proc parseSourceDirectories*(in_conf: TomlValueRef): seq[string] =
@ -34,6 +36,16 @@ proc parseEncryption*(enc_conf: TomlValueRef) =
setEncryptionPassphraseFile(enc_conf{"encryption_passphrase_file"}.getStr("")) setEncryptionPassphraseFile(enc_conf{"encryption_passphrase_file"}.getStr(""))
setEncryptionPassCommand(enc_conf{"encryption_passcommand"}.getStr("")) setEncryptionPassCommand(enc_conf{"encryption_passcommand"}.getStr(""))
proc addConfigBinaries*(current: var Binaries, bin_conf: TomlValueRef) =
let
borg = bin_conf{"borg_bin"}.getStr()
restic = bin_conf{"restic_bin"}.getStr()
if borg != "":
current.borg.insert(borg,0)
if restic != "":
current.restic.insert(restic,0)
proc parseConfigFile*(file: string): NorgConfig = proc parseConfigFile*(file: string): NorgConfig =
let in_conf = parsetoml.parseFile(file) let in_conf = parsetoml.parseFile(file)
norg_config.source_directories = parseSourceDirectories(in_conf) norg_config.source_directories = parseSourceDirectories(in_conf)
@ -45,6 +57,8 @@ proc parseConfigFile*(file: string): NorgConfig =
norg_config.notifiers = parseNotifiers(in_conf) norg_config.notifiers = parseNotifiers(in_conf)
norg_config.actions = parseActions(in_conf{"actions"}) norg_config.actions = parseActions(in_conf{"actions"})
norg_config.maintenance = parseMaintenance(in_conf{"maintenance"}) norg_config.maintenance = parseMaintenance(in_conf{"maintenance"})
norg_config.bins.addConfigBinaries(in_conf{"binaries"})
norg_config.bins.setBinaryLocations()
return norg_config return norg_config

View file

@ -0,0 +1,11 @@
type
Binaries* = object
borg*: seq[string]
restic*: seq[string]
proc newBinaries*(): Binaries =
var
borgs: seq[string] = @["borg","/usr/local/bin/borg","/usr/bin/borg","borg.exe"]
restics: seq[string] = @["restic","/usr/local/bin/restic","/usr/bin/restic","restic.exe"]
return Binaries(borg: borgs, restic: restics)

View file

@ -1,5 +1,5 @@
const BORG_BIN* = "borg" import ../model/binary_type
const RESTIC_BIN* = "restic" import os
type type
Command* = enum Command* = enum
@ -14,6 +14,14 @@ type
CHECK = "check", CHECK = "check",
COMPACT = "compact" COMPACT = "compact"
var BORG_BIN* = "borg"
var RESTIC_BIN* = "restic"
proc setBinaryLocations*(b: Binaries) =
for borg in b.borg:
if fileExists(borg): BORG_BIN = borg
for restic in b.restic:
if fileExists(restic): RESTIC_BIN = restic
proc toCommand*(str: string): Command = proc toCommand*(str: string): Command =
for cmd in Command.items: for cmd in Command.items:
if str == $cmd: return cmd if str == $cmd: return cmd

View file

@ -2,12 +2,14 @@ import repository_type
import notifier_types import notifier_types
import actions_type import actions_type
import maintenance_type import maintenance_type
import binary_type
import ../config/args import ../config/args
export repository_type export repository_type
export notifier_types export notifier_types
export actions_type export actions_type
export maintenance_type export maintenance_type
export binary_type
type type
@ -20,11 +22,12 @@ type
notifiers*: Notifiers notifiers*: Notifiers
actions*: Actions actions*: Actions
args*: NorgArgs args*: NorgArgs
bins*: Binaries
proc newNorgConfig*(): NorgConfig = proc newNorgConfig*(): NorgConfig =
var nc = NorgConfig() var nc = NorgConfig()
nc.maintenance = newMaintenance() nc.maintenance = newMaintenance()
nc.bins = newBinaries()
return nc return nc
var norg_config*: NorgConfig = newNorgConfig() var norg_config*: NorgConfig = newNorgConfig()

View file

@ -3,7 +3,6 @@ import osproc
import ../model/maintenance_type import ../model/maintenance_type
proc run*(cmd: string): int = proc run*(cmd: string): int =
echo fmt"Trying to run : {cmd}" echo fmt"Trying to run : {cmd}"
try: try: