New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Automated unique default user_input_ID for UserInput #1408
Automated unique default user_input_ID for UserInput #1408
Conversation
…tion (some kind of precondition for issue 1366)
…p of endless retrying UserInput calls
@jsmeix I had another close look at the I therefore would like us to consider to remove this automatic feature with the goal of only having explicit interfaces for users to configure and not to have implicit interfaces. As we just introduce the People will still have to update their answers when we change the wording of the answer they use but at least they won't have to do anything when we move the code or when we change the default or an answer that they didn't care about. Here is the list of files to update, IMHO no big deal: $ git grep -cE '^[^\#]+\(\s*UserInput'
usr/share/rear/format/USB/default/200_check_usb_layout.sh:1
usr/share/rear/format/USB/default/300_format_usb_disk.sh:1
usr/share/rear/layout/prepare/GNU/Linux/150_include_drbd_code.sh:1
usr/share/rear/layout/prepare/default/600_show_unprocessed.sh:1
usr/share/rear/restore/BORG/default/300_load_archives.sh:1
usr/share/rear/restore/FDRUPSTREAM/default/270_selinux_considerations.sh:1
usr/share/rear/restore/NBKDC/default/400_restore_backup.sh:1 What do you think? |
@schlomo The idea is that each different UserInput function is called UserInput -I 123 ... The automated default user_input_ID is only there Why I currently do not call UserInput with '-I': Because IDs of different UserInput function calls I think the ID should contain the script number, UserInput -I 123... ... but the script number is not unique so that As soon as I have a good idea for a reasonable and |
Note that UserInput calls can even have same IDs Only a theoretical example (I don't know a real one): UserInput -I 999999 -t 0 -p 'Press [Enter] to continue after restore' Of course this here is only a theoretical example |
I fully understand and share your concerns, @jsmeix The more we talk about this the more I get the feeling that a bash array is the wrong tool for providing the answers to ReaR questions. Bash arrays are indexed by numbers which is apparently not flexible enough. How about switching to property files? Let's think about a directory
And of course the user input function for the multipathing issue we discuss in #1449 would be called with The idea is semantic naming for the user input ID. With a little magic grep and sed I will be able to create for you an answer file where everything is commented out :-) With such a model (string instead of number as user input ID) you don't need to keep a precise inventory of existing user input IDs. And I would still prefer to not have automatic user input IDs because I don't want to create an interface that will change as we refactor ReaR code. |
Only a side note Bash 4.x supports associative arrays where the members # unset USER_INPUT_VALUES # declare -A USER_INPUT_VALUES # USER_INPUT_VALUES[first_user_input]='input for UserInput -I first_user_input' # USER_INPUT_VALUES[second_user_input]='input for UserInput -I second_user_input' # USER_INPUT_VALUES[third_user_input]='input for UserInput -I third_user_input' # for user_input in "${USER_INPUT_VALUES[@]}" ; do echo "'$user_input'" ; done 'input for UserInput -I second_user_input' 'input for UserInput -I third_user_input' 'input for UserInput -I first_user_input' # index='second_user_input' ; echo ${USER_INPUT_VALUES[$index]} input for UserInput -I second_user_input # USER_INPUT_VALUES[last user input]="input for UserInput -I 'last user input'" # for user_input in "${USER_INPUT_VALUES[@]}" ; do echo "'$user_input'" ; done 'input for UserInput -I second_user_input' 'input for UserInput -I 'last user input'' 'input for UserInput -I third_user_input' 'input for UserInput -I first_user_input' # index='last user input' ; echo ${USER_INPUT_VALUES[$index]} input for UserInput -I 'last user input' |
If we do not have automatic user input IDs I think with strings as ID this should be acceptable UserInput -I asdfghjkl -t 0 -p 'Press [Enter] to continue' when he does not care about the ID string. |
@schlomo I think a single file /etc/rear/user_input[.conf] ID_string="arbitrary user input string" should be sufficient. I would like to source that file in the UserInput function |
Whatever we do must support multiple configuration / input files so that people can easily provide different answers from different sources (e.g. packages). Therefore I'd like to have a directory where users can put multiple files. Personally I think that editing a properties file is simpler because there you have the user input ID as the key without any prefix. But I don't insist on that. What I do find important is that the user input ID is something that the user can set "as is" in a file. If the user input IDs are Bash variables then we must prefix them with some constant and then the So the main question is probably: Do we want to have user input IDs without a prefix? Then we should put them into a different configuration namespace which would be a different configuration directory. Even if the format is Bash (and we read it with And I am not sure if |
Have an automated unique default user_input_ID
for the UserInput function so that each
UserInput function call has a user_input_ID
which is some kind of precondition for
#1366
Now (at least from my current point of view)
the UserInput function should be feature-complete.
It needs 'bc' to calculate huge numbers and (fortunately) since
#1332
'bc' is one of the REQUIRED_PROGS in default.conf
so that it is also available in the ReaR recovery system.
By the way I enhanced the CallerSource function
that now also outputs the line number (useful in bigger scripts)
because I learned how to use BASH_LINENO correctly
(there is an unexpected - but documented - "off by one"
for the BASH_LINENO array index).