Update scripts/dccd2.sh
This commit is contained in:
parent
30dc8575a7
commit
79d2f0d5ba
1 changed files with 26 additions and 16 deletions
|
@ -64,13 +64,6 @@ update_compose_files() {
|
||||||
if [ "$local_hash" != "$remote_hash" ]; then
|
if [ "$local_hash" != "$remote_hash" ]; then
|
||||||
log_message "STATE: Hashes don't match, updating..."
|
log_message "STATE: Hashes don't match, updating..."
|
||||||
|
|
||||||
# Pull any changes in the Git repository
|
|
||||||
if ! git pull --quiet origin "$REMOTE_BRANCH"; then
|
|
||||||
log_message "ERROR: Unable to pull changes from the remote repository (the server may be offline or unreachable)"
|
|
||||||
send_notification "Script Error" "Failed to update compose files: Unable to pull changes from the remote repository (the server may be offline or unreachable)"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Get list of changed files
|
# Get list of changed files
|
||||||
changed_files=$(git diff --name-only HEAD@{1} HEAD)
|
changed_files=$(git diff --name-only HEAD@{1} HEAD)
|
||||||
|
|
||||||
|
@ -86,6 +79,21 @@ update_compose_files() {
|
||||||
|
|
||||||
# Check if docker-compose.yml was changed in this directory
|
# Check if docker-compose.yml was changed in this directory
|
||||||
if echo "$changed_files" | grep -q "$folder/docker-compose.yml"; then
|
if echo "$changed_files" | grep -q "$folder/docker-compose.yml"; then
|
||||||
|
# Calculate hash of docker-compose.yml before pull
|
||||||
|
before_pull_hash=$(md5sum "$folder/docker-compose.yml" | awk '{ print $1 }')
|
||||||
|
|
||||||
|
# Pull any changes in the Git repository
|
||||||
|
if ! git pull --quiet origin "$REMOTE_BRANCH"; then
|
||||||
|
log_message "ERROR: Unable to pull changes from the remote repository (the server may be offline or unreachable)"
|
||||||
|
send_notification "Script Error" "Failed to update compose files: Unable to pull changes from the remote repository (the server may be offline or unreachable)"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Calculate hash of docker-compose.yml after pull
|
||||||
|
after_pull_hash=$(md5sum "$folder/docker-compose.yml" | awk '{ print $1 }')
|
||||||
|
|
||||||
|
# Compare hashes to determine if the file was modified
|
||||||
|
if [ "$before_pull_hash" != "$after_pull_hash" ]; then
|
||||||
# Go into the directory
|
# Go into the directory
|
||||||
cd "$folder" || { log_message "ERROR: Failed to enter directory $folder"; send_notification "Script Error" "Failed to update compose files: Failed to enter directory $folder"; continue; }
|
cd "$folder" || { log_message "ERROR: Failed to enter directory $folder"; send_notification "Script Error" "Failed to update compose files: Failed to enter directory $folder"; continue; }
|
||||||
|
|
||||||
|
@ -98,6 +106,7 @@ update_compose_files() {
|
||||||
else
|
else
|
||||||
log_message "INFO: No changes in $folder/docker-compose.yml"
|
log_message "INFO: No changes in $folder/docker-compose.yml"
|
||||||
fi
|
fi
|
||||||
|
fi
|
||||||
done
|
done
|
||||||
else
|
else
|
||||||
log_message "STATE: Hashes match, so nothing to do"
|
log_message "STATE: Hashes match, so nothing to do"
|
||||||
|
@ -112,6 +121,7 @@ update_compose_files() {
|
||||||
log_message "STATE: Done!"
|
log_message "STATE: Done!"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
usage() {
|
usage() {
|
||||||
printf "
|
printf "
|
||||||
Usage: $0 [OPTIONS]
|
Usage: $0 [OPTIONS]
|
||||||
|
|
Reference in a new issue