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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ease upgrade procedure #400

Merged
merged 5 commits into from
Apr 13, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions LATEST
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2.2.4
2 changes: 1 addition & 1 deletion bash_completion/kerl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ _kerl()
case $prev in
kerl)
# shellcheck disable=SC2207
COMPREPLY=($(compgen -W 'build install update list delete active path status' -- "$cur"))
COMPREPLY=($(compgen -W 'build install update upgrade list delete active path status' -- "$cur"))
;;
list)
# shellcheck disable=SC2207
Expand Down
43 changes: 43 additions & 0 deletions kerl
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ KERL_CONFIG=${KERL_CONFIG:="$HOME"/.kerlrc}
KERL_DOWNLOAD_DIR=${KERL_DOWNLOAD_DIR:="${KERL_BASE_DIR:?}"/archives}
KERL_BUILD_DIR=${KERL_BUILD_DIR:="${KERL_BASE_DIR:?}"/builds}
KERL_GIT_DIR=${KERL_GIT_DIR:="${KERL_BASE_DIR:?}"/gits}
KERL_GIT_BASE=https://raw.githubusercontent.com/kerl/kerl/master

if [ -n "$OTP_GITHUB_URL" ]; then
_OGU="$OTP_GITHUB_URL"
Expand Down Expand Up @@ -193,6 +194,7 @@ usage() {
echo ' install Install the specified release at the given location'
echo ' deploy Deploy the specified installation to the given host and location'
echo ' update Update the list of available releases from your source provider'
echo ' upgrade Upgrade kerl to the latest available version'
echo ' list List releases, builds and installations'
echo ' delete Delete builds and installations'
echo ' install-docsh Install erl shell documentation access extension - docsh'
Expand Down Expand Up @@ -1736,6 +1738,10 @@ update_usage() {
echo "usage: $0 update releases"
}

upgrade_usage() {
echo "upgrade: $0 upgrade"
}

get_active_path() {
if [ -n "$_KERL_ACTIVE_DIR" ]; then
echo "$_KERL_ACTIVE_DIR"
Expand Down Expand Up @@ -2124,6 +2130,15 @@ index caa1ce568b..6ebb3d3a25 100644
_END_PATCH
}

upgrade_kerl() {
install_folder=$1
wget -q -O "$install_folder/kerl" $KERL_GIT_BASE/kerl
Copy link
Collaborator

Choose a reason for hiding this comment

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

We use curl everywhere else in the script currently, can we please use it here too instead of adding a new dependency on wget.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure 馃憤

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done in 2d2912a

chmod +x "$install_folder/kerl"
version=$(kerl version)
current_kerl_path="$(which kerl)"
echo "kerl $version is now available at $current_kerl_path."
}

case "$1" in
version)
echo "$KERL_VERSION"
Expand Down Expand Up @@ -2215,6 +2230,34 @@ case "$1" in
;;
esac
;;
upgrade)
if [ $# -ne 1 ]; then
upgrade_usage
exit 1
fi
current_kerl_path="$(which kerl)"
which_status=$?
if [ $which_status != 0 ]; then
install_folder="/usr/local/bin"
Copy link
Collaborator

Choose a reason for hiding this comment

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

This should probably be its own environment variable or otherwise settable to a directory from the command line. (For example, I install my kerl at $HOME/bin/kerl)

Copy link
Contributor

Choose a reason for hiding this comment

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

Current kerl is $0 ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jadeallenx, agreed. If not set, would the current choice (/usr/local/bin) be acceptable as a default? Should we document this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Current kerl is $0 ?

I didn't understand this, sorry. $0 is "current script".

Here (in this place in the code), we're covering the option where kerl is not yet "installed" anywhere (eg. local Git repo), so @jadeallenx's suggestion makes sense, but maybe I missed something (?)

echo "kerl not installed. Dropping it into $install_folder/kerl..."
upgrade_kerl $install_folder
else
version=$(kerl version)
echo "local kerl found ($current_kerl_path) at version $version."
latest=$(curl -s $KERL_GIT_BASE/LATEST)
echo "remote kerl found at version $latest."
if [ "$version" != "$latest" ]; then
echo "Versions are different. Upgrading to $latest."
current_kerl_path=$(dirname "$current_kerl_path")
upgrade_kerl "$current_kerl_path"
else
echo "No upgrade required."
fi
printf "Updating list of available releases... "
kerl update releases > /dev/null
echo "Done!"
fi
;;
list)
if [ $# -ne 2 ]; then
list_usage
Expand Down
1 change: 1 addition & 0 deletions zsh_completion/_kerl
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ _1st_arguments=(
'install:Install the specified release at the given location'
'deploy:Deploy the specified installation to the given host and location'
'update:Update the list of available releases from erlang.org'
'upgrade:Upgrade kerl to the latest available version'
'list:List releases, builds and installations'
'delete:Delete builds and installations'
'active:Print the path of the active installation'
Expand Down