diff --git a/norg/borg/execute.nim b/norg/borg/execute.nim index 78b8df6..4ba0233 100644 --- a/norg/borg/execute.nim +++ b/norg/borg/execute.nim @@ -5,6 +5,7 @@ import ../model/command_type import ../utils/run export run + proc genCommand*(cmd: string, repo: string, further_args: seq[string]): string = let args = further_args.join(" ") let cmd = fmt"{BORG_BIN} {cmd} {repo} {args}" diff --git a/norg/config/init.nim b/norg/config/init.nim index 5b642ec..9a67411 100644 --- a/norg/config/init.nim +++ b/norg/config/init.nim @@ -1,10 +1,12 @@ import parsetoml import ../model/config_type +import ../model/command_type import ../model/encryption_type import notifier_config import actions_config import maintenance_config + export config_type proc parseSourceDirectories*(in_conf: TomlValueRef): seq[string] = @@ -34,6 +36,16 @@ proc parseEncryption*(enc_conf: TomlValueRef) = setEncryptionPassphraseFile(enc_conf{"encryption_passphrase_file"}.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 = let in_conf = parsetoml.parseFile(file) norg_config.source_directories = parseSourceDirectories(in_conf) @@ -45,6 +57,8 @@ proc parseConfigFile*(file: string): NorgConfig = norg_config.notifiers = parseNotifiers(in_conf) norg_config.actions = parseActions(in_conf{"actions"}) norg_config.maintenance = parseMaintenance(in_conf{"maintenance"}) + norg_config.bins.addConfigBinaries(in_conf{"binaries"}) + norg_config.bins.setBinaryLocations() return norg_config diff --git a/norg/model/binary_type.nim b/norg/model/binary_type.nim new file mode 100644 index 0000000..d92ee26 --- /dev/null +++ b/norg/model/binary_type.nim @@ -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) diff --git a/norg/model/command_type.nim b/norg/model/command_type.nim index 4cb1175..c44feb8 100644 --- a/norg/model/command_type.nim +++ b/norg/model/command_type.nim @@ -1,5 +1,5 @@ -const BORG_BIN* = "borg" -const RESTIC_BIN* = "restic" +import ../model/binary_type +import os type Command* = enum @@ -14,6 +14,14 @@ type CHECK = "check", 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 = for cmd in Command.items: if str == $cmd: return cmd diff --git a/norg/model/config_type.nim b/norg/model/config_type.nim index bee2759..49fbb17 100644 --- a/norg/model/config_type.nim +++ b/norg/model/config_type.nim @@ -2,12 +2,14 @@ import repository_type import notifier_types import actions_type import maintenance_type +import binary_type import ../config/args export repository_type export notifier_types export actions_type export maintenance_type +export binary_type type @@ -20,11 +22,12 @@ type notifiers*: Notifiers actions*: Actions args*: NorgArgs - + bins*: Binaries proc newNorgConfig*(): NorgConfig = var nc = NorgConfig() nc.maintenance = newMaintenance() + nc.bins = newBinaries() return nc var norg_config*: NorgConfig = newNorgConfig() diff --git a/norg/utils/run.nim b/norg/utils/run.nim index ed6bda3..3c0b253 100644 --- a/norg/utils/run.nim +++ b/norg/utils/run.nim @@ -3,7 +3,6 @@ import osproc import ../model/maintenance_type - proc run*(cmd: string): int = echo fmt"Trying to run : {cmd}" try: