Code development platform for open source projects from the European Union institutions :large_blue_circle: EU Login authentication by SMS has been phased out. To see alternatives please check here

Skip to content
Snippets Groups Projects
Commit 81147442 authored by Kostis ANAGNOSTOPOULOS's avatar Kostis ANAGNOSTOPOULOS Committed by inp
Browse files

FEAT(setup) -k: KEEP_GOING, -f: FORCE >

fix: script nargs($#) NOT updated with `set -- new args`!
parent a200577d
No related branches found
No related tags found
No related merge requests found
...@@ -3,24 +3,24 @@ ...@@ -3,24 +3,24 @@
# Call this script with the name of the action-function as arg[1]. # Call this script with the name of the action-function as arg[1].
function _HELP { echo \ function _HELP { echo \
"$mycmd - setup a BDAP user account with (pending) actions for keyboard, bash, git, conda "$mycmd - setup a BDAP user account with (pending) actions for keyboard, bash, git, conda
SYNTAX: logout & re-login:
$mycmd [-h]--help] ... $mycmd [-h]--help] ...
$mycmd [-n] [ACTION]... $mycmd [-n] [-k] [-f] [ACTION]...
OPTIONS: OPTIONS:
-n: dry_run - don't actually update stuff -n: dry_run - don't actually update stuff (but evaluate checks)
-k: keep_going - don't stop on errors
-f: force - update stuff regardless of checks
ACTION: ACTION:
$(for i in $(_list_all_actions); do echo " $i"; done) $(for i in $(_list_all_actions); do echo " $i"; done)
NOTES: NOTES:
* Without any args, it launches 'all' actions above, in that order. * Without any args, it launches 'all' actions above, in that order.
* The 'upd30_git_user_XXX' actions awaits interactively input from the user. * The 'upd30_git_user_XXX' actions awaits interactively input from the user.
* You may have to logout & re-login after 'upd40_bashrc_conda_init', * It stops after 'upd40_bashrc_conda_init', to logout & re-login,
for 'upd50_create_conda_env' to succeed. for 'upd50_create_conda_env' to succeed (unless -k).
* You can repeatedly run this script, until all actions succeed. * You can repeatedly run this script, until all actions succeed.
" "
} }
set -e
mycmd="${0##*/}" mycmd="${0##*/}"
mydir=$(realpath "${0%/*}") mydir=$(realpath "${0%/*}")
cd "$mydir" cd "$mydir"
...@@ -37,6 +37,10 @@ function _short { ...@@ -37,6 +37,10 @@ function _short {
fi fi
} }
function _join {
echo $*
}
conda_env_prefix=$(_short "$mydir/env") conda_env_prefix=$(_short "$mydir/env")
function _mute { function _mute {
...@@ -50,13 +54,16 @@ function _log { ...@@ -50,13 +54,16 @@ function _log {
function _cmd_before_update { function _cmd_before_update {
local lognstack=$(( ${lognstack:-1} + 1)) local lognstack=$(( ${lognstack:-1} + 1))
if [ -n "$force" ]; then
set -- false # Force 2nd (running) branch in the check below.
fi
if "${@}"; then if "${@}"; then
_log -e "${notrun_msg:-already ok}" _log -e "${notrun_msg:-already ok}"
return 1 return 1
else else
_log -en "${running_msg:-updating...}" _log -en "${running_msg:-updating...}"
if [ -n "${dry_run}" ]; then if [ -n "${dry_run}" ]; then
echo "(DRY_RUN)" echo "${force:+(FORCE)}(DRY_RUN)"
return 1 # (already run) when $dry_run return 1 # (already run) when $dry_run
fi fi
return 0 # true, to run if-body updating stuff. return 0 # true, to run if-body updating stuff.
...@@ -276,8 +283,13 @@ function upd40_bashrc_conda_init { ...@@ -276,8 +283,13 @@ function upd40_bashrc_conda_init {
if _grep_before_update "$check_file" ">>> conda initialize >>>"; then if _grep_before_update "$check_file" ">>> conda initialize >>>"; then
## Will print a message to logout & re-login. ## Will print a message to logout & re-login.
conda init bash conda init bash
if [ -n "$keep_going" ]; then
_log "Would STOP to logout + re-login if not KEEP_GOING."
else
exit 0 exit 0
fi fi
fi
} }
## This function must be the 1st to run after all `upd_xxx` actions. ## This function must be the 1st to run after all `upd_xxx` actions.
...@@ -342,13 +354,32 @@ function all { ...@@ -342,13 +354,32 @@ function all {
if [[ "${@#-h}" != "$@" || "${@#--help}" != "$@" ]]; then if [[ "${@#-h}" != "$@" || "${@#--help}" != "$@" ]]; then
_HELP _HELP
else else
[[ "${@#-n}" != "$@" ]] && dry_run=1 let nargs="$#"
if [[ "${@#-k}" != "$@" ]]; then
keep_going=1
set -- "${@#-k}"
((nargs-=1))
fi
if [[ "${@#-n}" != "$@" ]]; then
dry_run=1
set -- "${@#-n}" set -- "${@#-n}"
if [[ $# -eq 0 ]]; then ((nargs-=1))
echo "Running all actions${dry_run:+(DRY_RUN)}..." fi
if [[ "${@#-f}" != "$@" ]]; then
force=1
set -- "${@#-f}"
((nargs-=1))
fi
if [ -z "$keep_going" ]; then
set -e
fi
if [ "$nargs" -eq 0 ]; then
echo "Running all actions${dry_run:+(DRY_RUN)}${keep_going:+(KEEP_GOING)}${force:+(FORCE)}..."
all all
else else
echo "Running x$# actions: '${@}'" echo "Running x$nargs actions: '${@}'"
## execute the asked action. ## execute the asked action.
for cmd in "${@}"; do for cmd in "${@}"; do
$cmd $cmd
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment