From d9eff7becef357a75d5343d244b3ec429e6d09df Mon Sep 17 00:00:00 2001 From: Arnie Date: Tue, 21 Aug 2018 18:10:08 +0200 Subject: [PATCH] Add WSL startup scripts --- ...cker-relay.sh => install-docker-in-wsl.sh} | 67 +++++++++++++++++-- 1 file changed, 62 insertions(+), 5 deletions(-) rename windows/{install-docker-relay.sh => install-docker-in-wsl.sh} (66%) diff --git a/windows/install-docker-relay.sh b/windows/install-docker-in-wsl.sh similarity index 66% rename from windows/install-docker-relay.sh rename to windows/install-docker-in-wsl.sh index bf84d7d..2609809 100755 --- a/windows/install-docker-relay.sh +++ b/windows/install-docker-in-wsl.sh @@ -1,7 +1,8 @@ #!/usr/bin/env bash installGo() { - echo "Fetching latest tags from github" + echo "Installing golang" + echo "Fetching latest tags from github..." local tags=$(curl -s https://github.com/golang/go/tags | awk '/golang\/go\/releases\/tag/{print $7}' FS='["/]') local latest="" @@ -56,11 +57,12 @@ installGo() { } installRelay() { - echo "Fetching the docker relay from github" + echo "Installing npiperelay" + echo "Fetching the relay from github" /usr/local/go/bin/go get -d github.com/jstarks/npiperelay [[ $? -ne 0 ]] && echo "Could not fetch the relay" && return 137 - echo "Building the relay for windows" + echo "Building the relay binary for windows" export GOOS=windows /usr/local/go/bin/go build -o /mnt/c/Users/${USER}/go/bin/npiperelay.exe github.com/jstarks/npiperelay [[ $? -ne 0 ]] && echo "Could not build the binary" && return 137 @@ -129,7 +131,59 @@ EOF return 0 } -createRelay() { +installDockerCompose() { + echo "Installing docker-compose" + echo "Fetching latest tags from github..." + local tags=$(curl -s https://github.com/docker/compose/tags | awk '/docker\/compose\/releases\/tag/{print $7}' FS='["/]') + + local latest="" + + if [[ ${tags} = "" ]]; then + echo "Could not fetch the tags" + return 2 + fi + + echo "Fetched the latest tags, deciding which one to use..." + + for tag in ${tags}[@]; do + tag=${tag//go} + if [[ ${tag} = *"rc"* ]]; then + continue + elif [[ ${tag} = *"beta"* ]]; then + continue + elif [[ ${tag} = *"alpha"* ]]; then + continue + fi + + echo "Found the latest tag: ${tag}" + latest=${tag} + + break + done + + if [[ "${latest}" = "" ]]; then + __err "Could not fetch the latest release" + return 2 + fi + + local compose_path=$(which docker-compose) + + which docker-compose > /dev/null 2>&1 + if [[ $? -ne 0 ]]; then + compose_path=/usr/local/bin/docker-compose + __warn "You do not seem to have docker compose installed, installing to ${compose_path}" + fi + + __msg "Installing docker-compose ${latest}" + sudo curl -L https://github.com/docker/compose/releases/download/${latest}/docker-compose-`uname -s`-`uname -m` --output "${compose_path}" && + sudo chmod +x "${compose_path}" + + [[ $? -ne 0 ]] && echo "Docker compose might be running, please close all processes before installing this version" && return 2 + + return 0 +} + +initialize() { installGo [[ $? -ne 0 ]] && echo "Could not install Go" && return 137 @@ -139,10 +193,13 @@ createRelay() { addStartupScript [[ $? -ne 0 ]] && echo "Could not add the startup script" && return 137 + installDockerCompose + [[ $? -ne 0 ]] && echo "Could not install docker compose" && return 137 + return 0 } -[[ ${1} = "" ]] && createRelay || "$@" +[[ ${1} = "" ]] && initialize || "$@" exit $?