Skip to content

Commit

Permalink
fix: ensure update-prompt can use release channels
Browse files Browse the repository at this point in the history
* fix an issue where update-prompt using a git-ref (version) based on
  tag, sha, or branch can be successfully installed
* add an interrupt trap to install and update-prompt to more reliably
  cancel the operation
* do not change directory to perform install
  • Loading branch information
dmccaffery committed Dec 16, 2020
1 parent 5137c12 commit 34633dc
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 40 deletions.
20 changes: 8 additions & 12 deletions bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -69,31 +69,27 @@ __am_prompt_update()

# print latest version already installed
if [ "${PROMPT_SHA}" = "${PROMPT_CURRENT_SHA}" ]; then
echo "${CLR_SUCCESS}prompt: latest version already installed: ${PROMPT_SHA}.${CLR_CLEAR}"
echo "${CLR_SUCCESS}prompt: latest version already installed: ${PROMPT_SHA}"
echo " - run update-prompt with the --force flag to reinstall ${CLR_CLEAR}"
exit 0
fi
fi

if [ ! -z "${PROMPT_DRY_RUN:-}" ]; then
echo "${CLR_WARN}prompt: a new version of prompt is available: ${PROMPT_SHA}."
echo "${CLR_WARN}prompt: a new version of prompt is available: ${PROMPT_SHA}"
echo " - run the update-prompt command line tool to upgrade${CLR_CLEAR}"
return 0
fi

local PROMPT_INSTALL_URI="https://github.com/automotiveMastermind/prompt/archive/$PROMPT_COMMIT_REF.tar.gz"
local PROMPT_INTALL_TEMP=$(mktemp -d)
local PROMPT_EXTRACT_TEMP="$PROMPT_INTALL_TEMP/extract"
local PROMPT_INSTALL_TEMP=$(mktemp -d)

local CURRENT_DIR=${PWD}
curl -skLo $PROMPT_INSTALL_TEMP/prompt.tgz $PROMPT_INSTALL_URI
tar -xzf $PROMPT_INSTALL_TEMP/prompt.tgz --strip-components=1 --directory=$PROMPT_INSTALL_TEMP

cd $PROMPT_INTALL_TEMP 1>/dev/null
curl -skL $PROMPT_INSTALL_URI | tar zx
cd prompt-master 1>/dev/null
./install.sh $PROMPT_SHELL
cd $CURRENT_DIR

rm -rf $PROMPT_INTALL_TEMP 1>/dev/null
. "$PROMPT_INSTALL_TEMP/install.sh" $PROMPT_SHELL
}

trap 'echo; echo; echo "${CLR_WARN}prompt: terminating update...${CLR_CLEAR}"; exit -1;' INT

__am_prompt_update $@
33 changes: 20 additions & 13 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

set -e

SCRIPT_DIR=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd -P)

CLR_SUCCESS="\033[1;32m" # BRIGHT GREEN
CLR_WARN="\033[1;33m" # BRIGHT YELLOW
CLR_CLEAR="\033[0m" # DEFAULT COLOR
Expand Down Expand Up @@ -46,25 +48,25 @@ __am_prompt_install() {
cp -R $AM_PROMPT/* "$BACKUP_PATH" 1>/dev/null

__am_prompt_success "removing $AM_PROMPT"
rm -rf "$AM_PROMPT/bash" 1>/dev/null 2>&1
rm -rf "$AM_PROMPT/sh" 1>/dev/null 2>&1
rm -rf "$AM_PROMPT/zsh" 1>/dev/null 2>&1
rm -rf "$AM_PROMPT/themes" 1>/dev/null 2>&1
rm -rf "$AM_PROMPT/bash" 1>/dev/null 2>&1
rm -rf "$AM_PROMPT/sh" 1>/dev/null 2>&1
rm -rf "$AM_PROMPT/zsh" 1>/dev/null 2>&1
rm -rf "$AM_PROMPT/themes" 1>/dev/null 2>&1

# remove legacy paths
rm -rf "$AM_PROMPT/completions" 1>/dev/null 2>&1
rm -rf "$AM_PROMPT/scripts" 1>/dev/null 2>&1
rm -f "$AM_PROMPT/bashrc" 1>/dev/null 2>&1
rm -rf "$AM_PROMPT/scripts" 1>/dev/null 2>&1
rm -f "$AM_PROMPT/bashrc" 1>/dev/null 2>&1
fi

__am_prompt_success "creating $AM_PROMPT"
mkdir -p "$AM_PROMPT/user" 1>/dev/null 2>&1

__am_prompt_success "installing promptMastermind to $AM_PROMPT"
cp -Rf src/bash "$AM_PROMPT" 1>/dev/null
cp -Rf src/sh "$AM_PROMPT" 1>/dev/null
cp -Rf src/zsh "$AM_PROMPT" 1>/dev/null
cp -Rf src/themes "$AM_PROMPT" 1>/dev/null
cp -Rf "$SCRIPT_DIR/src/bash" "$AM_PROMPT" 1>/dev/null
cp -Rf "$SCRIPT_DIR/src/sh" "$AM_PROMPT" 1>/dev/null
cp -Rf "$SCRIPT_DIR/src/zsh" "$AM_PROMPT" 1>/dev/null
cp -Rf "$SCRIPT_DIR/src/themes" "$AM_PROMPT" 1>/dev/null

for USER_ITEM in src/user/*; do
local USER_ITEM_NAME=$(basename "$USER_ITEM")
Expand Down Expand Up @@ -120,7 +122,6 @@ __am_prompt_install() {

local PROMPT_SHA=$(cat VERSION)
local PROMPT_SHA_PATH=$HOME/.am/prompt/.sha
local PROMPT_CHANGELOG_URL="https://github.com/automotivemastermind/prompt/blob/$PROMPT_SHA/CHANGELOG.md"

echo $PROMPT_SHA > $PROMPT_SHA_PATH

Expand All @@ -145,10 +146,16 @@ __am_prompt_install() {
local PROMPT_SHELL=$(echo $PROMPT_SHELL | tr '[:upper:]' '[:lower:]')

# use the correct shell
. $AM_PROMPT/sh/scripts/use-shell $PROMPT_SHELL
. "$AM_PROMPT/sh/scripts/use-shell" $PROMPT_SHELL

# open the changelog url
. $AM_PROMPT/sh/scripts/open-url $PROMPT_CHANGELOG_URL
. "$AM_PROMPT/sh/scripts/open-url" "https://github.com/automotivemastermind/prompt/blob/$PROMPT_SHA/CHANGELOG.md"
}

echo
echo "${CLR_WARN}prompt: establishing sudo (you may be prompted for credentials)...${CLR_CLEAR}"
sudo echo

trap 'echo; echo; echo "${CLR_WARN}prompt: terminating install...${CLR_CLEAR}"; exit -1;' INT

__am_prompt_install $@
24 changes: 9 additions & 15 deletions src/sh/scripts/update-prompt
Original file line number Diff line number Diff line change
Expand Up @@ -69,33 +69,27 @@ __am_prompt_update()

# print latest version already installed
if [ "${PROMPT_SHA}" = "${PROMPT_CURRENT_SHA}" ]; then
echo "${CLR_SUCCESS}prompt: latest version already installed: ${PROMPT_SHA}.${CLR_CLEAR}"
echo "${CLR_SUCCESS}prompt: latest version already installed: ${PROMPT_SHA}"
echo " - run update-prompt with the --force flag to reinstall ${CLR_CLEAR}"
exit 0
fi
fi

if [ ! -z "${PROMPT_DRY_RUN:-}" ]; then
echo "${CLR_WARN}prompt: a new version of prompt is available: ${PROMPT_SHA}."
echo "${CLR_WARN}prompt: a new version of prompt is available: ${PROMPT_SHA}"
echo " - run the update-prompt command line tool to upgrade${CLR_CLEAR}"
return 0
fi

remove-backup

local PROMPT_CHANGELOG_URI="https://github.com/automotivemastermind/prompt/blob/$PROMPT_COMMIT_REF/CHANGELOG.md"
local PROMPT_INSTALL_URI="https://github.com/automotiveMastermind/prompt/archive/$PROMPT_COMMIT_REF.tar.gz"
local PROMPT_INTALL_TEMP=$(mktemp -d)
local PROMPT_EXTRACT_TEMP="$PROMPT_INTALL_TEMP/extract"

local CURRENT_DIR=${PWD}
local PROMPT_INSTALL_TEMP=$(mktemp -d)

cd $PROMPT_INTALL_TEMP 1>/dev/null
curl -skL $PROMPT_INSTALL_URI | tar zx
cd prompt-master 1>/dev/null
./install.sh $PROMPT_SHELL
cd $CURRENT_DIR
curl -skLo $PROMPT_INSTALL_TEMP/prompt.tgz $PROMPT_INSTALL_URI
tar -xzf $PROMPT_INSTALL_TEMP/prompt.tgz --strip-components=1 --directory=$PROMPT_INSTALL_TEMP

rm -rf $PROMPT_INTALL_TEMP 1>/dev/null
. "$PROMPT_INSTALL_TEMP/install.sh" $PROMPT_SHELL
}

trap 'echo; echo; echo "${CLR_WARN}prompt: terminating update...${CLR_CLEAR}"; exit -1;' INT

__am_prompt_update $@

0 comments on commit 34633dc

Please sign in to comment.