Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jeffryang24/f5aaeb08fac481ebb30bfec6232bd995 to your computer and use it in GitHub Desktop.
Save jeffryang24/f5aaeb08fac481ebb30bfec6232bd995 to your computer and use it in GitHub Desktop.

Revisions

  1. @jcberthon jcberthon revised this gist Mar 5, 2018. 1 changed file with 8 additions and 1 deletion.
    9 changes: 8 additions & 1 deletion update-docker-compose.sh
    Original file line number Diff line number Diff line change
    @@ -17,6 +17,11 @@
    # It is given as a basis for building a production ready one, but you need
    # to add verifications for each stage.

    ## Quick Changelog
    # - made the script a bit more robust/safe (download the files unprivileged first
    # and "activate" them after simple verification when possible)
    # - corrected all feedback provided by [shellcheck](https://github.com/koalaman/shellcheck)

    set -eu

    function myerror {
    @@ -39,7 +44,9 @@ curl -s -L "$(echo "${files_list}" | grep "docker-compose-$(uname -s)-$(uname -m
    curl -s -L "$(echo "${files_list}" | grep "docker-compose-$(uname -s)-$(uname -m).sha256$")" \
    -o "${MYTEMPDIR}/docker-compose.sha256"

    if [ "$(sha256sum "${MYTEMPDIR}/docker-compose" | cut -c-64)" != "$(cut -c-64 "${MYTEMPDIR}/docker-compose.sha256")" ]; then
    cksum_computed="$(sha256sum "${MYTEMPDIR}/docker-compose" | cut -c-64)"
    cksum_given="$(cut -c-64 "${MYTEMPDIR}/docker-compose.sha256")"
    if [ "${cksum_computed}" != "${cksum_given}" ]; then
    myerror "ERROR: SHA256 downloaded does not match the file"
    fi

  2. @jcberthon jcberthon revised this gist Mar 5, 2018. 1 changed file with 39 additions and 9 deletions.
    48 changes: 39 additions & 9 deletions update-docker-compose.sh
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,5 @@
    #!/bin/bash
    # Copyright 2017 Jean-Christophe Berthon
    # Copyright 2017-2018 Jean-Christophe Berthon
    #
    # Licensed under the Apache License, Version 2.0 (the "License");
    # you may not use this file except in compliance with the License.
    @@ -13,24 +13,54 @@
    # See the License for the specific language governing permissions and
    # limitations under the License.

    ## WARNING: this script is NOT production ready. No checks are done.
    ## WARNING: this script is NOT production ready. A few checks are done.
    # It is given as a basis for building a production ready one, but you need
    # to add verifications for each stage.

    set -eu

    function myerror {
    echo >&2 "$@"
    exit 1
    }

    if ! MYTEMPDIR="$(mktemp -d)"; then
    MYTEMPDIR="/tmp/dc-$(dd status=none if=/dev/urandom bs=1 count=32 | sha256sum | cut -c-8)"
    mkdir "${MYTEMPDIR}" || myerror "ERROR: could not create temporary directory."
    fi


    # First download the latest release (no draft or prerelease, only full releases) of Docker Compose and
    # install it under /usr/local/bin/
    sudo curl -L $(curl -s https://api.github.com/repos/docker/compose/releases/latest | grep browser_download_url \
    | grep docker-compose-`uname -s`-`uname -m` | cut -d '"' -f 4) -o /usr/local/bin/docker-compose
    files_list="$(curl -s https://api.github.com/repos/docker/compose/releases/latest | grep browser_download_url \
    | grep "docker-compose-$(uname -s)-$(uname -m)" | cut -d '"' -f 4)"
    curl -s -L "$(echo "${files_list}" | grep "docker-compose-$(uname -s)-$(uname -m)$")" \
    -o "${MYTEMPDIR}/docker-compose"
    curl -s -L "$(echo "${files_list}" | grep "docker-compose-$(uname -s)-$(uname -m).sha256$")" \
    -o "${MYTEMPDIR}/docker-compose.sha256"

    if [ "$(sha256sum "${MYTEMPDIR}/docker-compose" | cut -c-64)" != "$(cut -c-64 "${MYTEMPDIR}/docker-compose.sha256")" ]; then
    myerror "ERROR: SHA256 downloaded does not match the file"
    fi

    # Make sure the permissions are correct
    sudo chmod 0755 /usr/local/bin/docker-compose
    chmod 0755 "${MYTEMPDIR}/docker-compose"

    # Docker Compose shall print its version information now
    /usr/local/bin/docker-compose version
    "${MYTEMPDIR}/docker-compose" version

    # (optional) Install BASH completion for Docker Compose
    sudo curl -L https://raw.githubusercontent.com/docker/compose/$(docker-compose version --short)/contrib/completion/bash/docker-compose \
    -o /etc/bash_completion.d/docker-compose
    # Install Docker Compose
    sudo mv "${MYTEMPDIR}/docker-compose" /usr/local/bin/docker-compose
    sudo chown root:root /usr/local/bin/docker-compose

    # (optional) Install BASH completion for Docker Compose
    curl -s -L "https://raw.githubusercontent.com/docker/compose/$(docker-compose version --short)/contrib/completion/bash/docker-compose" \
    -o "${MYTEMPDIR}/docker-compose"
    sudo mv "${MYTEMPDIR}/docker-compose" /etc/bash_completion.d/docker-compose
    # Make sure the permissions are correct
    sudo chmod 0644 /etc/bash_completion.d/docker-compose

    # Deleting temporary files and directories
    rm -Rf "${MYTEMPDIR}"

    exit 0
  3. @jcberthon jcberthon revised this gist Feb 24, 2017. 1 changed file with 19 additions and 0 deletions.
    19 changes: 19 additions & 0 deletions update-docker-compose.sh
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,22 @@
    #!/bin/bash
    # Copyright 2017 Jean-Christophe Berthon
    #
    # Licensed under the Apache License, Version 2.0 (the "License");
    # you may not use this file except in compliance with the License.
    # You may obtain a copy of the License at
    #
    # http://www.apache.org/licenses/LICENSE-2.0
    #
    # Unless required by applicable law or agreed to in writing, software
    # distributed under the License is distributed on an "AS IS" BASIS,
    # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    # See the License for the specific language governing permissions and
    # limitations under the License.

    ## WARNING: this script is NOT production ready. No checks are done.
    # It is given as a basis for building a production ready one, but you need
    # to add verifications for each stage.

    # First download the latest release (no draft or prerelease, only full releases) of Docker Compose and
    # install it under /usr/local/bin/
    sudo curl -L $(curl -s https://api.github.com/repos/docker/compose/releases/latest | grep browser_download_url \
  4. @jcberthon jcberthon created this gist Feb 17, 2017.
    17 changes: 17 additions & 0 deletions update-docker-compose.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    # First download the latest release (no draft or prerelease, only full releases) of Docker Compose and
    # install it under /usr/local/bin/
    sudo curl -L $(curl -s https://api.github.com/repos/docker/compose/releases/latest | grep browser_download_url \
    | grep docker-compose-`uname -s`-`uname -m` | cut -d '"' -f 4) -o /usr/local/bin/docker-compose

    # Make sure the permissions are correct
    sudo chmod 0755 /usr/local/bin/docker-compose

    # Docker Compose shall print its version information now
    /usr/local/bin/docker-compose version

    # (optional) Install BASH completion for Docker Compose
    sudo curl -L https://raw.githubusercontent.com/docker/compose/$(docker-compose version --short)/contrib/completion/bash/docker-compose \
    -o /etc/bash_completion.d/docker-compose

    # Make sure the permissions are correct
    sudo chmod 0644 /etc/bash_completion.d/docker-compose