diff --git a/norg/config/init.nim b/norg/config/init.nim index b310b7d..57192fc 100644 --- a/norg/config/init.nim +++ b/norg/config/init.nim @@ -16,10 +16,6 @@ proc parseSourceDirectories*(in_conf: TomlValueRef): seq[string] = norg_config.source_directories.add(dir.getStr()) return src_dirs -proc parseEncryption*(enc_conf: TomlValueRef) = - setEncryptionPassphrase(enc_conf{"encryption_passphrase"}.getStr("")) - setEncryptionPassphraseFD(enc_conf{"encryption_passphrase_fd"}.getStr("")) - setEncryptionPassCommand(enc_conf{"encryption_passcommand"}.getStr("")) proc parseRepositories*(rep_conf: TomlValueRef): seq[Repository] = var repos: seq[Repository] = @[] @@ -28,15 +24,25 @@ proc parseRepositories*(rep_conf: TomlValueRef): seq[Repository] = var repo = Repository() repo.path = rtable["path"].getStr() repo.label = rtable["label"].getStr() + if rtable.hasKey("tool"): + repo.tool = rtable["tool"].getStr("borg").toBackupTool() repos.add(repo) + echo repos return repos +proc parseEncryption*(enc_conf: TomlValueRef) = + setEncryptionPassphrase(enc_conf{"encryption_passphrase"}.getStr("")) + setEncryptionPassphraseFD(enc_conf{"encryption_passphrase_fd"}.getStr("")) + setEncryptionPassphraseFile(enc_conf{"encryption_passphrase_file"}.getStr("")) + setEncryptionPassCommand(enc_conf{"encryption_passcommand"}.getStr("")) + + proc parseConfigFile*(file: string): NorgConfig = norg_config = newNorgConfig() let in_conf = parsetoml.parseFile(file) norg_config.source_directories = parseSourceDirectories(in_conf) - parseEncryption(in_conf{"encryption"}) norg_config.repositories = parseRepositories(in_conf{"repositories"}) + parseEncryption(in_conf{"encryption"}) norg_config.notifiers = parseNotifiers(in_conf) norg_config.actions = parseActions(in_conf{"actions"}) norg_config.maintenance = parseMaintenance(in_conf{"maintenance"}) diff --git a/norg/model/encryption_type.nim b/norg/model/encryption_type.nim index 09381e6..59c7aa1 100644 --- a/norg/model/encryption_type.nim +++ b/norg/model/encryption_type.nim @@ -3,16 +3,25 @@ import os proc setEncryptionPassphrase*(pw: string) = if pw != "": putEnv("BORG_PASSPHRASE", pw) + putEnv("RESTIC_PASSWORD", pw) proc setEncryptionPassphraseFD*(pw: string) = if pw != "": putEnv("BORG_PASSPHRASE_FD", pw) +proc setEncryptionPassphraseFile*(pw: string) = + if pw != "": + putEnv("RESTIC_PASSWORD_FILE", pw) + proc setEncryptionPassCommand*(pw: string) = if pw != "": putEnv("BORG_PASSCOMMAND", pw) + putEnv("RESTIC_PASSWORD_COMMAND", pw) proc delEncryptionPassphraseInfo*() = delEnv("BORG_PASSPHRASE") delEnv("BORG_PASSPHRASE_FD") delEnv("BORG_PASSCOMMAND") + delEnv("RESTIC_PASSWORD") + delEnv("RESTIC_PASSWORD_FILE") + delEnv("RESTIC_PASSWORD_COMMAND") diff --git a/norg/model/tool_type.nim b/norg/model/tool_type.nim index 7604a12..70be64d 100644 --- a/norg/model/tool_type.nim +++ b/norg/model/tool_type.nim @@ -5,5 +5,6 @@ type RESTIC = "restic" proc toBackupTool*(str: string): BackupTool = - for cmd in BackupTool.items: - if str == $cmd: return cmd + for tool in BackupTool.items: + if str == $tool: return tool + return BORG diff --git a/norg/restic/backup.nim b/norg/restic/backup.nim new file mode 100644 index 0000000..359731f --- /dev/null +++ b/norg/restic/backup.nim @@ -0,0 +1,6 @@ +import ../model/config_type + +proc createBackup*(nc: NorgConfig, repo: Repository): int = + echo "Not Yet Implemented" + discard + diff --git a/norg/restic/extract.nim b/norg/restic/extract.nim new file mode 100644 index 0000000..4264ac8 --- /dev/null +++ b/norg/restic/extract.nim @@ -0,0 +1,5 @@ +import ../model/config_type + +proc extractArchive*(nc: NorgConfig, repo: Repository): int = + echo "Not Yet Implemented" + discard diff --git a/norg/restic/init.nim b/norg/restic/init.nim new file mode 100644 index 0000000..47b09d2 --- /dev/null +++ b/norg/restic/init.nim @@ -0,0 +1,6 @@ +import ../model/config_type + +proc initRepo*(nc: NorgConfig, repo: Repository): int = + echo "Not Yet Implemented" + discard + diff --git a/norg/restic/list.nim b/norg/restic/list.nim new file mode 100644 index 0000000..fa9e89b --- /dev/null +++ b/norg/restic/list.nim @@ -0,0 +1,7 @@ +import ../model/config_type + +proc listArchives*(nc: NorgConfig, repo: Repository): int = + echo "Not Yet Implemented" + discard + + diff --git a/norg/restic/mount.nim b/norg/restic/mount.nim new file mode 100644 index 0000000..2398781 --- /dev/null +++ b/norg/restic/mount.nim @@ -0,0 +1,10 @@ +import ../model/config_type + +proc mountArchive*(nc: NorgConfig, repo: Repository): int = + echo "Not Yet Implemented" + discard + +proc unmountArchive*(nc: NorgConfig): int = + echo "Not Yet Implemented" + discard + diff --git a/norg/restic/restic.nim b/norg/restic/restic.nim index 4a6c7b2..617ea24 100644 --- a/norg/restic/restic.nim +++ b/norg/restic/restic.nim @@ -1,29 +1,11 @@ import ../model/config_type import ../utils/actions -proc initRepo*(nc: NorgConfig, repo: Repository): int = - echo "Not Yet Implemented" - discard - -proc createBackup*(nc: NorgConfig, repo: Repository): int = - echo "Not Yet Implemented" - discard - -proc listArchives*(nc: NorgConfig, repo: Repository): int = - echo "Not Yet Implemented" - discard - -proc mountArchive*(nc: NorgConfig, repo: Repository): int = - echo "Not Yet Implemented" - discard - -proc unmountArchive*(nc: NorgConfig): int = - echo "Not Yet Implemented" - discard - -proc extractArchive*(nc: NorgConfig, repo: Repository): int = - echo "Not Yet Implemented" - discard +import init +import backup +import list +import mount +import extract proc execute*(nc: NorgConfig, repo: Repository) = case nc.args.command