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') 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') 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 ff298365626c4366eac930793918c6fbfb8c5d9a Mon Sep 17 00:00:00 2001 From: Marc Cornellà Date: Wed, 23 Feb 2022 18:44:31 +0100 Subject: fix(updater): timeout after 2s on available update check --- tools/check_for_upgrade.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'tools') diff --git a/tools/check_for_upgrade.sh b/tools/check_for_upgrade.sh index a36aecb84..2ad1fca92 100644 --- a/tools/check_for_upgrade.sh +++ b/tools/check_for_upgrade.sh @@ -65,11 +65,11 @@ function is_update_available() { local remote_head remote_head=$( if (( ${+commands[curl]} )); then - curl -fsSL -H 'Accept: application/vnd.github.v3.sha' $api_url 2>/dev/null + curl -m 2 -fsSL -H 'Accept: application/vnd.github.v3.sha' $api_url 2>/dev/null elif (( ${+commands[wget]} )); then - wget -O- --header='Accept: application/vnd.github.v3.sha' $api_url 2>/dev/null + wget -T 2 -O- --header='Accept: application/vnd.github.v3.sha' $api_url 2>/dev/null elif (( ${+commands[fetch]} )); then - HTTP_ACCEPT='Accept: application/vnd.github.v3.sha' fetch -o - $api_url 2>/dev/null + HTTP_ACCEPT='Accept: application/vnd.github.v3.sha' fetch -T 2 -o - $api_url 2>/dev/null else exit 0 fi -- cgit v1.2.3-70-g09d2 From 0b0af4df6aab075d257d4a0dcfd1bf42318fc69a Mon Sep 17 00:00:00 2001 From: Marc Cornellà Date: Wed, 23 Feb 2022 19:23:54 +0100 Subject: fix(updater): fix check for latest commit in local repository The previous check simply compared whether the last commit of the branch was the same in the local and the remote repository. This commit also checks whether the remote commit is an ancestor of the local commit. This fixes the case where the local repository has new commits after the last published commit. --- tools/check_for_upgrade.sh | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'tools') diff --git a/tools/check_for_upgrade.sh b/tools/check_for_upgrade.sh index 2ad1fca92..76d42d388 100644 --- a/tools/check_for_upgrade.sh +++ b/tools/check_for_upgrade.sh @@ -75,8 +75,17 @@ function is_update_available() { fi ) || return 1 - # Compare local and remote HEADs - [[ "$local_head" != "$remote_head" ]] + # Compare local and remote HEADs (if they're equal there are no updates) + [[ "$local_head" != "$remote_head" ]] || return 1 + + # If local and remote HEADs don't match, check if there's a common ancestor + # If the merge-base call fails, $remote_head might not be downloaded so assume there are updates + local base + base=$(cd -q "$ZSH"; git merge-base $local_head $remote_head 2>/dev/null) || return 0 + + # If the common ancestor ($base) is not $remote_head, + # the local HEAD is older than the remote HEAD + [[ $base != $remote_head ]] } function update_last_updated_file() { -- 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') 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 af0c3b64b8c7eb6afcdabc8db89241ff72bcc66a Mon Sep 17 00:00:00 2001 From: SBado <16034687+SBado@users.noreply.github.com> Date: Fri, 4 Mar 2022 15:54:51 +0000 Subject: fix(updater): prefix `cd` with `builtin` when it is aliased (#10753) --- tools/check_for_upgrade.sh | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'tools') diff --git a/tools/check_for_upgrade.sh b/tools/check_for_upgrade.sh index 76d42d388..d3ad7582c 100644 --- a/tools/check_for_upgrade.sh +++ b/tools/check_for_upgrade.sh @@ -36,11 +36,11 @@ function current_epoch() { function is_update_available() { local branch - branch=${"$(cd -q "$ZSH"; git config --local oh-my-zsh.branch)":-master} + branch=${"$(builtin cd -q "$ZSH"; git config --local oh-my-zsh.branch)":-master} local remote remote_url remote_repo - remote=${"$(cd -q "$ZSH"; git config --local oh-my-zsh.remote)":-origin} - remote_url=$(cd -q "$ZSH"; git config remote.$remote.url) + remote=${"$(builtin cd -q "$ZSH"; git config --local oh-my-zsh.remote)":-origin} + remote_url=$(builtin cd -q "$ZSH"; git config remote.$remote.url) local repo case "$remote_url" in @@ -58,7 +58,7 @@ function is_update_available() { # Get local HEAD. If this fails assume there are updates local local_head - local_head=$(cd -q "$ZSH"; git rev-parse $branch 2>/dev/null) || return 0 + local_head=$(builtin cd -q "$ZSH"; git rev-parse $branch 2>/dev/null) || return 0 # Get remote HEAD. If no suitable command is found assume there are updates # On any other error, skip the update (connection may be down) @@ -81,7 +81,7 @@ function is_update_available() { # If local and remote HEADs don't match, check if there's a common ancestor # If the merge-base call fails, $remote_head might not be downloaded so assume there are updates local base - base=$(cd -q "$ZSH"; git merge-base $local_head $remote_head 2>/dev/null) || return 0 + base=$(builtin cd -q "$ZSH"; git merge-base $local_head $remote_head 2>/dev/null) || return 0 # If the common ancestor ($base) is not $remote_head, # the local HEAD is older than the remote HEAD @@ -170,7 +170,7 @@ function has_typed_input() { fi # Test if Oh My Zsh directory is a git repository - if ! (cd -q "$ZSH" && LANG= git rev-parse &>/dev/null); then + if ! (builtin cd -q "$ZSH" && LANG= git rev-parse &>/dev/null); then echo >&2 "[oh-my-zsh] Can't update: not a git repository." return fi -- 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') 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 4a988c46609c4c2d32240092899ae0aae45b11a6 Mon Sep 17 00:00:00 2001 From: thinszx <1217641779@qq.com> Date: Thu, 17 Mar 2022 19:54:47 +0800 Subject: fix(updater): change remote using deprecated `git:` protocol (#10779) --- tools/upgrade.sh | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'tools') diff --git a/tools/upgrade.sh b/tools/upgrade.sh index b6cb10b5a..afc6a98dd 100755 --- a/tools/upgrade.sh +++ b/tools/upgrade.sh @@ -164,6 +164,10 @@ git remote -v | while read remote url extra; do git@github.com:robbyrussell/oh-my-zsh(|.git)) git remote set-url "$remote" "git@github.com:ohmyzsh/ohmyzsh.git" break ;; + # Update out-of-date "unauthenticated git protocol on port 9418" to https + git://github.com/robbyrussell/oh-my-zsh(|.git)) + git remote set-url "$remote" "https://github.com/ohmyzsh/ohmyzsh.git" + break ;; esac done -- 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') 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