-
-
Notifications
You must be signed in to change notification settings - Fork 15
feature/dialog: feature provides a wrapper around dialogs #40
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| # Feature: dialog | ||
|
|
||
| This feature provides a wrapper around dialogs such as password prompts. Work | ||
| with dialogs becomes more challenging when using bootsplash/plymouth. Other | ||
| utilities can also be used to display the dialog. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| # SPDX-License-Identifier: GPL-3.0-or-later | ||
|
|
||
| DIALOG_DATADIR ?= $(FEATURESDIR)/dialog/data |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,118 @@ | ||
| #!/bin/bash | ||
| # SPDX-License-Identifier: GPL-3.0-or-later | ||
|
|
||
| if [ -z "${__dialog_sh_functions-}" ]; then | ||
| __dialog_sh_functions=1 | ||
|
|
||
| __dialog_plymouth_is_running= | ||
|
|
||
| # shellcheck disable=SC2120 | ||
| dialog_plymouth_is_running() | ||
| { | ||
| local recheck="${1-}" | ||
|
|
||
| if [ -n "$recheck" ] || [ -z "${__dialog_plymouth_is_running-}" ]; then | ||
| type -P plymouth >/dev/null && plymouth --ping 2>/dev/null && | ||
| __dialog_plymouth_is_running=1 || | ||
| __dialog_plymouth_is_running=0 | ||
| fi | ||
|
|
||
| [ "$__dialog_plymouth_is_running" = 1 ] | ||
| } | ||
|
|
||
| __ask_pass_directly() | ||
| { | ||
| local prompt tries cmd rc | ||
|
|
||
| prompt="$1"; shift | ||
| tries="$1"; shift | ||
| cmd="$1"; shift | ||
|
|
||
| ! dialog_plymouth_is_running || | ||
| plymouth hide-splash 2>/dev/null | ||
|
|
||
| rc=2 | ||
|
|
||
| while [ "$rc" != 0 ] && [ "$tries" != 0 ]; do | ||
| "$cmd" | ||
| rc="$?" | ||
| tries=$(($tries - 1)) | ||
| done | ||
|
|
||
| ! dialog_plymouth_is_running || | ||
| plymouth show-splash 2>/dev/null | ||
|
|
||
| return $rc | ||
| } | ||
|
|
||
| __ask_pass_with_unl0kr() | ||
| { | ||
| local prompt tries cmd rc | ||
|
|
||
| prompt="$1"; shift | ||
| tries="$1"; shift | ||
| cmd="$1"; shift | ||
|
|
||
| ! dialog_plymouth_is_running || | ||
| plymouth hide-splash 2>/dev/null | ||
|
|
||
| rc=2 | ||
|
|
||
| while [ "$rc" != 0 ] && [ "$tries" != 0 ]; do | ||
| unl0kr 2>/dev/null | "$cmd" | ||
| rc="$?" | ||
| tries=$(($tries - 1)) | ||
| done | ||
|
|
||
| ! dialog_plymouth_is_running || | ||
| plymouth show-splash 2>/dev/null | ||
|
|
||
| return $rc | ||
| } | ||
|
|
||
| __ask_pass_with_plymouth() | ||
| { | ||
| local prompt tries cmd | ||
|
|
||
| prompt="$1"; shift | ||
| tries="$1"; shift | ||
| cmd="$1"; shift | ||
|
|
||
| plymouth ask-for-password \ | ||
| --prompt "$prompt" \ | ||
| --number-of-tries="$tries" \ | ||
| --command="$cmd" | ||
| } | ||
|
|
||
| dialog_ask_pass() | ||
| { | ||
| local rc tries ask | ||
|
|
||
| prompt="$1"; shift | ||
| tries="$1"; shift | ||
|
|
||
| ask=__ask_pass_directly | ||
|
|
||
| ! dialog_plymouth_is_running || ask=__ask_pass_with_plymouth | ||
| ! type -P unl0kr >/dev/null || ask=__ask_pass_with_unl0kr | ||
|
|
||
| # To avoid issues with quoting arguments for the utility, a temporary | ||
| # wrapper can be created. | ||
| local cmdwrapper | ||
| cmdwrapper="/.initrd/dialog-ask-pass-$$.$BASHPID" | ||
| { | ||
| printf '#!/bin/bash\n' | ||
| printf 'exec ' | ||
| printf ' %q' "$@" | ||
| } > "$cmdwrapper" | ||
| chmod +x "$cmdwrapper" | ||
|
|
||
| rc=0 | ||
| "$ask" "$prompt" "$tries" "$cmdwrapper" || rc="$?" | ||
|
|
||
| rm -f -- "$cmdwrapper" | ||
|
|
||
| return $rc | ||
| } | ||
|
|
||
| fi # __dialog_sh_functions | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| # SPDX-License-Identifier: GPL-3.0-or-later | ||
|
|
||
| PUT_FEATURE_DIRS += $(DIALOG_DATADIR) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Too hacky, but OK.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@wladmis What exactly seems like a hack to you?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A workaround with a wrapper file to solve quoting issues, but I don't know better solution.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, this is a simple and effective way to do it. If it doesn't happen very often, I don't see anything wrong with it.