MT#15943 Prompt for commit message during 'ngcpcfg apply' on outstanding changes

Provide "apply" action as separate script.

We don't care about changes related to etckeeper, but just
about outstanding commits in /etc/ngcp-config.

Change-Id: I47411f00a5085d65cacf9e24fc8a468258d57c31
changes/50/3050/2
Michael Prokop 11 years ago
parent 550067a6a8
commit 24aa4a97fa

@ -12,6 +12,7 @@ lib/* usr/lib/ngcp-ngcpcfg/
sbin/ngcp-network usr/sbin/ sbin/ngcp-network usr/sbin/
sbin/ngcp-sync-constants usr/sbin/ sbin/ngcp-sync-constants usr/sbin/
sbin/ngcpcfg usr/sbin/ sbin/ngcpcfg usr/sbin/
scripts/apply usr/share/ngcp-ngcpcfg/scripts/
scripts/build usr/share/ngcp-ngcpcfg/scripts/ scripts/build usr/share/ngcp-ngcpcfg/scripts/
scripts/check usr/share/ngcp-ngcpcfg/scripts/ scripts/check usr/share/ngcp-ngcpcfg/scripts/
scripts/commit usr/share/ngcp-ngcpcfg/scripts/ scripts/commit usr/share/ngcp-ngcpcfg/scripts/

@ -21,8 +21,8 @@ tl;dr? - ngcpcfg for the impatient
---------------------------------- ----------------------------------
The main system configuration is done in the file _/etc/ngcp-config/config.yml_. The main system configuration is done in the file _/etc/ngcp-config/config.yml_.
After modifying the file execute 'ngcpcfg apply' to build the accordingly After modifying the file execute 'ngcpcfg apply "<summary of changes>"' to build
configurations file. the according configuration files.
Taxonomy Taxonomy
-------- --------
@ -203,11 +203,14 @@ Display ngcpcfg version and exit.
Actions Actions
------- -------
**apply**:: **apply** [<commit_message>]::
Executes the _check_, _build_, _services_ and _commit_ commands in a batch Executes the _check_, _build_, _services_ and _commit_ commands in a batch
(assuming each command worked as expected). This option serves as a shortcut for (assuming each command worked as expected). This option serves as a shortcut for
the most commonly executed commands. the most commonly executed commands. If there are any outstanding changes that
need to be committed, then the commit message needs to be provided. This is
meant so the configuration change history (accessible e.g. via 'ngcpcfg log')
provides useful information.
**check** [<config_files_or_directories>|<pattern>]:: **check** [<config_files_or_directories>|<pattern>]::

@ -98,6 +98,11 @@ show() {
"${SCRIPTS}"/show $* "${SCRIPTS}"/show $*
} }
apply() {
log_debug "${SCRIPTS}/apply $*"
"${SCRIPTS}"/apply $*
}
usage() { usage() {
# make sure to output errors on stderr # make sure to output errors on stderr
[ "${1:-}" = "1" ] && exec >&2 [ "${1:-}" = "1" ] && exec >&2
@ -156,7 +161,7 @@ case ${1:-} in
pull) shift ; pull "$*" ;; pull) shift ; pull "$*" ;;
services) shift ; services "$*" ;; services) shift ; services "$*" ;;
status) shift ; status "$*" ;; status) shift ; status "$*" ;;
apply) shift ; check && build && services && commit "$*" && etckeeper ;; apply) shift ; apply "$*" ;;
encrypt) shift ; encrypt "$*" ;; encrypt) shift ; encrypt "$*" ;;
decrypt) shift ; decrypt "$*" ;; decrypt) shift ; decrypt "$*" ;;
diff) shift ; diff "$*" ;; diff) shift ; diff "$*" ;;

@ -0,0 +1,43 @@
#!/bin/bash
# Purpose: shortcut for check, build, services, commit + etckeeper in one run
################################################################################
set -e
set -u
set -o pipefail
# support testsuite
FUNCTIONS="${FUNCTIONS:-/usr/share/ngcp-ngcpcfg/functions/}"
HELPER="${HELPER:-/usr/share/ngcp-ngcpcfg/helper/}"
SCRIPTS="${SCRIPTS:-/usr/share/ngcp-ngcpcfg/scripts/}"
if ! [ -r "${FUNCTIONS}"/main ] ; then
printf "Error: %s/main could not be read. Exiting.\n" "${FUNCTIONS}">&2
exit 1
fi
timestamp_replacementchars=''
. "${FUNCTIONS}"/main
# based on check_local_state() from scripts/status
check_for_outstanding_commits() {
log_debug "cd $NGCPCTL_MAIN"
cd "$NGCPCTL_MAIN"
log_debug "git status | grep -q 'working directory clean'"
if git status | grep -q 'working directory clean' ; then
return 1 # nothing to commit
else
return 0 # outstanding commits
fi
}
if check_for_outstanding_commits && [ -z "${1:-}" ] ; then
log_error "Uncommitted configuration files found."
log_info "Please provide commit message, like: $PN apply 'summary of your changes'"
exit 1
fi
"${SCRIPTS}"/check && "${SCRIPTS}"/build && "${SCRIPTS}"/services && "${SCRIPTS}"/commit "$*" && "${SCRIPTS}"/etckeeper
## END OF FILE #################################################################
Loading…
Cancel
Save