[sr-dev] git:master: kamctl: new commands can be defined in separate files

Daniel-Constantin Mierla miconda at gmail.com
Sat Jun 15 22:10:54 CEST 2013


Module: sip-router
Branch: master
Commit: ea772b354f84eccff0190234025f057879ff33ed
URL:    http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=ea772b354f84eccff0190234025f057879ff33ed

Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date:   Sat Jun 15 22:03:58 2013 +0200

kamctl: new commands can be defined in separate files

- write new kamctl commands either in CFGDIR/kamctl.newcmd.ext or
  ~/.kamctl/kamctl.newcmd.ext
- 'newcmd' has to be replaced with the name of the command
- the file must include cmd_newcmd() function which is executed with the
  parameters after the command name
- example: adding new command 'sample'
	- content of ~/.kamctl/kamctl.sample.ext file:

usage_sample() {
    echo
    mecho " -- command 'sample' - kamctl sample extension command"
    echo
cat <<EOF
 test ............................... print test message
 help ............................... help text
EOF
}

cmd_sample() {
    case $1 in
        test)
            echo "message from sample test command"
        ;;
        *)
            usage_sample
        ;;
    esac
    exit 1;
}

- new command 'sample' can be executed with:

kamctl sample test

---

 utils/kamctl/kamctl |   21 +++++++++++++++++++++
 1 files changed, 21 insertions(+), 0 deletions(-)

diff --git a/utils/kamctl/kamctl b/utils/kamctl/kamctl
index 4583926..0dee374 100755
--- a/utils/kamctl/kamctl
+++ b/utils/kamctl/kamctl
@@ -2524,6 +2524,25 @@ tls_ca() {
 	fi
 }
 
+extcmd() {
+	if [ -f $ETCDIR/kamctl.${1}.ext ]; then
+		. $ETCDIR/kamctl.${1}.ext
+	else
+		if [ -f ~/.kamctl/kamctl.${1}.ext ]; then
+			. ~/.kamctl/kamctl.${1}.ext
+		else
+			return
+		fi
+	fi
+
+	XCMD=cmd_${1}
+
+	shift
+	$XCMD "$@"
+
+	exit 1
+}
+
 #
 ##### ================================================ #####
 ### main command switch
@@ -2705,6 +2724,8 @@ case $1 in
 		;;
 		
 	*)
+		extcmd "$@"
+
 		usage
 		exit 1
 		;;




More information about the sr-dev mailing list