From: Bastian Dehn Date: Sun, 16 Aug 2026 13:30:31 +0000 (+0200) Subject: add check exists commands X-Git-Tag: v1.0.7^2~1^2~26 X-Git-Url: https://gitweb.hhaalo.de/?a=commitdiff_plain;h=e32343a8f4110e7e8596a5eb8ba2d582727b6165;p=simple-backup.git add check exists commands --- diff --git a/src/backupmount b/src/backupmount index 9b35334..20f31d4 100755 --- a/src/backupmount +++ b/src/backupmount @@ -1,7 +1,31 @@ #!/bin/bash +errlog() +{ + local lastexit=$? + local msg="$1" + + echo "❌ ERROR: $msg" + return $lastexit +} + +exists_needed_commands() +{ + command -v yq > /dev/null \ + || errlog "command yq not found" \ + || return $? + command -v jq > /dev/null \ + || errlog "command jq not found" \ + || return $? + command -v cryptsetup > /dev/null \ + || errlog "command cryptsetup not found" \ + || return $? +} + main() { + local CONFIG_FILE=${CONFIG_FILE:="config.yaml"} + exists_needed_commands || return $? echo "⭐ START: backupmount" } diff --git a/tests/backupmount_tests.bats b/tests/backupmount_tests.bats index 16f11c7..786aad5 100755 --- a/tests/backupmount_tests.bats +++ b/tests/backupmount_tests.bats @@ -14,8 +14,48 @@ teardown() { unset CONFIG_FILE } +# bats test_tags=backupmount:start @test "success start backupmount" { + exists_needed_commands() { + return 0 + } run main assert_line --index 0 "⭐ START: backupmount" +} + +# bats test_tags=backupmount:start,backupmount:cmd +@test "failure yq command not found" { + command() { + return 1 + } + + run main + + assert_failure + assert_line --index 0 "❌ ERROR: command yq not found" +} + +# bats test_tags=backupmount:start,backupmount:cmd +@test "failure jq command not found" { + command() { + [ "$2" != "jq" ] || return 1 + } + + run main + + assert_failure + assert_line --index 0 "❌ ERROR: command jq not found" +} + +# bats test_tags=backupmount:start,backupmount:cmd +@test "failure cryptsetup command not found" { + command() { + [ "$2" != "cryptsetup" ] || return 1 + } + + run main + + assert_failure + assert_line --index 0 "❌ ERROR: command cryptsetup not found" } \ No newline at end of file