d2379b2701df66a36b217a7707e77f8029a99814

Author
Sri Harsha Ponukumati <53646447+hponukumati@users.noreply.github.com>
Committer
GitHub <noreply@github.com>
Date

Message

chore(install): quote vars and defensive programming (#13840)

Diff

 1diff --git a/tools/install.sh b/tools/install.sh
 2index 5234c17a4d5f3e3cd2162d35ec134f77ac0632da..3eae21f9bc2297b1c62782d68402d6e7214a366b 100755
 3--- a/tools/install.sh
 4+++ b/tools/install.sh
 5@@ -51,7 +51,7 @@ USER=${USER:-$(id -u -n)}
 6 # POSIX: https://pubs.opengroup.org/onlinepubs/009696899/basedefs/xbd_chap08.html#tag_08_03
 7 HOME="${HOME:-$(getent passwd $USER 2>/dev/null | cut -d: -f6)}"
 8 # macOS does not have getent, but this works even if $HOME is unset
 9-HOME="${HOME:-$(eval echo ~$USER)}"
10+HOME="${HOME:-$(eval echo ~"$USER")}"
11 
12 
13 # Track if $ZSH was provided
14@@ -344,7 +344,7 @@ setup_zshrc() {
15       return
16     fi
17     
18-    if [ $OVERWRITE_CONFIRMATION != "no" ]; then
19+    if [ "$OVERWRITE_CONFIRMATION" != "no" ]; then
20       # Ask user for confirmation before backing up and overwriting
21       echo "${FMT_YELLOW}Found ${zdot}/.zshrc."
22       echo "The existing .zshrc will be backed up to .zshrc.pre-oh-my-zsh if overwritten."
23@@ -475,12 +475,14 @@ EOF
24   if user_can_sudo; then
25     sudo -k >/dev/null 2>&1 || true # -k forces the password prompt when supported
26     sudo chsh -s "$zsh" "$USER"
27+    chsh_status=$?
28   else
29     chsh -s "$zsh" "$USER"          # run chsh normally
30+    chsh_status=$?
31   fi
32 
33   # Check if the shell change was successful
34-  if [ $? -ne 0 ]; then
35+  if [ "$chsh_status" -ne 0 ]; then
36     fmt_error "chsh command unsuccessful. Change your default shell manually."
37   else
38     export SHELL="$zsh"