Commit 44d57497 authored by Steven Armstrong's avatar Steven Armstrong

first attempt to make this type actually work

Signed-off-by: default avatarSteven Armstrong <steven@icarus.ethz.ch>
parent 66ad2752
https://dl.bintray.com/mitchellh/consul/0.5.0_linux_amd64.zip
......@@ -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
__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
# specific version
__consul \
--install-from file:///cluster/adm/software/consul/bin/consul
--version 0.4.1
# install the consul binary to a specific location
__consul \
......
......@@ -33,33 +33,22 @@ case "$os" in
;;
esac
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
versions_dir="$__type/files/versions"
version="$(cat "$__object/parameter/version")"
version_dir="$versions_dir/$version"
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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment