From 9b883aa4171585995475d9ddff2ef59401199b36 Mon Sep 17 00:00:00 2001 From: Marc Cornellà Date: Mon, 21 Feb 2022 20:10:18 +0100 Subject: fix(installer): set `$HOME` if not defined (#10680) Fixes #10680 --- tools/install.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'tools/install.sh') diff --git a/tools/install.sh b/tools/install.sh index e64e39063..c80c09365 100755 --- a/tools/install.sh +++ b/tools/install.sh @@ -42,13 +42,17 @@ set -e # $USER is defined by login(1) which is not always executed (e.g. containers) # POSIX: https://pubs.opengroup.org/onlinepubs/009695299/utilities/id.html USER=${USER:-$(id -u -n)} +# $HOME is defined at the time of login, but it could be unset. If it is unset, +# a tilde by itself (~) will not be expanded to the current user's home directory. +# POSIX: https://pubs.opengroup.org/onlinepubs/009696899/basedefs/xbd_chap08.html#tag_08_03 +HOME="${HOME:-$(getent passwd $USER | cut -d: -f6)}" # Track if $ZSH was provided custom_zsh=${ZSH:+yes} # Default settings -ZSH=${ZSH:-~/.oh-my-zsh} +ZSH="${ZSH:-$HOME/.oh-my-zsh}" REPO=${REPO:-ohmyzsh/ohmyzsh} REMOTE=${REMOTE:-https://github.com/${REPO}.git} BRANCH=${BRANCH:-master} -- cgit v1.2.3-70-g09d2 From 914b6399e88a16fdced427c2ae7738785dcb16b0 Mon Sep 17 00:00:00 2001 From: Marc Cornellà Date: Mon, 21 Feb 2022 20:18:58 +0100 Subject: fix(installer): silence `git init` --- tools/install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tools/install.sh') diff --git a/tools/install.sh b/tools/install.sh index c80c09365..7953ad112 100755 --- a/tools/install.sh +++ b/tools/install.sh @@ -272,7 +272,7 @@ setup_ohmyzsh() { fi # Manual clone with git config options to support git < v1.7.2 - git init "$ZSH" && cd "$ZSH" \ + git init --quiet "$ZSH" && cd "$ZSH" \ && git config core.eol lf \ && git config core.autocrlf false \ && git config fsck.zeroPaddedFilemode ignore \ -- cgit v1.2.3-70-g09d2 From c81804825c03e563ab748aae84c3f63458961208 Mon Sep 17 00:00:00 2001 From: Marc Cornellà Date: Fri, 25 Feb 2022 14:06:19 +0100 Subject: fix(installer): fix removal of OMZ directory on failure When the `git init` call fails, the directory is not created, so the rm command fails with a not found error. This change checks whether the directory exists before deleting it. --- tools/install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tools/install.sh') diff --git a/tools/install.sh b/tools/install.sh index 7953ad112..93608eb7c 100755 --- a/tools/install.sh +++ b/tools/install.sh @@ -283,7 +283,7 @@ setup_ohmyzsh() { && git remote add origin "$REMOTE" \ && git fetch --depth=1 origin \ && git checkout -b "$BRANCH" "origin/$BRANCH" || { - rm -rf "$ZSH" + [ ! -d "$ZSH" ] || rm -rf "$ZSH" 2>/dev/null fmt_error "git clone of oh-my-zsh repo failed" exit 1 } -- cgit v1.2.3-70-g09d2 From 4f0b680248e1acf71e9e557af62f3a08bb5b96c6 Mon Sep 17 00:00:00 2001 From: Marc Cornellà Date: Mon, 7 Mar 2022 11:38:48 +0100 Subject: fix(installer): fix `$HOME` setting if `getent` is not found (macOS) Related: https://github.com/ohmyzsh/ohmyzsh/pull/10713/files#r820219899 --- tools/install.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'tools/install.sh') diff --git a/tools/install.sh b/tools/install.sh index 93608eb7c..f04d0dc9c 100755 --- a/tools/install.sh +++ b/tools/install.sh @@ -45,7 +45,9 @@ USER=${USER:-$(id -u -n)} # $HOME is defined at the time of login, but it could be unset. If it is unset, # a tilde by itself (~) will not be expanded to the current user's home directory. # POSIX: https://pubs.opengroup.org/onlinepubs/009696899/basedefs/xbd_chap08.html#tag_08_03 -HOME="${HOME:-$(getent passwd $USER | cut -d: -f6)}" +HOME="${HOME:-$(getent passwd $USER 2>/dev/null | cut -d: -f6)}" +# macOS does not have getent, but this works even if $HOME is unset +HOME="${HOME:-$(eval echo ~$USER)}" # Track if $ZSH was provided -- cgit v1.2.3-70-g09d2 From 9e967b4eccbe26701315860a3b0bad01fde725c8 Mon Sep 17 00:00:00 2001 From: Marc Cornellà Date: Mon, 28 Mar 2022 16:33:03 +0200 Subject: fix(installer): exit install directory on setup (#10804) --- tools/install.sh | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'tools/install.sh') diff --git a/tools/install.sh b/tools/install.sh index f04d0dc9c..495ad2c11 100755 --- a/tools/install.sh +++ b/tools/install.sh @@ -285,10 +285,15 @@ setup_ohmyzsh() { && git remote add origin "$REMOTE" \ && git fetch --depth=1 origin \ && git checkout -b "$BRANCH" "origin/$BRANCH" || { - [ ! -d "$ZSH" ] || rm -rf "$ZSH" 2>/dev/null + [ ! -d "$ZSH" ] || { + cd - + rm -rf "$ZSH" 2>/dev/null + } fmt_error "git clone of oh-my-zsh repo failed" exit 1 } + # Exit installation directory + cd - echo } -- cgit v1.2.3-70-g09d2