From 44d57497e08fe125586785f941962a6d7613d58c Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Tue, 24 Feb 2015 23:05:25 +0100 Subject: [PATCH] first attempt to make this type actually work Signed-off-by: Steven Armstrong --- .../type/__consul/files/versions/0.4.1/cksum | 1 + .../versions/0.4.1/source} | 0 .../type/__consul/files/versions/0.5.0/cksum | 1 + .../type/__consul/files/versions/0.5.0/source | 1 + cdist/conf/type/__consul/man.text | 34 ++++++--------- cdist/conf/type/__consul/manifest | 43 +++++++------------ .../type/__consul/parameter/default/version | 1 + cdist/conf/type/__consul/parameter/optional | 2 +- 8 files changed, 33 insertions(+), 50 deletions(-) create mode 100644 cdist/conf/type/__consul/files/versions/0.4.1/cksum rename cdist/conf/type/__consul/{parameter/default/install-from => files/versions/0.4.1/source} (100%) create mode 100644 cdist/conf/type/__consul/files/versions/0.5.0/cksum create mode 100644 cdist/conf/type/__consul/files/versions/0.5.0/source create mode 100644 cdist/conf/type/__consul/parameter/default/version diff --git a/cdist/conf/type/__consul/files/versions/0.4.1/cksum b/cdist/conf/type/__consul/files/versions/0.4.1/cksum new file mode 100644 index 00000000..edba1a68 --- /dev/null +++ b/cdist/conf/type/__consul/files/versions/0.4.1/cksum @@ -0,0 +1 @@ +428915666 15738724 consul diff --git a/cdist/conf/type/__consul/parameter/default/install-from b/cdist/conf/type/__consul/files/versions/0.4.1/source similarity index 100% rename from cdist/conf/type/__consul/parameter/default/install-from rename to cdist/conf/type/__consul/files/versions/0.4.1/source diff --git a/cdist/conf/type/__consul/files/versions/0.5.0/cksum b/cdist/conf/type/__consul/files/versions/0.5.0/cksum new file mode 100644 index 00000000..fe9888ae --- /dev/null +++ b/cdist/conf/type/__consul/files/versions/0.5.0/cksum @@ -0,0 +1 @@ +131560372 17734417 consul diff --git a/cdist/conf/type/__consul/files/versions/0.5.0/source b/cdist/conf/type/__consul/files/versions/0.5.0/source new file mode 100644 index 00000000..00a209a5 --- /dev/null +++ b/cdist/conf/type/__consul/files/versions/0.5.0/source @@ -0,0 +1 @@ +https://dl.bintray.com/mitchellh/consul/0.5.0_linux_amd64.zip diff --git a/cdist/conf/type/__consul/man.text b/cdist/conf/type/__consul/man.text index f91dcf5c..25d8565f 100644 --- a/cdist/conf/type/__consul/man.text +++ b/cdist/conf/type/__consul/man.text @@ -10,34 +10,28 @@ cdist-type__consul - install consul DESCRIPTION ----------- -Quick and dirty installation of the consul binary. -Note that the consul binary is downloaded on the server and then deployed using -the __file type. +Downloads and installs the consul binary from https://dl.bintray.com/mitchellh/consul. +Note that the consul binary is downloaded on the server (the machine running +cdist) and then deployed to the target host using the __file type. -Future ideas: -- get latest version info from https://checkpoint-api.hashicorp.com/v1/check/consul - - then download from - https://dl.bintray.com/mitchellh/consul/${current_version}_${os}_${arch}.zip -- install from given path to binary -- download from given url -- install from packet +REQUIRED PARAMETERS +------------------- +None. OPTIONAL PARAMETERS ------------------- -install-from:: - uri from where to download consul. This can be anything that curl understands. - If install-uri ends with .zip the downloaded file will be unziped and the - contained file deployed as the consul binary. If install-uri does not end in .zip - it is assumed to be the consul binary and will be deployed as is. - install-to:: where to install the binary. Defaults to /usr/local/bin/consul state:: either 'present' or 'absent'. Defaults to 'present' +version:: + which version of consul to install. See ./files/versions for a list of + supported versions. Defaults to the latest known version. + EXAMPLES -------- @@ -46,13 +40,9 @@ EXAMPLES # just install using defaults __consul -# download on the machine running cdist, then unzip, then upload to the target host +# specific version __consul \ - --install-from https://dl.bintray.com/mitchellh/consul/0.4.1_linux_amd64.zip - -# take binary from local folder on the machine running cdist -__consul \ - --install-from file:///cluster/adm/software/consul/bin/consul + --version 0.4.1 # install the consul binary to a specific location __consul \ diff --git a/cdist/conf/type/__consul/manifest b/cdist/conf/type/__consul/manifest index 321a3e4c..d32009c4 100755 --- a/cdist/conf/type/__consul/manifest +++ b/cdist/conf/type/__consul/manifest @@ -33,33 +33,22 @@ case "$os" in ;; esac +versions_dir="$__type/files/versions" +version="$(cat "$__object/parameter/version")" +version_dir="$versions_dir/$version" -state="$(cat "$__object/parameter/state")" -install_from="$(cat "$__object/parameter/install-from")" -install_to="$(cat "$__object/parameter/install-to")" - -if [ "$state" = "absent" ]; then - __file "$install_to" \ - --state absent - exit 0 +if [ ! -d "$version_dir" ]; then + echo "Unknown consul version '$version'. Expected one of:" >&2 + ls "$versions_dir" >&2 + exit 1 fi -case "$install_from" in - /*|file://*) - source="${install_from#*file://}" - ;; - *.zip) - mkdir "$__object/files" - source="$__object/files/consul" - # FIXME: need some persistent place to cache downloaded files - curl -s "$install_from" | unzip -p > "$source" - ;; - *) - echo "Do not know how to install from: $install_from" >&2 - exit 1 - ;; -esac - -__file "$install_to" \ - --owner root --group root --mode 755 \ - --source "$source" +__staged_file "$(cat "$__object/parameter/install-to")" \ + --source "$(cat "$version_dir/source")" \ + --cksum "$(cat "$version_dir/cksum")" \ + --fetch-command 'curl -s -L "%s"' \ + --prepare-command 'unzip -p "%s"' \ + --state "$(cat "$__object/parameter/state")" \ + --group root \ + --owner root \ + --mode 755 diff --git a/cdist/conf/type/__consul/parameter/default/version b/cdist/conf/type/__consul/parameter/default/version new file mode 100644 index 00000000..8f0916f7 --- /dev/null +++ b/cdist/conf/type/__consul/parameter/default/version @@ -0,0 +1 @@ +0.5.0 diff --git a/cdist/conf/type/__consul/parameter/optional b/cdist/conf/type/__consul/parameter/optional index 480f1bcd..ca68058b 100644 --- a/cdist/conf/type/__consul/parameter/optional +++ b/cdist/conf/type/__consul/parameter/optional @@ -1,3 +1,3 @@ -install-from install-to state +version