Add WSL startup scripts

This commit is contained in:
Arnie 2018-08-21 18:10:08 +02:00
parent ba8fc9be8d
commit d9eff7bece

View File

@ -1,7 +1,8 @@
#!/usr/bin/env bash #!/usr/bin/env bash
installGo() { 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 tags=$(curl -s https://github.com/golang/go/tags | awk '/golang\/go\/releases\/tag/{print $7}' FS='["/]')
local latest="" local latest=""
@ -56,11 +57,12 @@ installGo() {
} }
installRelay() { 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 /usr/local/go/bin/go get -d github.com/jstarks/npiperelay
[[ $? -ne 0 ]] && echo "Could not fetch the relay" && return 137 [[ $? -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 export GOOS=windows
/usr/local/go/bin/go build -o /mnt/c/Users/${USER}/go/bin/npiperelay.exe github.com/jstarks/npiperelay /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 [[ $? -ne 0 ]] && echo "Could not build the binary" && return 137
@ -129,7 +131,59 @@ EOF
return 0 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 installGo
[[ $? -ne 0 ]] && echo "Could not install Go" && return 137 [[ $? -ne 0 ]] && echo "Could not install Go" && return 137
@ -139,10 +193,13 @@ createRelay() {
addStartupScript addStartupScript
[[ $? -ne 0 ]] && echo "Could not add the startup script" && return 137 [[ $? -ne 0 ]] && echo "Could not add the startup script" && return 137
installDockerCompose
[[ $? -ne 0 ]] && echo "Could not install docker compose" && return 137
return 0 return 0
} }
[[ ${1} = "" ]] && createRelay || "$@" [[ ${1} = "" ]] && initialize || "$@"
exit $? exit $?