Skip to content

Commit ccbeca5

Browse files
committed
fix missing conditional block
1 parent 4c80614 commit ccbeca5

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

tools/utils/cloud-image-downloader.sh

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ LOG_RETENTION_DAYS=30
4040

4141
LOGGER_TAG="cloud-image-downloader"
4242
LOGGER_FACILITY="user"
43+
LOGGER_AVAILABLE=false
4344

4445
log_message() {
4546
local priority=$1
@@ -48,10 +49,12 @@ log_message() {
4849
local timestamp=$(date +'%Y-%m-%d %H:%M:%S')
4950

5051
# Log to file
51-
echo "${timestamp} [${priority}] ${message} | tee ${LOG_FILE}
52+
echo "${timestamp} [${priority}] ${message}" | tee -a "${LOG_FILE}"
5253

5354
# Log to syslog using logger utility
54-
logger -t "${LOGGER_TAG}" -p "${LOGGER_FACILITY}.${priority}" -- "${message}"
55+
if [ "${LOGGER_AVAILABLE}" = true ]; then
56+
logger -t "${LOGGER_TAG}" -p "${LOGGER_FACILITY}.${priority}" -- "${message}"
57+
fi
5558
}
5659

5760
log_info() {
@@ -154,14 +157,14 @@ cleanup_on_exit() {
154157
fi
155158
}
156159

157-
trap cleanup_on_exit EXIT INT TER
160+
trap cleanup_on_exit EXIT INT TERM
158161

159162
#-------------------------------------------------------------------------------
160163
# Main Script Logic
161164
#-------------------------------------------------------------------------------
162165

163-
if ! command -v logger &> /dev/null; then
164-
log_warn "logger utility not found - syslog logging disabled"
166+
if command -v logger &> /dev/null; then
167+
LOGGER_AVAILABLE=true
165168
fi
166169

167170
# Ensure base destination and log directories exist
@@ -176,6 +179,13 @@ log_info "Temporary directory: $TEMP_DIR"
176179
log_info "Base destination directory: $DEST_DIR"
177180
log_info "Log file: $LOG_FILE"
178181

182+
# Inform about logger status
183+
if [ "${LOGGER_AVAILABLE}" = true ]; then
184+
log_info "Syslog logging enabled (tag: ${LOGGER_TAG})"
185+
else
186+
log_warn "Syslog logging disabled - logger utility not found"
187+
fi
188+
179189
# Loop through the image URLs
180190
for filename in "${!IMAGE_URLS[@]}"; do
181191
url="${IMAGE_URLS[$filename]}"

0 commit comments

Comments
 (0)