Skip to content
Snippets Groups Projects
Commit fd676bf7 authored by Erik von Reis's avatar Erik von Reis
Browse files

more flexible command line flag handling

parent f9e2c3cd
No related branches found
No related tags found
1 merge request!150Update rtcds with user-space model flags
......@@ -4,6 +4,48 @@ log() {
echo "$@" >&2
}
# capture all command line flags as variables
params=""
ccmd=""
while (( "$#" )); do
case "$1" in
--all)
ALL_FLAG=0
shift
;;
--user-space|--userland)
USERLAND_FLAG=0
shift
;;
-f)
FOLLOW_FLAG=0
shift
;;
-i)
INFO_FLAG=0
shift
;;
version|-v|--version)
VERSION_FLAG=0
shift
;;
help|-h|--help)
HELP_FLAG=0
shift
;;
--*|-*) # unknown flags
log "Error: Unknown flag $1"
exit 1
;;
*) #handle non-flags
params="${params} $1"
shift
;;
esac
done
eval set -- "$params"
RTS_VERSION=${RTS_VERSION:-__VERSION__}
if [[ "$RTS_VERSION" =~ ._VERSION_. ]] ; then
log "RTS_VERSION variable not set."
......@@ -364,14 +406,15 @@ usage() {
local enable_usage=""
fi
echo "Usage: $(basename $0) <command> [args]
echo "Usage: $(basename $0) <command> [options] [args]
Advanced LIGO Real Time System control interface.
Available commands:
build|make <sys> build system
install <sys> install system
build|make <sys>...|--all build system
--user-space|--userland build for user space instead of kernel space
install <sys>...|--all install system
list|ls list systems for host
......@@ -393,7 +436,17 @@ Available commands:
"
}
if [ "$1" ] ; then
if [[ $HELP_FLAG ]]; then
usage
exit 0
fi
if [[ $VERSION_FLAG ]] ; then
echo $RTS_VERSION
exit 0
fi
if [[ $1 ]] ; then
cmd=$1
shift
else
......@@ -403,101 +456,100 @@ else
exit 1
fi
case $cmd in
'build'|'make')
if [ -z "$1" ] ; then
if [[ $ALL_FLAG ]] ; then
check_env
prep_buildd
build_world
elif [[ $1 ]] ; then
check_env
prep_buildd
build_sys $@
else
log "You must specify at least one system to build."
exit 2
fi
check_env
prep_buildd
if [[ "$1" == '--all' ]] ; then
build_world
else
build_sys $@
fi
;;
'install')
if [ -z "$1" ] ; then
if [[ $ALL_FLAG ]] ; then
check_env
prep_target
install_world
elif [[ $1 ]] ; then
check_env
prep_target
install_sys $@
else
log "You must specify at least one system to install."
exit 2
fi
check_env
prep_target
if [[ "$1" == '--all' ]] ; then
install_world
else
install_sys $@
fi
;;
'start')
if [ -z "$1" ] ; then
if [[ $ALL_FLAG ]] ; then
start_sys $(list_host_sys)
elif [[ $1 ]] ; then
check_host_sys_inactive $@
start_sys $@
else
log "You must specify at least one system to start (or '--all')."
exit 2
fi
if [[ "$1" == '--all' ]] ; then
start_sys $(list_host_sys)
else
check_host_sys_inactive $@
start_sys $@
fi
;;
'restart')
if [ -z "$1" ] ; then
if [[ $ALL_FLAG ]] ; then
# we do this in reverse so the IOP is stopped last
stop_sys $(list_host_sys | tac)
start_sys $(list_host_sys)
elif [[ $1 ]] ; then
check_host_sys_active $@
stop_sys $@
start_sys $@
else
log "You must specify at least one system to restart (or '--all')."
exit 2
fi
if [[ "$1" == '--all' ]] ; then
# we do this in reverse so the IOP is stopped last
stop_sys $(list_host_sys | tac)
start_sys $(list_host_sys)
else
check_host_sys_active $@
stop_sys $@
start_sys $@
fi
;;
'stop'|'kill')
if [ -z "$1" ] ; then
if [[ $ALL_FLAG ]] ; then
# we do this in reverse so the IOP is stopped last
stop_sys $(list_host_sys | tac)
elif [[ $1 ]] ; then
check_host_sys_active $@
stop_sys $@
else
log "You must specify at least one system to stop (or '--all')."
exit 2
fi
if [[ "$1" == '--all' ]] ; then
# we do this in reverse so the IOP is stopped last
stop_sys $(list_host_sys | tac)
else
check_host_sys_active $@
stop_sys $@
fi
;;
'enable'|'disable')
if [[ ${cmd} == 'enable' ]] && ! $ALLOW_MODEL_ENABLE ]] ; then
log "Enabling models is not allowed on this host."
log "ALLOW_MODEL_ENABLE environment variable is set to false."
exit 2
fi
if [ -z "$1" ] ; then
if [[ ${cmd} == 'enable' ]] && ! $ALLOW_MODEL_ENABLE ]] ; then
log "Enabling models is not allowed on this host."
log "ALLOW_MODEL_ENABLE environment variable is set to false."
exit 2
fi
if [[ $ALL_FLAG ]] ; then
# we do this in reverse so the IOP is stopped last
${cmd}_sys $(list_host_sys | tac)
elif [[ $1 ]] ; then
${cmd}_sys $@
else
log "You must specify at least one system to $cmd (or '--all')."
exit 2
fi
if [[ "$1" == '--all' ]] ; then
# we do this in reverse so the IOP is stopped last
${cmd}_sys $(list_host_sys | tac)
else
${cmd}_sys $@
fi
;;
'status')
if [ -z "$1" ] ; then
if [ -z "$1" ] || [[ $ALL_FLAG ]] ; then
global_status
else
sys=$1
systemctl status rts@${sys}.target rts-{awgtpman,epics,module}@${sys}.service
fi
;;
;;
'log')
args=
if [[ "$1" == '-f' ]] ; then
if [[ $FOLLOW_FLAG ]] ; then
args="-f"
shift
fi
......@@ -510,7 +562,7 @@ case $cmd in
;;
'blog')
format=full
if [[ "$1" == '-i' ]] ; then
if [[ $INFO_FLAG ]] ; then
format=info
shift
fi
......@@ -540,12 +592,6 @@ case $cmd in
'env')
check_env
;;
'version'|'v'|'vers'|'-v'|'--version')
echo $RTS_VERSION
;;
'help'|'-h'|'--help')
usage
;;
*)
log "Unknown command: $cmd"
log
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment