#!/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: %s/main could not be read. Exiting.\n" "${FUNCTIONS}">&2 exit 1 fi timestamp_replacementchars='' . "${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" } # shellcheck disable=SC2034 { # used on ngcpcfg-ha/functions/ha_features.execute_check_remote() 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 type -p execute_check_shared_storage &>/dev/null ; then log_debug "execute_check_shared_storage function, action 'push'" execute_check_shared_storage push fi } check_shared_storage() { if type -p execute_check_shared_storage &>/dev/null ; then log_debug "execute_check_shared_storage function, action all" execute_check_shared_storage all fi } check_remote() { if type -p execute_check_remote &>/dev/null ; then log_debug "execute_check_remote function" execute_check_remote fi } check_reboot_requests() { log_debug "check_requested_reboot" log_info "Checking for pending reboot requests:" if [ -f "${RUN_DIR}/reboot-required" ]; then log_info "ACTION_NEEDED: configuration, service or system changes requested a reboot" log_info "-> reboot the system at your earliest convenience" else log_info "OK: no reboot requested" fi } if [ -z "${1:-}" ] ; then check_local_state check_push check_etc_state check_shared_storage "$@" check_reboot_requests fi check_remote "$@" ## END OF FILE #################################################################