Browse code

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

Daniel-Constantin Mierla authored on 15/06/2013 20:03:58
Showing 1 changed files
... ...
@@ -2524,6 +2524,25 @@ tls_ca() {
2524 2524
 	fi
2525 2525
 }
2526 2526
 
2527
+extcmd() {
2528
+	if [ -f $ETCDIR/kamctl.${1}.ext ]; then
2529
+		. $ETCDIR/kamctl.${1}.ext
2530
+	else
2531
+		if [ -f ~/.kamctl/kamctl.${1}.ext ]; then
2532
+			. ~/.kamctl/kamctl.${1}.ext
2533
+		else
2534
+			return
2535
+		fi
2536
+	fi
2537
+
2538
+	XCMD=cmd_${1}
2539
+
2540
+	shift
2541
+	$XCMD "$@"
2542
+
2543
+	exit 1
2544
+}
2545
+
2527 2546
 #
2528 2547
 ##### ================================================ #####
2529 2548
 ### main command switch
... ...
@@ -2705,6 +2724,8 @@ case $1 in
2705 2724
 		;;
2706 2725
 		
2707 2726
 	*)
2727
+		extcmd "$@"
2728
+
2708 2729
 		usage
2709 2730
 		exit 1
2710 2731
 		;;