diff --git a/debian/ngcp-ngcpcfg.install b/debian/ngcp-ngcpcfg.install index 4a2988d5..46878a34 100644 --- a/debian/ngcp-ngcpcfg.install +++ b/debian/ngcp-ngcpcfg.install @@ -25,6 +25,7 @@ scripts/clean usr/share/ngcp-ngcpcfg/scripts/ scripts/commit usr/share/ngcp-ngcpcfg/scripts/ scripts/del usr/share/ngcp-ngcpcfg/scripts/ scripts/diff usr/share/ngcp-ngcpcfg/scripts/ +scripts/edit usr/share/ngcp-ngcpcfg/scripts/ scripts/etckeeper usr/share/ngcp-ngcpcfg/scripts/ scripts/get usr/share/ngcp-ngcpcfg/scripts/ scripts/initialise usr/share/ngcp-ngcpcfg/scripts/ diff --git a/debian/ngcpcfg.completion b/debian/ngcpcfg.completion index 6a3a581c..0e929f37 100644 --- a/debian/ngcpcfg.completion +++ b/debian/ngcpcfg.completion @@ -70,6 +70,11 @@ _ngcpcfg() fi return ;; + edit) + cur=${cur:-/etc/ngcp-config/} + _filedir + return + ;; get) # XXX - would be nice to get completion based on content of /etc/ngcp-config/*.yml return diff --git a/docs/ngcpcfg.txt b/docs/ngcpcfg.txt index d0b1c1b5..3a2cdc18 100644 --- a/docs/ngcpcfg.txt +++ b/docs/ngcpcfg.txt @@ -413,6 +413,11 @@ to specify revisions). If the tool doesn't report anything it means that there are neither any uncommitted changes nor any new or removed files (files which are not yet (un)registered to the repository). + **edit**:: + +Helper to edit the ngcpcfg's YML configuration files in a faster way +(it prevents unnecessary pressing). + **encrypt**:: Encrypt /etc/ngcp-config and all resulting configuration files with a user diff --git a/sbin/ngcpcfg b/sbin/ngcpcfg index 1ab530ab..069d70a5 100755 --- a/sbin/ngcpcfg +++ b/sbin/ngcpcfg @@ -48,6 +48,7 @@ Actions: commit [] commit and record changes (without pushing) del [] delete YAML option from defined file diff [] display pending configuration changes + edit edit YAML configuration files get print key value from YAML configuration files help display this help screen and exit initialise initialise setup (to be executed only once on setup) @@ -141,6 +142,7 @@ case ${1:-} in init-shared|\ initialise|\ get|\ + edit|\ show) main_action "$@" ;; diff --git a/scripts/edit b/scripts/edit new file mode 100755 index 00000000..8943b690 --- /dev/null +++ b/scripts/edit @@ -0,0 +1,76 @@ +#!/bin/bash +# Purpose: edit ngcp-config's configuration YML file +################################################################################ + +set -e +set -u + +# support testsuite +FUNCTIONS="${FUNCTIONS:-/usr/share/ngcp-ngcpcfg/functions/}" +HELPER="${HELPER:-/usr/share/ngcp-ngcpcfg/helper/}" + +if ! [ -r "${FUNCTIONS}"/main ] ; then + printf "Error: %s/main could not be read. Exiting.\n" "${FUNCTIONS}" >&2 + exit 1 +fi + +if [ -z "${EDITOR:-}" ] ; then + if [ -x "/usr/bin/vim" ]; then + EDITOR="/usr/bin/vim" + else + printf "Error: Missing \$EDITOR environmanent variable. Exiting.\n" >&2 + exit 1 + fi +fi + +# shellcheck disable=SC1090 +. "${FUNCTIONS}"/main + +# main script +RC=0 +file="" + +if [ "${#:-}" -ge 1 ] ; then + file=$1 + case ${file,,} in + 1|config|config.yml) + file="${NGCPCTL_MAIN}/config.yml" + ;; + 2|network|network.yml) + file="${NGCPCTL_MAIN}/network.yml" + ;; + 3|constants|constants.yml) + file="${NGCPCTL_MAIN}/constants.yml" + ;; + *) + echo "Error: Unknown choise '${file}'. Aborting." >&2 + exit 1 + ;; + esac +else + # Get the list of configs in static order to be constant over the time + # and process the main YML configs first: config.yml network.yml constants.yml + # NOTE: the file are loaded/merged into ngcpcfg in different order! + declare -a CONFIGS + for f in ${NGCPCTL_CONFIG:?} ${NETWORK_CONFIG:?} ${CONSTANTS_CONFIG:?} ${HA_CONFIG:-} ${PAIR_CONFIG:-} ${HOST_CONFIG:-} ${LOCAL_CONFIG:-} "${EXTRA_CONFIG_FILES[@]}" ; do + if [ -r "$f" ] ; then + CONFIGS+=("${f}") + fi + done + + select f in "${CONFIGS[@]}" ; do + if [[ -z "${f}" ]]; then + echo "Exit as requested." + exit 0 + else + file=$f + break + fi + done +fi + +"${EDITOR}" "${file}" || RC=$? + +exit "$RC" + +## END OF FILE #################################################################