Skip to content

Instantly share code, notes, and snippets.

@leggiero
Last active August 26, 2023 15:02
Show Gist options
  • Save leggiero/9b449030736af2464b6eaa6b1d5c1101 to your computer and use it in GitHub Desktop.
Save leggiero/9b449030736af2464b6eaa6b1d5c1101 to your computer and use it in GitHub Desktop.

Revisions

  1. leggiero revised this gist Aug 26, 2023. 1 changed file with 8 additions and 0 deletions.
    8 changes: 8 additions & 0 deletions awscli-update
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,12 @@
    #!/usr/bin/env bash
    # The MIT License (MIT)
    # Copyright 2023 Eduardo Leggiero
    #
    # Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
    #
    # The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
    #
    # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
    set -e

    if [ "$EUID" -ne 0 ]; then
  2. leggiero renamed this gist Dec 20, 2022. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  3. leggiero revised this gist Dec 20, 2022. 1 changed file with 6 additions and 7 deletions.
    13 changes: 6 additions & 7 deletions awscli-upgrade
    Original file line number Diff line number Diff line change
    @@ -1,13 +1,12 @@
    #!/usr/bin/env bash

    set -e

    if [ "$EUID" -ne 0 ]; then
    >&2 echo "Please run as root"
    exit 1
    >&2 echo "Please run as root"; exit 1
    elif ! command -v curl &>/dev/null; then
    >&2 echo "No curl command found"; exit 1
    elif ! command -v unzip &>/dev/null; then
    >&2 echo "No unzip command found"
    exit 1
    >&2 echo "No unzip command found"; exit 1
    fi

    script_file="$(basename "$(test -L "$0" && readlink "$0" || echo "$0")")"
    @@ -27,10 +26,10 @@ unzip -qq "$package_path" -d "$tmp_dir"

    if [ -d "$install_dir" ]; then
    echo "Upgrading awscli..."
    output="$(cd $tmp_dir; ./aws/install -i "$install_dir" -b "$bin_dir" --update)"
    output="$(cd "$tmp_dir"; ./aws/install -i "$install_dir" -b "$bin_dir" --update)"
    else
    echo "Installing awscli..."
    output="$(cd $tmp_dir; ./aws/install -i "$install_dir" -b "$bin_dir")"
    output="$(cd "$tmp_dir"; ./aws/install -i "$install_dir" -b "$bin_dir")"
    fi

    if [[ "$output" == "Found same AWS CLI version"* ]]; then
  4. leggiero revised this gist Dec 20, 2022. No changes.
  5. leggiero revised this gist Dec 20, 2022. 1 changed file with 1 addition and 8 deletions.
    9 changes: 1 addition & 8 deletions awscli-upgrade
    Original file line number Diff line number Diff line change
    @@ -11,11 +11,6 @@ elif ! command -v unzip &>/dev/null; then
    fi

    script_file="$(basename "$(test -L "$0" && readlink "$0" || echo "$0")")"

    # Temporary: delete previous executions
    tmp="$(dirname $(mktemp tmp.XXXXXXXXXX -ut))"
    rm -rf "$tmp/$script_file".*

    tmp_dir="$(mktemp -d -t $script_file.XXXXXX)"
    package_name="awscliv2.zip"
    package_path="$tmp_dir/$package_name"
    @@ -45,7 +40,5 @@ else
    fi
    aws --version

    echo "Done!"

    rm -rf $tmp_dir
    # echo "Keeping $tmp_dir for debug."
    echo "Done!"
  6. leggiero created this gist Dec 20, 2022.
    51 changes: 51 additions & 0 deletions awscli-upgrade
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,51 @@
    #!/usr/bin/env bash

    set -e

    if [ "$EUID" -ne 0 ]; then
    >&2 echo "Please run as root"
    exit 1
    elif ! command -v unzip &>/dev/null; then
    >&2 echo "No unzip command found"
    exit 1
    fi

    script_file="$(basename "$(test -L "$0" && readlink "$0" || echo "$0")")"

    # Temporary: delete previous executions
    tmp="$(dirname $(mktemp tmp.XXXXXXXXXX -ut))"
    rm -rf "$tmp/$script_file".*

    tmp_dir="$(mktemp -d -t $script_file.XXXXXX)"
    package_name="awscliv2.zip"
    package_path="$tmp_dir/$package_name"
    install_dir="/usr/local/aws-cli"
    bin_dir="/usr/local/bin"

    echo "Temporary download location: $tmp_dir"

    echo "Downloading awscli..."
    curl -sS "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "$package_path"

    echo "Extracting awscli..."
    unzip -qq "$package_path" -d "$tmp_dir"

    if [ -d "$install_dir" ]; then
    echo "Upgrading awscli..."
    output="$(cd $tmp_dir; ./aws/install -i "$install_dir" -b "$bin_dir" --update)"
    else
    echo "Installing awscli..."
    output="$(cd $tmp_dir; ./aws/install -i "$install_dir" -b "$bin_dir")"
    fi

    if [[ "$output" == "Found same AWS CLI version"* ]]; then
    echo "awscli already up-to-date."
    else
    echo "Installation successfull."
    fi
    aws --version

    echo "Done!"

    rm -rf $tmp_dir
    # echo "Keeping $tmp_dir for debug."