Created
October 24, 2018 07:40
-
-
Save hongkongkiwi/b62a9bf8c89d3a07414c3b58bc2ae553 to your computer and use it in GitHub Desktop.
Easily install or upgrade docker-compose on any system!
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
#!/bin/sh | |
COMPOSE_PATH="/usr/local/bin/docker-compose" | |
if `command -v "docker-compose" >/dev/null 2>&1`; then | |
CURRENT_VERSION=`docker-compose -v | sed 's|.*version \([0-9\.]*\).*|\1|'` | |
if [[ ! -f "$COMPOSE_PATH" ]]; then | |
echo "WARNING" | |
echo "Looks like docker-compose is not residing in $COMPOSE_PATH" | |
echo "This is OK, but make sure that your path variable has /usr/local/bin first to make sure you are running the latest" | |
echo 'e.g. export PATH="$PATH:/usr/local/bin"' | |
echo | |
fi | |
else | |
CURRENT_VERSION="" | |
fi | |
get_latest_release() { | |
curl --silent "https://api.github.com/repos/$1/releases/latest" | # Get latest release from GitHub api | |
grep '"tag_name":' | # Get tag line | |
sed -E 's/.*"([^"]+)".*/\1/' # Pluck JSON value | |
} | |
echo "Checking for latest docker-compose version..." | |
COMPOSE_RELEASE=`get_latest_release "docker/compose"` | |
if [[ "$CURRENT_VERSION" == "$COMPOSE_RELEASE" ]]; then | |
echo "You already have compose installed and it is the latest version ($CURRENT_VERSION)" | |
exit 0 | |
elif [[ "$CURRENT_VERSION" == "" ]]; then | |
echo "Compose is not installed. Downloading latest version $COMPOSE_RELEASE" | |
else | |
echo "Compose is isntalled but it is an old version ($CURRENT_VERSION). Upgrading latest version $COMPOSE_RELEASE" | |
fi | |
curl -L https://github.com/docker/compose/releases/download/${COMPOSE_RELEASE}/docker-compose-`uname -s`-`uname -m` -o "$COMPOSE_PATH" | |
chmod +x "$COMPOSE_PATH" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment