2021-12-22 13:18:41 +01:00
|
|
|
#!/bin/bash
|
2022-01-10 16:31:48 +01:00
|
|
|
source lib/functions.sh
|
2021-12-22 13:18:41 +01:00
|
|
|
|
2022-05-11 10:30:18 +02:00
|
|
|
log "INFO" "Checking for updates of services"
|
2022-01-11 14:40:16 +01:00
|
|
|
|
2022-05-11 10:30:18 +02:00
|
|
|
# Check git updates
|
|
|
|
for DIR in /etc/bridgehead $(pwd); do
|
|
|
|
old_git_hash="$(git -C $DIR rev-parse --verify HEAD)"
|
|
|
|
git -C $DIR fetch 2>&1
|
|
|
|
git -C $DIR pull 2>&1
|
2022-05-16 11:02:51 +02:00
|
|
|
git -C $DIR remote -v
|
2022-05-11 10:30:18 +02:00
|
|
|
new_git_hash="$(git -C $DIR rev-parse --verify HEAD)"
|
|
|
|
git_updated="false"
|
|
|
|
if [ "$old_git_hash" != "$new_git_hash" ]; then
|
2022-05-16 11:02:51 +02:00
|
|
|
log "INFO" "Updated git repository in ${DIR} from commit $old_git_hash to $new_git_hash"
|
|
|
|
# NOTE: Link generation doesn't work on repositories placed at an self-hosted instance of bitbucket.
|
|
|
|
# See: https://community.atlassian.com/t5/Bitbucket-questions/BitBucket-4-14-diff-between-any-two-commits/qaq-p/632974
|
|
|
|
if [ "$(git -C $DIR remote get-url origin | grep "github.com")" ]; then
|
|
|
|
log "INFO" "You can review all changes on the repository with https://github.com/samply/bridgehead/compare/$old_git_hash...$new_git_hash"
|
|
|
|
fi
|
2022-05-11 10:30:18 +02:00
|
|
|
git_updated="true"
|
|
|
|
fi
|
|
|
|
done
|
2022-01-11 14:40:16 +01:00
|
|
|
|
2022-05-11 10:30:18 +02:00
|
|
|
# Check docker updates
|
2021-12-22 13:18:41 +01:00
|
|
|
docker_updated="false"
|
2022-05-11 10:30:18 +02:00
|
|
|
for IMAGE in $(docker ps --filter "name=bridgehead" --format {{.Image}}); do
|
|
|
|
log "INFO" "Checking for Updates of Image: $IMAGE"
|
|
|
|
if docker pull $IMAGE | grep "Downloaded newer image"; then
|
|
|
|
log "INFO" "$IMAGE updated."
|
2021-12-22 13:18:41 +01:00
|
|
|
docker_updated="true"
|
|
|
|
fi
|
|
|
|
done
|
2022-05-11 10:30:18 +02:00
|
|
|
|
|
|
|
# If anything is updated, restart service
|
2021-12-22 13:18:41 +01:00
|
|
|
if [ $git_updated = "true" ] || [ $docker_updated = "true" ]; then
|
2022-05-11 10:30:18 +02:00
|
|
|
log "INFO" "Due to previous updates now restarting bridgehead"
|
|
|
|
systemctl restart 'bridgehead@*'
|
2021-12-22 13:18:41 +01:00
|
|
|
fi
|
|
|
|
log "INFO" "checking updates finished"
|
2022-05-16 11:02:51 +02:00
|
|
|
exit 0
|
|
|
|
|
|
|
|
# TODO: Print last commit explicit
|