mirror of https://github.com/sipwise/ngcpcfg.git
Normally it is necessary to press TAB multiple times, e.g: > vim /etc/ngcp-conf<TAB>/con<TAB>f<TAB>... For new NGCP users it is even longer. In the same time we have a nice usability experience for ngcp-ppa, where users are just pressing "ngcp-ppa<ENTER>1<ENTER>1<ENTER>". Let's add the same concept here as the order of the main files is static: > 1) /etc/ngcp-config/config.yml > 2) /etc/ngcp-config/network.yml > 3) /etc/ngcp-config/constants.yml if I need to edit network.yml I will type: > ngcpc<TAB> e<TAB><ENTER>2<ENTER> or even: > ngcpc<TAB> e<TAB>2<ENTER> Change-Id: Id20fec8c931c15c73a73689a3f8b552a72ef11f7mr10.0
parent
53f98d540b
commit
b821e0052b
@ -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 #################################################################
|
||||
Loading…
Reference in new issue