- Migrate rx3_net_adm and add coresponding completion script.

This commit is contained in:
2026-04-15 18:06:36 +02:00
parent 360db73a09
commit f58ffedef9
2 changed files with 265 additions and 79 deletions

View File

@@ -1,29 +1,27 @@
#!/bin/bash
#-----------------------------------------------------------------------------------------------------------------------------------
#
#
# Rx3 Net Adm
#
#
# 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 Lesser General Public License for more details.
#
#
# You should have received a copy of the GNU Lesser General Public
# License along with this program; If not, see
# <https://www.gnu.org/licenses/>.
#
#
#-----------------------------------------------------------------------------------------------------------------------------------
#-----------------------------------------------------------------------------------------------------------------------------------
# Includes
#-----------------------------------------------------------------------------------------------------------------------------------
@@ -33,34 +31,121 @@
#-----------------------------------------------------------------------------------------------------------------------------------
# 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
prog="rx3-net"
#DEBUG=""
#DEBUG="echo"
#DEBUG=":"
#LOG=":"
#LOG="echo"
rna_version_print()
{
version_print
}
#--------------------------------------------------------------------------------------------------------------------------
#-----------------------------------------------------------------------------------------------------------------------------------
# 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()
rna_start()
{
echo "Starting..."
if [ -r /var/lock/subsys/rx3-net ]
then
echo "already started"
@@ -68,20 +153,22 @@ start()
else
network_start
RETVAL=$?
[ "$RETVAL" = 0 ] && touch /var/lock/subsys/rx3-net
RETVAL=$?
[ "${RETVAL}" = 0 ] && touch /var/lock/subsys/rx3-net
fi
echo
}
#--------------------------------------------------------------------------------------------------------------------------
# Stop
#--------------------------------------------------------------------------------------------------------------------------
stop()
#-----------------------------------------------------------------------------------------------------------------------------------
# Stop
#-----------------------------------------------------------------------------------------------------------------------------------
rna_stop()
{
echo "Stopping..."
@@ -95,8 +182,8 @@ stop()
RETVAL=0
fi
[ "$RETVAL" = 0 ] && rm -f /var/lock/subsys/rx3-net
[ "${RETVAL}" = 0 ] && rm -f /var/lock/subsys/rx3-net
echo
}
@@ -104,11 +191,11 @@ stop()
#--------------------------------------------------------------------------------------------------------------------------
#-----------------------------------------------------------------------------------------------------------------------------------
# Status
#--------------------------------------------------------------------------------------------------------------------------
#-----------------------------------------------------------------------------------------------------------------------------------
status()
rna_status()
{
network_status
}
@@ -117,11 +204,11 @@ status()
#--------------------------------------------------------------------------------------------------------------------------
#-----------------------------------------------------------------------------------------------------------------------------------
# Dump
#--------------------------------------------------------------------------------------------------------------------------
#-----------------------------------------------------------------------------------------------------------------------------------
dump()
rna_dump()
{
network_tab_dump
}
@@ -131,14 +218,14 @@ dump()
#--------------------------------------------------------------------------------------------------------------------------
# Table_Set
# Table Set
#--------------------------------------------------------------------------------------------------------------------------
table_set()
rna_table_set()
{
echo "Setting ip:$1 table:$2"
network_table_set $1 $2
network_table_set "$1" "$2"
}
@@ -146,72 +233,80 @@ table_set()
#--------------------------------------------------------------------------------------------------------------------------
# Address_Refresh
# Address Refresh
#--------------------------------------------------------------------------------------------------------------------------
address_refresh()
rna_address_refresh()
{
dst_id="$1"
if [[ "${dst_id}" != "" ]]
then
echo "Refreshing address: [${dst_id}]..."
network_dst_tab_get ${dst_id}
network_dst_address_refresh ${dst_id} ${dst_host_name} ${dst_ip}
network_dst_tab_get "${dst_id}"
network_dst_address_refresh "${dst_id}" "${dst_host_name}" "${dst_ip}"
else
echo "Refreshing all address..."
network_dst_address_refresh_all
fi
}
#--------------------------------------------------------------------------------------------------------------------------
#-----------------------------------------------------------------------------------------------------------------------------------
# Main
#--------------------------------------------------------------------------------------------------------------------------
#-----------------------------------------------------------------------------------------------------------------------------------
rna_args_parse "$@"
if [[ "${MODE}" == "EXIT" ]]
then
exit 0
fi
network_init
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
case "${MODE}" in
START)
rna_start
;;
STOP)
rna_stop
;;
RESTART)
rna_stop
sleep 1
start
;;
status)
status
;;
rna_start
;;
dump)
dump
;;
table_set)
table_set $2 $3
;;
STATUS)
rna_status
;;
DUMP)
rna_dump
;;
TABLE_SET)
rna_table_set "$2" "$3"
;;
REFRESH_ADDRESS)
rna_address_refresh "$2"
;;
refresh_address)
address_refresh $2
;;
*)
echo "Usage: $0 {start|stop|restart|status|dump|table_set|refresh_address}"
RETVAL=1
;;
;;
esac
network_deinit
exit $RETVAL
exit ${RETVAL}