11#! /usr/bin/env bash
22set -o errexit
33set -o pipefail
4+ set -o nounset
45
56JOB_NAME=${JOB_NAME:- mirrIO}
67RETENTION=${RETENTION:- 30d0h0m}
7- ADDITIONAL_PARAMETERS=${ADDITIONAL_PARAMETERS:- --quiet}
8- MC_BINARY=${MC_BINARY:-/ work/ mc}
9- MC_CONFIG_DIR=${MC_CONFIG_DIR:-/ work/ .mc}
10- mkdir -p " $MC_CONFIG_DIR "
8+ ADDITIONAL_PARAMETERS=${ADDITIONAL_PARAMETERS:- }
119
12- # mc wrapper to use config dir
13- mc () { " $MC_BINARY " --config-dir " $MC_CONFIG_DIR " " $@ " ; }
10+ # Prefer MC_CONFIG_DIR if set, otherwise fall back to $HOME/.mc
11+ MC_CONFIG_DIR=" ${MC_CONFIG_DIR:- ${HOME} / .mc} "
12+ mkdir -p " ${MC_CONFIG_DIR} "
1413
1514pushgateway () {
1615 if [[ -n " ${PUSHGATEWAY_URL:- } " ]]; then
2524
2625check_env () {
2726 for var in " $@ " ; do
28- if [[ -z " ${! var} " ]]; then
27+ if [[ -z " ${! var:- } " ]]; then
2928 echo " ${var} is not set!"
3029 exit 1
3130 fi
@@ -47,12 +46,15 @@ check_env \
4746 SOURCE_BUCKET \
4847 DESTINATION_BUCKET
4948
49+ # If anything errors after here, mark failure + exit
5050trap ' notify; exit 1' ERR
51+ trap ' notify; exit 1' SIGINT SIGTERM
5152
5253# Split extra parameters into an array so multiple flags work
5354# shellcheck disable=SC2206
5455read -r -a MC_MIRROR_ARGS <<< " ${ADDITIONAL_PARAMETERS}"
5556
57+ # Use env-based config dir (MC_CONFIG_DIR) — no wrapper / flag needed
5658mc alias set source " ${SOURCE_URL} " " ${SOURCE_ACCESSKEY} " " ${SOURCE_SECRETKEY} " --api S3v4
5759mc alias set destination " ${DESTINATION_URL} " " ${DESTINATION_ACCESSKEY} " " ${DESTINATION_SECRETKEY} " --api S3v4
5860
0 commit comments