-
Notifications
You must be signed in to change notification settings - Fork 159
fix(scripts/login.in): don't canonicalize symlink value #179
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
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 |
|---|---|---|
| @@ -1,44 +1,77 @@ | ||
| #!/bin/sh | ||
| # shellcheck shell=dash | ||
|
|
||
| set -e -u | ||
| set -eu | ||
|
|
||
| show_usage () { | ||
| is_executable_file() { | ||
| test -f "$1" -a -x "$1" | ||
| } | ||
|
|
||
| show_usage() { | ||
| echo "usage: chsh [-s shell]" | ||
| echo "Change the login shell." | ||
| echo | ||
| if [ "${1:-}" = "login" ]; then | ||
| echo "The shell value must be one of following and cannot be 'login':" | ||
| else | ||
| echo "The shell value must be one of following:" | ||
| fi | ||
| echo " - Empty value to restore default shell." | ||
| echo " - Absolute path to shell starting with a '/'." | ||
| echo " - Relative path to shell not starting with a '/' relative to '@TERMUX_PREFIX@/bin'." | ||
| } | ||
|
|
||
| set_shell () { | ||
| if [ "$1" = login ]; then | ||
| echo "login is not a valid shell" | ||
| set_shell() { | ||
| if [ -z "${1:-}" ]; then | ||
| echo "Restoring default shell" | ||
| rm -f "$HOME/.termux/shell" | ||
| exit 0 | ||
| fi | ||
|
|
||
| if [ "$1" = "login" ]; then | ||
| show_usage "login" | ||
| exit 1 | ||
| fi | ||
| mkdir -p $HOME/.termux | ||
| NEW_SHELL=@TERMUX_PREFIX@/bin/$1 | ||
| if test -x $NEW_SHELL -a ! -d $NEW_SHELL; then | ||
candrew66 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ln -f -s $NEW_SHELL $HOME/.termux/shell | ||
| else | ||
| echo "$NEW_SHELL is not an executable file!" | ||
candrew66 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| mkdir -p "$HOME/.termux" | ||
|
|
||
| unset NEW_SHELL | ||
| case "$1" in | ||
| "/"*) NEW_SHELL="$1" ;; | ||
| *) NEW_SHELL="@TERMUX_PREFIX@/bin/$1" ;; | ||
| esac | ||
|
|
||
| SHELL_TARGET="$(realpath -s "$NEW_SHELL")" | ||
|
|
||
| if ! is_executable_file "$SHELL_TARGET"; then | ||
| echo "The shell file '$SHELL_TARGET' is not an executable file." 1>&2 | ||
| exit 1 | ||
| fi | ||
candrew66 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| if [ "$SHELL_TARGET" -ef "@TERMUX_PREFIX@/bin/login" ]; then | ||
| echo "The shell file '$SHELL_TARGET' must not point to the '@TERMUX_PREFIX@/bin/login' script." 1>&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| ln -sf "$SHELL_TARGET" "$HOME/.termux/shell" | ||
| } | ||
|
|
||
| O=`getopt -l help -- hs: "$@"` | ||
| eval set -- "$O" | ||
| while true; do | ||
| case "$1" in | ||
| -h|--help) show_usage; exit 0;; | ||
| -s) set_shell $2; exit 0;; | ||
| -s) set_shell "$2"; exit 0;; | ||
| --) shift; break;; | ||
| *) echo Error; show_usage; exit 1;; | ||
| esac | ||
| done | ||
|
|
||
| DEFAULT_SHELL=bash | ||
| if [ ! -x @TERMUX_PREFIX@/bin/$DEFAULT_SHELL ]; then DEFAULT_SHELL=sh; fi | ||
| if ! is_executable_file "@TERMUX_PREFIX@/bin/$DEFAULT_SHELL"; then DEFAULT_SHELL=sh; fi | ||
|
|
||
| echo Changing the login shell | ||
| echo Enter the new value, or press ENTER for the default | ||
| printf " Login Shell [$DEFAULT_SHELL]: " | ||
| read shell | ||
|
|
||
| if [ -z "$shell" ]; then shell=$DEFAULT_SHELL; fi | ||
| set_shell $shell | ||
| set_shell "$shell" | ||
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.
Uh oh!
There was an error while loading. Please reload this page.