From 7739d84fa70fdae203fabb7b5278fd6af976e3ce Mon Sep 17 00:00:00 2001 From: stefanprodan Date: Thu, 30 Apr 2020 22:21:52 +0300 Subject: [PATCH] Add CLI install instruction and script --- README.md | 2 ++ install/README.md | 37 ++++++++++++++++++++++++++++++++++ install/tk.sh | 51 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 90 insertions(+) create mode 100644 install/README.md create mode 100755 install/tk.sh diff --git a/README.md b/README.md index 1ff3b168..5cd9d1c1 100644 --- a/README.md +++ b/README.md @@ -8,3 +8,5 @@ Components: * [Toolkit CLI](docs/cmd/tk.md) * [Source Controller](https://github.com/fluxcd/source-controller) * [Kustomize Controller](https://github.com/fluxcd/kustomize-controller) + +To install the toolkit CLI, see these [instructions](install/README.md). diff --git a/install/README.md b/install/README.md new file mode 100644 index 00000000..50f6eb33 --- /dev/null +++ b/install/README.md @@ -0,0 +1,37 @@ +# TK CLI Installation + +Binaries for macOS and Linux AMD64 are available for download on the +[release page](https://github.com/fluxcd/toolkit/releases). + +To install the latest release run: + +```bash +curl -s https://raw.githubusercontent.com/fluxcd/toolkit/master/install/tk.sh | sudo bash +``` + +The install script does the following: +* attempts to detect your OS +* downloads and unpacks the release tar file in a temporary directory +* copies the tk binary to `/usr/local/bin` +* removes the temporary directory + +## Build from source + +Clone the repository: + +```bash +git clone https://github.com/fluxcd/toolkit +cd toolkit +``` + +Build the tk binary (requires go >= 1.14): + +```bash +make build +``` + +Run the binary: + +```bash +./bin/tk -h +``` diff --git a/install/tk.sh b/install/tk.sh new file mode 100755 index 00000000..f16a2a1a --- /dev/null +++ b/install/tk.sh @@ -0,0 +1,51 @@ +#!/usr/bin/env bash + +set -e + +DEFAULT_BIN_DIR="/usr/local/bin" +BIN_DIR=${1:-"$DEFAULT_BIN_DIR"} + +opsys="" +if [[ "$OSTYPE" == linux* ]]; then + opsys=linux +elif [[ "$OSTYPE" == darwin* ]]; then + opsys=darwin +fi + +if [[ "$opsys" == "" ]]; then + echo "OS $OSTYPE not supported" + exit 1 +fi + +if [[ ! -x "$(command -v curl)" ]]; then + echo "curl not found" + exit 1 +fi + +tmpDir=`mktemp -d` +if [[ ! "$tmpDir" || ! -d "$tmpDir" ]]; then + echo "could not create temp dir" + exit 1 +fi + +function cleanup { + rm -rf "$tmpDir" +} + +trap cleanup EXIT + +pushd $tmpDir >& /dev/null + +curl -s https://api.github.com/repos/fluxcd/toolkit/releases/latest |\ + grep browser_download |\ + grep $opsys |\ + cut -d '"' -f 4 |\ + xargs curl -sL -o tk.tar.gz + +tar xzf ./tk.tar.gz + +mv ./tk $BIN_DIR + +popd >& /dev/null + +echo "$(tk --version) installed"