diff --git a/src/lib/handlers/targets/s3cmd.sh b/src/lib/handlers/targets/s3cmd.sh index 097a865..deb203d 100644 --- a/src/lib/handlers/targets/s3cmd.sh +++ b/src/lib/handlers/targets/s3cmd.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -# s3cmd.sh - upload files to S3 compatible object storage. +# s3cmd.sh - upload files to S3 compatible object storage via s3cmd. # Copyright (c) 2022 ge # # This program is free software: you can redistribute it and/or modify @@ -41,17 +41,12 @@ tgt_s3cmd() { s3cmd_options="${s3cmd_options:---preserve --quiet --no-progress}" # Set s3cmd comand. See s3cmd(1) - if [ -n "$s3cmd_config" ]; then - # Use configuration file - # shellcheck disable=SC2154,SC2086 - set -- s3cmd $s3cmd_options --config "$s3cmd_config" \ - put "${backups[@]}" "$uri" - elif [ -n "$s3_access_key" ] && \ - [ -n "$s3_secret_key" ] && \ - [ -n "$s3_host" ] && \ - [ -n "$s3_host_bucket" ] + if [ -n "$s3_access_key" ] && \ + [ -n "$s3_secret_key" ] && \ + [ -n "$s3_host" ] && \ + [ -n "$s3_host_bucket" ] then - s3_region="${s3_region:-na}" # fallback to 'no available' region + s3_region="${s3_region:-na}" # fallback to 'not available' region # Use parameters provided from backup script # shellcheck disable=SC2154,SC2086 set -- s3cmd $s3cmd_options \ @@ -62,10 +57,11 @@ tgt_s3cmd() { --host-bucket="$s3_host_bucket" \ put "${backups[@]}" "$uri" else - # Exit if no configuration - log -p "Error: Bad s3cmd credentials."\ - "See boring-backup(1) for details" >&2 - exit 1 + # Use configuration file + s3cmd_config="${s3cmd_comfig:-$HOME/.s3cfg}" + # shellcheck disable=SC2154,SC2086 + set -- s3cmd $s3cmd_options --config "$s3cmd_config" \ + put "${backups[@]}" "$uri" fi echo "Run command: $*" | @@ -74,7 +70,7 @@ tgt_s3cmd() { # Upload backups # shellcheck disable=SC2154 - if "$@" 2>> "$__log_file"; then + if "$@" 2>> "$log_file"; then : # Success else handle_error \