Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
offline installer
Browse files Browse the repository at this point in the history
ianchen-tw committed Nov 25, 2022

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent ea86f71 commit 850c842
Showing 2 changed files with 74 additions and 12 deletions.
4 changes: 1 addition & 3 deletions bin/pyenv-installer
Original file line number Diff line number Diff line change
@@ -7,7 +7,6 @@ if [ -z "$PYENV_ROOT" ]; then
export PYENV_ROOT="${HOME}/.pyenv"
fi

OS="$(uname -s)"
SRC_WRITTEN=false

colorize() {
@@ -73,6 +72,7 @@ write_source() {
}

add_userpath() {
OS="$(uname -s)"
CURRENT_SHELL="$(basename "$SHELL")"

if [[ "$OS" = "Darwin" ]]; then
@@ -110,7 +110,6 @@ add_userpath() {
}

if ! command -v pyenv 1>/dev/null; then

add_userpath

if ${SRC_WRITTEN}; then
@@ -127,5 +126,4 @@ if ! command -v pyenv 1>/dev/null; then
"${PYENV_ROOT}/bin/pyenv" virtualenv-init || true
} >&2
fi

fi
82 changes: 73 additions & 9 deletions bin/pyenv-offline-installer
Original file line number Diff line number Diff line change
@@ -7,6 +7,8 @@ if [ -z "$PYENV_ROOT" ]; then
PYENV_ROOT="${HOME}/.pyenv"
fi

SRC_WRITTEN=false

colorize() {
if [ -t 1 ]; then printf "\e[%sm%s\e[m" "$1" "$2"
else echo -n "$2"
@@ -60,16 +62,78 @@ conditional_mv "$TMP_DIR/pyenv-which-ext" "${PYENV_ROOT}/plugins/pyenv-which-ex

rm -rf $TMP_DIR

write_source() {
{
echo "Appending the following lines to $1:"
echo ' # pyenv'
echo ' export PATH="'"$PYENV_ROOT/bin:"'$PATH"'
echo ' eval "$(pyenv init --path)"'
echo ' eval "$(pyenv virtualenv-init -)"'
echo ''
} >&2

echo "" >>$1
echo '# pyenv' >>$1
echo 'export PATH="'"$PYENV_ROOT/bin:"'$PATH"' >>$1
echo 'eval "$(pyenv init --path)"' >>$1
echo 'eval "$(pyenv virtualenv-init -)"' >>$1

SRC_WRITTEN=true
}

add_userpath() {
OS="$(uname -s)"
CURRENT_SHELL="$(basename "$SHELL")"

if [[ "$OS" = "Darwin" ]]; then
if [[ "$CURRENT_SHELL" = "zsh" ]]; then
write_source "$HOME/.zprofile"
elif [[ "$CURRENT_SHELL" = "bash" ]]; then
write_source "$HOME/.bash_profile"
fi

elif [[ "$CURRENT_SHELL" = "zsh" ]]; then
# write to first match: zshrc/zprofile
if [[ -f $HOME/.zshrc ]]; then
write_source "$HOME/.zshrc"
elif [[ -f $HOME/.zprofile ]]; then
write_source "$HOME/.zprofile"
fi

elif [[ "$CURRENT_SHELL" = "bash" ]]; then
# bashrc
write_source "$HOME/.bashrc"

# write to first match: profile/bash_profile
if [[ -f $HOME/.profile ]]; then
write_source "$HOME/.profile"
elif [[ -f $HOME/.bash_profile ]]; then
write_source "$HOME/.bash_profile"
fi

else
{
echo "Add userpath for $CURRENT_SHELL is not currently supported"
echo "Please set up manually"
} >&2
fi
}

if ! command -v pyenv 1>/dev/null; then
{ echo
colorize 1 "WARNING"
echo ": seems you still have not added 'pyenv' to the load path."
echo
} >&2
add_userpath

{ # Without args, `init` commands print installation help
"${PYENV_ROOT}/bin/pyenv" init || true
"${PYENV_ROOT}/bin/pyenv" virtualenv-init || true
} >&2
if ${SRC_WRITTEN}; then
echo "Close and reopen your terminal to start using pyenv" >&2
else
{ echo
colorize 1 "WARNING"
echo ": seems you still have not added 'pyenv' to the load path."
echo
} >&2

{ # Without args, `init` commands print installation help
"${PYENV_ROOT}/bin/pyenv" init || true
"${PYENV_ROOT}/bin/pyenv" virtualenv-init || true
} >&2
fi
fi

0 comments on commit 850c842

Please sign in to comment.