You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ngcpcfg/scripts/status

125 lines
3.3 KiB

#!/bin/bash
# Purpose: display state of ngcpcfg setup and pending/recommended actions
################################################################################
set -e
set -u
set -o pipefail
# support testsuite
FUNCTIONS="${FUNCTIONS:-/usr/share/ngcp-ngcpcfg/functions/}"
if ! [ -r ${FUNCTIONS}/main ] ; then
printf "Error: ${FUNCTIONS}/main could not be read. Exiting.\n" >&2
exit 1
fi
. ${FUNCTIONS}/main
# main script
if ! [ -d "${NGCPCTL_MAIN:-}" ] ; then
log_error "Directory ${NGCPCTL_MAIN:-} does not exist yet. Execute 'ngcpcfg initialise'."
exit 1
fi
usage() {
printf "ngcpcfg status -- supported command line options:
--local-only - do not check state on any remote host(s) (HA/PRO only)\n\n"
}
CHECK_REMOTE=true
REMOTE_INVOKED=false
while [ -n "${1:-}" ] ; do
case "$1" in
*--local-only*) CHECK_REMOTE=false ; shift ;;
*--remote*) REMOTE_INVOKED=true ; shift ;; # used when invoking ngcpcfg status remotely
*--help*) usage ; exit 0 ;;
*) break ;;
esac
done
check_local_state() {
log_debug "check_local_state"
log_debug "cd $NGCPCTL_MAIN"
cd "$NGCPCTL_MAIN"
log_info "Checking state of ngcpcfg:"
if ! [ -r /etc/ngcp-config/.git/HEAD ] ; then
log_warn "ngcpcfg has not been initialised yet. Execute 'ngcpcfg initialise'."
exit 0
fi
log_info "OK: has been initialised already"
log_info "Checking state of configuration files:"
log_debug "git status | grep -q 'working directory clean'"
if git status | grep -q 'working directory clean' ; then
log_info "OK: nothing to commit"
else
if git diff-index --name-only HEAD | grep -q . ; then
log_info "ACTION_NEEDED: configuration files have been modified:"
log_debug "git diff-index --name-only HEAD | sed \"s;^;${NGCPCTL_MAIN}/;\""
git diff-index --name-only HEAD | sed "s;^;${NGCPCTL_MAIN}/;" | sed "s/^/$timestamp_replacementchars/"
fi
if git ls-files --other --exclude-standard | grep -q . ; then
log_info "ACTION_NEEDED: configuration files have been added:"
log_debug "git ls-files --other --exclude-standard | sed \"s;^;${NGCPCTL_MAIN}/;\""
git ls-files --other --exclude-standard | sed "s;^;${NGCPCTL_MAIN}/;" | sed "s/^/$timestamp_replacementchars/"
fi
log_info "-> execute 'ngcpcfg build' and 'ngcpcfg commit'"
fi
}
check_etc_state() {
log_debug "check_etc_state"
log_debug "cd /etc"
cd /etc
log_info "Checking state of /etc files:"
log_debug "git status | grep -q 'working directory clean'"
if git status | grep -q 'working directory clean' ; then
log_info "OK: nothing to commit"
else
log_info "ACTION_NEEDED: configuration files changed (execute 'etckeeper commit [message]')"
fi
}
check_push() {
if which execute_check_push &>/dev/null ; then
log_debug "execute_check_push function"
execute_check_push
fi
}
check_shared_storage() {
if which execute_check_shared_storage &>/dev/null ; then
log_debug "execute_check_shared_storage function"
execute_check_shared_storage
fi
}
check_remote() {
if which execute_check_remote &>/dev/null ; then
log_debug "execute_check_remote function"
execute_check_remote
fi
}
if [ -z "${1:-}" ] ; then
check_local_state
check_push
check_etc_state
check_shared_storage "$@"
fi
check_remote "$@"
## END OF FILE #################################################################