- Migrate rx3_net_adm and add coresponding completion script.
This commit is contained in:
91
etc/bash_completion.d/rx3_net_adm
Normal file
91
etc/bash_completion.d/rx3_net_adm
Normal file
@@ -0,0 +1,91 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
#
|
||||||
|
# Rx3 Net Adm Bash Completion
|
||||||
|
#
|
||||||
|
# Copyright (C) 2025-2026 Arnaud G. GIBERT
|
||||||
|
# mailto:arnaud@rx3.net
|
||||||
|
#
|
||||||
|
# This is free software: you can redistribute it and/or modify it
|
||||||
|
# under the terms of the GNU Lesser General Public License as published
|
||||||
|
# by the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program; If not, see
|
||||||
|
# <https://www.gnu.org/licenses/>.
|
||||||
|
#
|
||||||
|
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
# Rx3 Net Adm Completion
|
||||||
|
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
_rx3_net_adm_completion()
|
||||||
|
{
|
||||||
|
local cur="${COMP_WORDS[COMP_CWORD]}"
|
||||||
|
local prev="${COMP_WORDS[COMP_CWORD-1]}"
|
||||||
|
local opts="-h --help -V --version -v --verbose"
|
||||||
|
|
||||||
|
local pos=0
|
||||||
|
local i
|
||||||
|
|
||||||
|
COMPREPLY=()
|
||||||
|
|
||||||
|
# Count non-option positional arguments already provided
|
||||||
|
for (( i=1; i<COMP_CWORD; i++ ))
|
||||||
|
do
|
||||||
|
case "${COMP_WORDS[i]}" in
|
||||||
|
-h|--help|-V|--version|-v|--verbose)
|
||||||
|
;;
|
||||||
|
--)
|
||||||
|
;;
|
||||||
|
-*)
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
pos=$(( pos + 1 ))
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
# Complete options if current word starts with '-'
|
||||||
|
if [[ "${cur}" == -* ]]
|
||||||
|
then
|
||||||
|
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Complete positional arguments
|
||||||
|
case "${pos}" in
|
||||||
|
0)
|
||||||
|
COMPREPLY=( $(compgen -W "start stop restart status dump table_set refresh_address" -- "${cur}") )
|
||||||
|
;;
|
||||||
|
1)
|
||||||
|
case "${prev}" in
|
||||||
|
table_set)
|
||||||
|
COMPREPLY=( $(compgen -W "$(network_dst_tab_dump | grep -oP 'Name.*: \[\K[^\]]+')" -- "${cur}") )
|
||||||
|
;;
|
||||||
|
refresh_address)
|
||||||
|
COMPREPLY=( $(compgen -W "$(network_dst_tab_dump | grep -oP 'Name.*: \[\K[^\]]+')" -- "${cur}") )
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
COMPREPLY=()
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
COMPREPLY=()
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
complete -o filenames -F _rx3_net_adm_completion rx3_net_adm
|
||||||
@@ -22,8 +22,6 @@
|
|||||||
#
|
#
|
||||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||||
# Includes
|
# Includes
|
||||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||||
@@ -33,31 +31,118 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
# Global Variables
|
||||||
|
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
declare -g VERSION="1.0.0"
|
||||||
|
declare -g NAME="rx3_net_adm"
|
||||||
|
declare -g HELP="usage: [-h | --help] | [-V | --version] | [-v | --verbose] {start|stop|restart|status|dump|table_set|refresh_address} [args...]"
|
||||||
|
|
||||||
|
declare -g MODE="DEFAULT"
|
||||||
|
declare -g VERBOSE="FALSE"
|
||||||
|
declare -g DRY_RUN="FALSE"
|
||||||
|
declare -g RETVAL=0
|
||||||
|
declare -g prog="rx3-net"
|
||||||
|
|
||||||
|
declare -g DEBUG=""
|
||||||
|
#declare -g DEBUG="echo"
|
||||||
|
#declare -g DEBUG=":"
|
||||||
|
|
||||||
|
declare -g LOG=""
|
||||||
|
#declare -g LOG=":"
|
||||||
|
#declare -g LOG="echo"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||||
# Global Variable
|
# Version Print
|
||||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
RETVAL=0
|
rna_version_print()
|
||||||
prog="rx3-net"
|
{
|
||||||
|
version_print
|
||||||
#DEBUG=""
|
}
|
||||||
#DEBUG="echo"
|
|
||||||
#DEBUG=":"
|
|
||||||
|
|
||||||
#LOG=":"
|
|
||||||
#LOG="echo"
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#--------------------------------------------------------------------------------------------------------------------------
|
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
# Help Print
|
||||||
|
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
rna_help_print()
|
||||||
|
{
|
||||||
|
rna_version_print
|
||||||
|
help_print
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
# Arg Parse
|
||||||
|
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
rna_args_parse()
|
||||||
|
{
|
||||||
|
tmp_args=$(getopt -o hvV --long help,verbose,version -n "${NAME}" -- "$@")
|
||||||
|
|
||||||
|
if [ $? != 0 ]; then echo "Terminating..." >&2; exit 1; fi
|
||||||
|
|
||||||
|
eval set -- "${tmp_args}"
|
||||||
|
|
||||||
|
while true
|
||||||
|
do
|
||||||
|
case "$1" in
|
||||||
|
# Options
|
||||||
|
-h|--help) MODE="EXIT"; rna_help_print; shift;;
|
||||||
|
-V|--version) MODE="EXIT"; rna_version_print; shift;;
|
||||||
|
-v|--verbose) VERBOSE="TRUE"; shift;;
|
||||||
|
|
||||||
|
# End of options
|
||||||
|
--) shift; break;;
|
||||||
|
*) echo "args_parse internal error [$1]!"; exit 1;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
if [[ "${MODE}" != "EXIT" ]]
|
||||||
|
then
|
||||||
|
if [[ "${#}" -lt "1" ]]
|
||||||
|
then
|
||||||
|
MODE="EXIT"
|
||||||
|
|
||||||
|
echo_error "Not enough args!"
|
||||||
|
rna_help_print
|
||||||
|
else
|
||||||
|
case "$1" in
|
||||||
|
start|stop|restart|status|dump|table_set|refresh_address)
|
||||||
|
MODE="$(echo "$1" | tr '[:lower:]' '[:upper:]')"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
MODE="EXIT"
|
||||||
|
|
||||||
|
echo_error "Invalid command: [$1]"
|
||||||
|
rna_help_print
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||||
# Start
|
# Start
|
||||||
#--------------------------------------------------------------------------------------------------------------------------
|
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
start()
|
rna_start()
|
||||||
{
|
{
|
||||||
echo "Starting..."
|
echo "Starting..."
|
||||||
|
|
||||||
@@ -69,7 +154,7 @@ start()
|
|||||||
network_start
|
network_start
|
||||||
|
|
||||||
RETVAL=$?
|
RETVAL=$?
|
||||||
[ "$RETVAL" = 0 ] && touch /var/lock/subsys/rx3-net
|
[ "${RETVAL}" = 0 ] && touch /var/lock/subsys/rx3-net
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo
|
echo
|
||||||
@@ -77,11 +162,13 @@ start()
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
#--------------------------------------------------------------------------------------------------------------------------
|
|
||||||
# Stop
|
|
||||||
#--------------------------------------------------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
stop()
|
|
||||||
|
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
# Stop
|
||||||
|
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
rna_stop()
|
||||||
{
|
{
|
||||||
echo "Stopping..."
|
echo "Stopping..."
|
||||||
|
|
||||||
@@ -95,7 +182,7 @@ stop()
|
|||||||
RETVAL=0
|
RETVAL=0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
[ "$RETVAL" = 0 ] && rm -f /var/lock/subsys/rx3-net
|
[ "${RETVAL}" = 0 ] && rm -f /var/lock/subsys/rx3-net
|
||||||
|
|
||||||
echo
|
echo
|
||||||
}
|
}
|
||||||
@@ -104,11 +191,11 @@ stop()
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
#--------------------------------------------------------------------------------------------------------------------------
|
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||||
# Status
|
# Status
|
||||||
#--------------------------------------------------------------------------------------------------------------------------
|
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
status()
|
rna_status()
|
||||||
{
|
{
|
||||||
network_status
|
network_status
|
||||||
}
|
}
|
||||||
@@ -117,11 +204,11 @@ status()
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
#--------------------------------------------------------------------------------------------------------------------------
|
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||||
# Dump
|
# Dump
|
||||||
#--------------------------------------------------------------------------------------------------------------------------
|
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
dump()
|
rna_dump()
|
||||||
{
|
{
|
||||||
network_tab_dump
|
network_tab_dump
|
||||||
}
|
}
|
||||||
@@ -131,14 +218,14 @@ dump()
|
|||||||
|
|
||||||
|
|
||||||
#--------------------------------------------------------------------------------------------------------------------------
|
#--------------------------------------------------------------------------------------------------------------------------
|
||||||
# Table_Set
|
# Table Set
|
||||||
#--------------------------------------------------------------------------------------------------------------------------
|
#--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
table_set()
|
rna_table_set()
|
||||||
{
|
{
|
||||||
echo "Setting ip:$1 table:$2"
|
echo "Setting ip:$1 table:$2"
|
||||||
|
|
||||||
network_table_set $1 $2
|
network_table_set "$1" "$2"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -146,20 +233,19 @@ table_set()
|
|||||||
|
|
||||||
|
|
||||||
#--------------------------------------------------------------------------------------------------------------------------
|
#--------------------------------------------------------------------------------------------------------------------------
|
||||||
# Address_Refresh
|
# Address Refresh
|
||||||
#--------------------------------------------------------------------------------------------------------------------------
|
#--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
address_refresh()
|
rna_address_refresh()
|
||||||
{
|
{
|
||||||
dst_id="$1"
|
dst_id="$1"
|
||||||
|
|
||||||
|
|
||||||
if [[ "${dst_id}" != "" ]]
|
if [[ "${dst_id}" != "" ]]
|
||||||
then
|
then
|
||||||
echo "Refreshing address: [${dst_id}]..."
|
echo "Refreshing address: [${dst_id}]..."
|
||||||
|
|
||||||
network_dst_tab_get ${dst_id}
|
network_dst_tab_get "${dst_id}"
|
||||||
network_dst_address_refresh ${dst_id} ${dst_host_name} ${dst_ip}
|
network_dst_address_refresh "${dst_id}" "${dst_host_name}" "${dst_ip}"
|
||||||
else
|
else
|
||||||
echo "Refreshing all address..."
|
echo "Refreshing all address..."
|
||||||
|
|
||||||
@@ -169,41 +255,50 @@ address_refresh()
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
#--------------------------------------------------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
|
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||||
# Main
|
# Main
|
||||||
#--------------------------------------------------------------------------------------------------------------------------
|
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
rna_args_parse "$@"
|
||||||
|
|
||||||
|
if [[ "${MODE}" == "EXIT" ]]
|
||||||
|
then
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
network_init
|
network_init
|
||||||
|
|
||||||
case "$1" in
|
case "${MODE}" in
|
||||||
start)
|
START)
|
||||||
start
|
rna_start
|
||||||
;;
|
;;
|
||||||
|
|
||||||
stop)
|
STOP)
|
||||||
stop
|
rna_stop
|
||||||
;;
|
;;
|
||||||
|
|
||||||
restart)
|
RESTART)
|
||||||
stop
|
rna_stop
|
||||||
sleep 1
|
sleep 1
|
||||||
start
|
rna_start
|
||||||
;;
|
;;
|
||||||
|
|
||||||
status)
|
STATUS)
|
||||||
status
|
rna_status
|
||||||
;;
|
;;
|
||||||
|
|
||||||
dump)
|
DUMP)
|
||||||
dump
|
rna_dump
|
||||||
;;
|
;;
|
||||||
|
|
||||||
table_set)
|
TABLE_SET)
|
||||||
table_set $2 $3
|
rna_table_set "$2" "$3"
|
||||||
;;
|
;;
|
||||||
|
|
||||||
refresh_address)
|
REFRESH_ADDRESS)
|
||||||
address_refresh $2
|
rna_address_refresh "$2"
|
||||||
;;
|
;;
|
||||||
|
|
||||||
*)
|
*)
|
||||||
@@ -214,4 +309,4 @@ esac
|
|||||||
|
|
||||||
network_deinit
|
network_deinit
|
||||||
|
|
||||||
exit $RETVAL
|
exit ${RETVAL}
|
||||||
|
|||||||
Reference in New Issue
Block a user