Skip to content
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

Update the installer! #43

Merged
Merged
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 30 additions & 30 deletions doc/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,47 +6,47 @@

ZINIT_HOME="${ZINIT_HOME:-$ZPLG_HOME}"
if [ -z "$ZINIT_HOME" ]; then
ZINIT_HOME="${ZDOTDIR:-$HOME}/.zinit"
ZINIT_HOME="${XDG_DATA_HOME:-${HOME}/.local/share}/zinit"
fi

ZINIT_BIN_DIR_NAME="${ZINIT_BIN_DIR_NAME:-$ZPLG_BIN_DIR_NAME}"
if [ -z "$ZINIT_BIN_DIR_NAME" ]; then
ZINIT_BIN_DIR_NAME="bin"
ZINIT_BIN_DIR_NAME="zinit.git"
fi

if ! test -d "$ZINIT_HOME"; then
mkdir "$ZINIT_HOME"
mkdir -p "$ZINIT_HOME"
pschmitt marked this conversation as resolved.
Show resolved Hide resolved
chmod g-w "$ZINIT_HOME"
chmod o-w "$ZINIT_HOME"
fi

if ! command -v git >/dev/null 2>&1; then
echo "▓▒░ Something went wrong: no git available, cannot proceed."
echo "▓▒░ Something went wrong: git is not available, cannot proceed."
exit 1
fi

ZINIT_BRANCH="${ZINIT_BRANCH:-master}"

# Get the download-progress bar tool
GIT_PROCESS_SCRIPT_URL="https://raw.githubusercontent.com/zdharma-continuum/zinit/${ZINIT_BRANCH}/git-process-output.zsh"
mkdir -p /tmp/zinit
cd /tmp/zinit || { echo "Failed to cd to /tmp/zinit" >&2; exit 1; }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you're messing with temp directories, how about fixing the security issues?

Use TMPDIR if available with a fallback to /tmp/zinit-$UID/ and ensure you properly chmod/chown or exit if it already exists.

Copy link
Member Author

@pschmitt pschmitt Nov 13, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense to do so but a bit out of scope for this MR. Will do.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done: f4e1468

if command -v curl >/dev/null 2>&1; then
mkdir -p /tmp/zinit
cd /tmp/zinit
curl -fsSLO https://raw.githubusercontent.com/zdharma-continuum/zinit/master/git-process-output.zsh && \
chmod a+x /tmp/zinit/git-process-output.zsh
curl -fsSLO "$GIT_PROCESS_SCRIPT_URL"
elif command -v wget >/dev/null 2>&1; then
mkdir -p /tmp/zinit
cd /tmp/zinit
wget -q https://raw.githubusercontent.com/zdharma-continuum/zinit/master/git-process-output.zsh && \
chmod a+x /tmp/zinit/git-process-output.zsh
wget -q "$GIT_PROCESS_SCRIPT_URL"
fi
chmod a+x /tmp/zinit/git-process-output.zsh 2>/dev/null

echo
if test -d "$ZINIT_HOME/$ZINIT_BIN_DIR_NAME/.git"; then
cd "$ZINIT_HOME/$ZINIT_BIN_DIR_NAME"
echo "▓▒░ Updating DHARMA Initiative Plugin Manager at $ZINIT_HOME/$ZINIT_BIN_DIR_NAME"
git pull origin master
cd "$ZINIT_HOME/$ZINIT_BIN_DIR_NAME" || { echo "Failed to cd to $ZINIT_HOME/$ZINIT_BIN_DIR_NAME" >&2; exit 1; }
echo "▓▒░ Updating ZDHARMA-CONTINUUM Initiative Plugin Manager to $ZINIT_HOME/$ZINIT_BIN_DIR_NAME"
git pull origin "${ZINIT_BRANCH}"
else
cd "$ZINIT_HOME"
echo "▓▒░ Installing DHARMA Initiative Plugin Manager at $ZINIT_HOME/$ZINIT_BIN_DIR_NAME"
{ git clone --progress https://github.com/zdharma-continuum/zinit.git "$ZINIT_BIN_DIR_NAME" \
cd "$ZINIT_HOME" || { echo "Failed to cd to $ZINIT_HOME" >&2; exit 1; }
echo "▓▒░ Installing ZDHARMA-CONTINUUM Initiative Plugin Manager to $ZINIT_HOME/$ZINIT_BIN_DIR_NAME"
{ git clone --progress --branch "$ZINIT_BRANCH" https://github.com/zdharma-continuum/zinit.git "$ZINIT_BIN_DIR_NAME" \
2>&1 | { /tmp/zinit/git-process-output.zsh || cat; } } 2>/dev/null
if [ -d "$ZINIT_BIN_DIR_NAME" ]; then
echo
Expand All @@ -55,7 +55,7 @@ else
echo "▓▒░ Version: $VERSION"
else
echo
echo "▓▒░ Something went wrong, couldn't install Zinit at $ZINIT_HOME/$ZINIT_BIN_DIR_NAME"
echo "▓▒░ Something went wrong, couldn't install Zinit to $ZINIT_HOME/$ZINIT_BIN_DIR_NAME"
fi
fi

Expand All @@ -64,19 +64,19 @@ fi
#
THE_ZDOTDIR="${ZDOTDIR:-$HOME}"
RCUPDATE=1
if egrep '(zinit|zplugin)\.zsh' "$THE_ZDOTDIR/.zshrc" >/dev/null 2>&1; then
if grep -E '(zinit|zplugin)\.zsh' "$THE_ZDOTDIR/.zshrc" >/dev/null 2>&1; then
echo "▓▒░ .zshrc already contains \`zinit …' commands – not making changes."
RCUPDATE=0
fi

if [ $RCUPDATE -eq 1 ]; then
echo "▓▒░ Updating $THE_ZDOTDIR/.zshrc (10 lines of code, at the bottom)"
ZINIT_HOME="$(echo $ZINIT_HOME | sed "s|$HOME|\$HOME|")"
ZINIT_HOME="$(echo "$ZINIT_HOME" | sed "s|$HOME|\$HOME|")"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be done entirely in Zsh

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah the entire script could in zsh. What's your point?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I missed that it was in /bin/sh. My bad.

command cat <<-EOF >> "$THE_ZDOTDIR/.zshrc"

### Added by Zinit's installer
if [[ ! -f $ZINIT_HOME/$ZINIT_BIN_DIR_NAME/zinit.zsh ]]; then
print -P "%F{33}▓▒░ %F{220}Installing %F{33}DHARMA%F{220} Initiative Plugin Manager (%F{33}zdharma-continuum/zinit%F{220})…%f"
print -P "%F{33}▓▒░ %F{220}Installing %F{33}ZDHARMA-CONTINUUM%F{220} Initiative Plugin Manager (%F{33}zdharma-continuum/zinit%F{220})…%f"
command mkdir -p "$ZINIT_HOME" && command chmod g-rwX "$ZINIT_HOME"
command git clone https://github.com/zdharma-continuum/zinit "$ZINIT_HOME/$ZINIT_BIN_DIR_NAME" && \\
print -P "%F{33}▓▒░ %F{34}Installation successful.%f%b" || \\
Expand Down Expand Up @@ -105,7 +105,7 @@ echo "▓▒░ Would you like to add 4 useful plugins" \
"functions-features to the plugin manager) to the zshrc as well?" \
"It will be the following snippet:"
command cat "$file"
echo -n "▓▒░ Enter y/n and press Return: "
printf "▓▒░ Enter y/n and press Return: "
read -r input
if [ "$input" = y ] || [ "$input" = Y ]; then
command cat "$file" >> "$THE_ZDOTDIR"/.zshrc
Expand Down Expand Up @@ -141,12 +141,12 @@ command cat <<-EOF
▓▒░ run-atpull reset-prompt trackbinds aliases sh bash ksh csh

For more information see:
- The zdharma-continuum GitHub organization, which hosts zinit and all related components
- https://github.com/zdharma-continuum
- README section on the ice-modifiers:
- https://github.com/zdharma-continuum/zinit#ice-modifiers,
- intro to Zinit at the Wiki:
- https://zdharma-continuum.org/zinit/wiki/INTRODUCTION/,
- zinit-zsh GitHub account, which holds all the available Zinit annexes:
- https://github.com/zdharma-continuum/,
- For-Syntax article on the Wiki; it is less directly related to the ices, however, it explains how to use them conveniently:
- https://zdharma-continuum.org/zinit/wiki/For-Syntax/.
- https://github.com/zdharma-continuum/zinit#ice-modifiers
- An introduction to Zinit on the wiki:
- https://zdharma-continuum.github.io/zinit/wiki/INTRODUCTION/
- For-Syntax article on the wiki; it is less directly related to the ices but it explains how to use them conveniently:
- https://zdharma-continuum.github.io/zinit/wiki/For-Syntax/
EOF