-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update nns and sns extensions pinned version (#350)
# Motivation We haven't updated the version of the `nns` and `sns` extensions we use in some time. It's not possible to upgrade an extension, so we used to be stuck with one version but now it's at least possible to uninstall and reinstall. # Changes 1. Add `bin/dfx-software-dfx-extension-install` to hold the shared code between `bin/dfx-software-dfx-extension-nns-install` and `bin/dfx-software-dfx-extension-sns-install`. 2. Check the current installed version and uninstall if it's different from the desired version. Note that when the "latest" version is requested, we don't ask for a specific version but take what we get. We don't know ahead of time what we'll get so in this case we always uninstall first. # Tested Tested manually by installing with `--version 0.2.1`, with `--version latest` and `--version pinned`.
- Loading branch information
Showing
4 changed files
with
55 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#!/usr/bin/env bash | ||
set -euo pipefail | ||
|
||
SOURCE_DIR="$(dirname "${BASH_SOURCE[0]}")" | ||
PATH="$SOURCE_DIR:$PATH" | ||
|
||
print_help() { | ||
cat <<-EOF | ||
Installs a dfx extension. | ||
EOF | ||
} | ||
|
||
# Source the clap.bash file --------------------------------------------------- | ||
source "$SOURCE_DIR/clap.bash" | ||
# Define options | ||
clap.define short=e long=extension desc="The extension to install." variable=EXTENSION default="" | ||
clap.define short=v long=version desc="The version of the extension to install" variable=VERSION default="latest" | ||
# Source the output file ---------------------------------------------------------- | ||
source "$(clap.build)" | ||
|
||
if [[ -z "$EXTENSION" ]]; then | ||
echo "Error: --extension must be set. For example to 'nns' or 'sns'." >&2 | ||
exit 1 | ||
fi | ||
|
||
if [[ "$VERSION" = "latest" ]]; then | ||
VERSION_ARGS=() | ||
else | ||
VERSION_ARGS=("--version" "$VERSION") | ||
fi | ||
|
||
is_installed() { | ||
dfx extension list | grep -w "$EXTENSION" | ||
} | ||
|
||
get_current_version() { | ||
jq -r .version "$(dfx cache show)/extensions/$EXTENSION/extension.json" | ||
} | ||
|
||
if is_installed; then | ||
current_version="$(get_current_version)" | ||
if [[ "$current_version" = "$VERSION" ]]; then | ||
echo "$EXTENSION extension version $VERSION is already installed." | ||
exit 0 | ||
fi | ||
echo "Uninstalling current $EXTENSION extension version $current_version." | ||
dfx extension uninstall "$EXTENSION" | ||
fi | ||
|
||
dfx extension install "$EXTENSION" "${VERSION_ARGS[@]}" | ||
echo "Installed $EXTENSION dfx extension version $(get_current_version)" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters