Merge pull request #13 from samply/feature/addedGitDiffForGitlab
Ensured Logging through the Log Function
This commit is contained in:
commit
4c9a5fc02f
|
@ -1,12 +1,10 @@
|
||||||
#!/bin/bash -e
|
#!/bin/bash -e
|
||||||
source lib/functions.sh
|
source lib/functions.sh
|
||||||
|
|
||||||
log "This script add's a user with password to the bridghead"
|
log "INFO" "This script add's a user with password to the bridghead"
|
||||||
|
|
||||||
read -p 'Username: ' bc_user
|
read -p 'Username: ' bc_user
|
||||||
read -sp 'Password: ' bc_password
|
read -sp 'Password: ' bc_password
|
||||||
|
|
||||||
echo
|
log "INFO" "\nPlease export the line in the your environment. Please replace the dollar signs with with \\\$"
|
||||||
|
|
||||||
log "Please export the line in the your environment. Please replace the dollar signs with with \\\$"
|
|
||||||
docker run --rm -it httpd:latest htpasswd -nb $bc_user $bc_password
|
docker run --rm -it httpd:latest htpasswd -nb $bc_user $bc_password
|
||||||
|
|
|
@ -2,13 +2,13 @@
|
||||||
|
|
||||||
exitIfNotRoot() {
|
exitIfNotRoot() {
|
||||||
if [ "$EUID" -ne 0 ]; then
|
if [ "$EUID" -ne 0 ]; then
|
||||||
echo "Please run as root"
|
log "ERROR" "Please run as root"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
log() {
|
log() {
|
||||||
echo "$(date +'%Y-%m-%d %T')" "$1:" "$2"
|
echo -e "$(date +'%Y-%m-%d %T')" "$1:" "$2"
|
||||||
}
|
}
|
||||||
|
|
||||||
printUsage() {
|
printUsage() {
|
||||||
|
@ -18,7 +18,7 @@ printUsage() {
|
||||||
|
|
||||||
checkRequirements() {
|
checkRequirements() {
|
||||||
if ! lib/prerequisites.sh; then
|
if ! lib/prerequisites.sh; then
|
||||||
log ERROR "Validating Prerequisites failed, please fix the error(s) above this line."
|
log "ERROR" "Validating Prerequisites failed, please fix the error(s) above this line."
|
||||||
exit 1
|
exit 1
|
||||||
else
|
else
|
||||||
return 0
|
return 0
|
||||||
|
@ -38,12 +38,12 @@ fetchVarsFromVault() {
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
log INFO "Fetching secrets from vault ..."
|
log "INFO" "Fetching secrets from vault ..."
|
||||||
|
|
||||||
[ -e /etc/bridgehead/vault.conf ] && source /etc/bridgehead/vault.conf
|
[ -e /etc/bridgehead/vault.conf ] && source /etc/bridgehead/vault.conf
|
||||||
|
|
||||||
if [ -z "$BW_MASTERPASS" ] || [ -z "$BW_CLIENTID" ] || [ -z "$BW_CLIENTSECRET" ]; then
|
if [ -z "$BW_MASTERPASS" ] || [ -z "$BW_CLIENTID" ] || [ -z "$BW_CLIENTSECRET" ]; then
|
||||||
log ERROR "Please supply correct credentials in /etc/bridgehead/vault.conf."
|
log "ERROR" "Please supply correct credentials in /etc/bridgehead/vault.conf."
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
|
@ -3,12 +3,12 @@
|
||||||
source lib/functions.sh
|
source lib/functions.sh
|
||||||
|
|
||||||
if [ $# -eq 0 ]; then
|
if [ $# -eq 0 ]; then
|
||||||
log "Please provide a Project as argument"
|
log "ERROR" "Please provide a Project as argument"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ $1 != "ccp" ] && [ $1 != "nngm" ] && [ $1 != "gbn" ]; then
|
if [ $1 != "ccp" ] && [ $1 != "nngm" ] && [ $1 != "gbn" ]; then
|
||||||
log "Please provide a supported project like ccp, gbn or nngm"
|
log "ERROR" "Please provide a supported project like ccp, gbn or nngm"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -16,8 +16,10 @@ export PROJECT=$1
|
||||||
|
|
||||||
#checkRequirements // not needed when uninstalling
|
#checkRequirements // not needed when uninstalling
|
||||||
|
|
||||||
log "Stopping systemd services and removing bridgehead ..."
|
log "INFO" "Stopping system units and removing bridgehead for ${PROJECT} ..."
|
||||||
|
|
||||||
systemctl disable --now bridgehead@${PROJECT}.service bridgehead-update@${PROJECT}.timer bridgehead-update@${PROJECT}.service
|
systemctl disable --now bridgehead@${PROJECT}.service bridgehead-update@${PROJECT}.timer bridgehead-update@${PROJECT}.service
|
||||||
|
|
||||||
rm -v /etc/systemd/system/{bridgehead\@.service,bridgehead-update\@.timer,bridgehead-update\@.service}
|
rm -v /etc/systemd/system/{bridgehead\@.service,bridgehead-update\@.timer,bridgehead-update\@.service}
|
||||||
|
|
||||||
|
log "INFO" "Successfully removed bridgehead for ${PROJECT} from your system"
|
||||||
|
|
|
@ -5,12 +5,12 @@ source lib/functions.sh
|
||||||
exitIfNotRoot
|
exitIfNotRoot
|
||||||
|
|
||||||
if [ $# -eq 0 ]; then
|
if [ $# -eq 0 ]; then
|
||||||
log "Please provide a Project as argument"
|
log "ERROR" "Please provide a Project as argument"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ $1 != "ccp" ] && [ $1 != "nngm" ] && [ $1 != "gbn" ]; then
|
if [ $1 != "ccp" ] && [ $1 != "nngm" ] && [ $1 != "gbn" ]; then
|
||||||
log "Please provide a supported project like ccp, gbn or nngm"
|
log "ERROR" "Please provide a supported project like ccp, gbn or nngm"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@ export PROJECT=$1
|
||||||
|
|
||||||
checkRequirements
|
checkRequirements
|
||||||
|
|
||||||
echo -e "\nInstalling systemd units ..."
|
log "INFO" "Register system units for bridgehead and bridgehead-update"
|
||||||
cp -v \
|
cp -v \
|
||||||
lib/systemd/bridgehead\@.service \
|
lib/systemd/bridgehead\@.service \
|
||||||
lib/systemd/bridgehead-update\@.service \
|
lib/systemd/bridgehead-update\@.service \
|
||||||
|
@ -27,13 +27,11 @@ cp -v \
|
||||||
|
|
||||||
systemctl daemon-reload
|
systemctl daemon-reload
|
||||||
|
|
||||||
echo
|
|
||||||
|
|
||||||
if ! systemctl is-active --quiet bridgehead@"${PROJECT}"; then
|
if ! systemctl is-active --quiet bridgehead@"${PROJECT}"; then
|
||||||
log "Enabling autostart of bridgehead@${PROJECT}.service"
|
log "INFO" "Enabling autostart of bridgehead@${PROJECT}.service"
|
||||||
systemctl enable bridgehead@"${PROJECT}"
|
systemctl enable bridgehead@"${PROJECT}"
|
||||||
log "Enabling nightly updates for bridgehead@${PROJECT}.service ..."
|
log "INFO" "Enabling nightly updates for bridgehead@${PROJECT}.service ..."
|
||||||
systemctl enable --now bridgehead-update@"${PROJECT}".timer
|
systemctl enable --now bridgehead-update@"${PROJECT}".timer
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo -e "\nDone - now start your bridgehead by running\n\tsystemctl start bridgehead@${PROJECT}.service\nor by rebooting your machine."
|
log "INFO" "\nDone - now start your bridgehead by running\n\tsystemctl start bridgehead@${PROJECT}.service\nor by rebooting your machine."
|
||||||
|
|
|
@ -8,15 +8,22 @@ for DIR in /etc/bridgehead $(pwd); do
|
||||||
old_git_hash="$(git -C $DIR rev-parse --verify HEAD)"
|
old_git_hash="$(git -C $DIR rev-parse --verify HEAD)"
|
||||||
git -C $DIR fetch 2>&1
|
git -C $DIR fetch 2>&1
|
||||||
git -C $DIR pull 2>&1
|
git -C $DIR pull 2>&1
|
||||||
git -C $DIR remote -v
|
|
||||||
new_git_hash="$(git -C $DIR rev-parse --verify HEAD)"
|
new_git_hash="$(git -C $DIR rev-parse --verify HEAD)"
|
||||||
git_updated="false"
|
git_updated="false"
|
||||||
if [ "$old_git_hash" != "$new_git_hash" ]; then
|
if [ "$old_git_hash" != "$new_git_hash" ]; then
|
||||||
log "INFO" "Updated git repository in ${DIR} from commit $old_git_hash to $new_git_hash"
|
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.
|
# 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
|
# 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
|
git_repository_url="$(git -C $DIR remote get-url origin)"
|
||||||
log "INFO" "You can review all changes on the repository with https://github.com/samply/bridgehead/compare/$old_git_hash...$new_git_hash"
|
git_repository_url=${git_repository_url/.git/}
|
||||||
|
if [ "$( echo $git_repository_url | grep "github.com")" ]; then
|
||||||
|
# Ensure web link even if ssh is used
|
||||||
|
git_repository_url="${git_repository_url/git@github.com/https:\/\/github.com\/}"
|
||||||
|
log "INFO" "You can review all changes on the repository with $git_repository_url/compare/$old_git_hash...$new_git_hash"
|
||||||
|
elif [ "$( echo $git_repository_url | grep "git.verbis.dkfz.de")" ]; then
|
||||||
|
git_repository_url="${git_repository_url/ssh:\/\/git@git.verbis.dkfz.de/https:\/\/git.verbis.dkfz.de\/}"
|
||||||
|
git_repository_url="https://$(echo $git_repository_url | awk -F '@' '{print $2}')"
|
||||||
|
log "INFO" "You can review all changes on the repository with $git_repository_url/compare?from=$old_git_hash&to=$new_git_hash"
|
||||||
fi
|
fi
|
||||||
git_updated="true"
|
git_updated="true"
|
||||||
fi
|
fi
|
||||||
|
|
Loading…
Reference in New Issue