fd4571d1b02ac68833a5b5c166395434723b9128

Author
Marc Cornellà <marc.cornella@live.com>
Committer
Marc Cornellà <marc.cornella@live.com>
Date

Message

installer: allow chsh to work in termux

Diff

 1diff --git a/tools/install.sh b/tools/install.sh
 2index 17b70bfea089ff5227fe5435097cddff338f3ea6..61010214ebfa3db7e6a1564a5370976f6e0b590a 100755
 3--- a/tools/install.sh
 4+++ b/tools/install.sh
 5@@ -165,29 +165,37 @@ setup_shell() {
 6 		*) echo "Invalid choice. Shell change skipped."; return ;;
 7 	esac
 8 
 9-	# Test for the right location of the "shells" file
10-	if [ -f /etc/shells ]; then
11-		shells_file=/etc/shells
12-	elif [ -f /usr/share/defaults/etc/shells ]; then # Solus OS
13-		shells_file=/usr/share/defaults/etc/shells
14-	else
15-		error "could not find /etc/shells file. Change your default shell manually."
16-		return
17-	fi
18+	# Check if we're running on Termux
19+	case "$PREFIX" in
20+		*com.termux*) termux=true; zsh=zsh ;;
21+		*) termux=false ;;
22+	esac
23 
24-	# Get the path to the right zsh binary
25-	# 1. Use the most preceding one based on $PATH, then check that it's in the shells file
26-	# 2. If that fails, get a zsh path from the shells file, then check it actually exists
27-	if ! zsh=$(which zsh) || ! grep -qx "$zsh" "$shells_file"; then
28-		if ! zsh=$(grep '^/.*/zsh$' "$shells_file" | tail -1) || [ ! -f "$zsh" ]; then
29-			error "no zsh binary found or not present in '$shells_file'"
30-			error "change your default shell manually."
31+	if [ "$termux" != true ]; then
32+		# Test for the right location of the "shells" file
33+		if [ -f /etc/shells ]; then
34+			shells_file=/etc/shells
35+		elif [ -f /usr/share/defaults/etc/shells ]; then # Solus OS
36+			shells_file=/usr/share/defaults/etc/shells
37+		else
38+			error "could not find /etc/shells file. Change your default shell manually."
39 			return
40 		fi
41+
42+		# Get the path to the right zsh binary
43+		# 1. Use the most preceding one based on $PATH, then check that it's in the shells file
44+		# 2. If that fails, get a zsh path from the shells file, then check it actually exists
45+		if ! zsh=$(which zsh) || ! grep -qx "$zsh" "$shells_file"; then
46+			if ! zsh=$(grep '^/.*/zsh$' "$shells_file" | tail -1) || [ ! -f "$zsh" ]; then
47+				error "no zsh binary found or not present in '$shells_file'"
48+				error "change your default shell manually."
49+				return
50+			fi
51+		fi
52 	fi
53 
54 	# We're going to change the default shell, so back up the current one
55-	if [ -n $SHELL ]; then
56+	if [ -n "$SHELL" ]; then
57 		echo $SHELL > ~/.shell.pre-oh-my-zsh
58 	else
59 		grep "^$USER:" /etc/passwd | awk -F: '{print $7}' > ~/.shell.pre-oh-my-zsh