#!/bin/sh # # 2015 Steven Armstrong (steven-cdist at armstrong.cc) # # This file is part of cdist. # # cdist is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # cdist is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with cdist. If not, see . # os=$(cat "$__global/explorer/os") case "$os" in centos|redhat) # whitelist safeguard : ;; *) echo "Your operating system ($os) is currently not supported by this type (${__type##*/})." >&2 echo "Please contribute an implementation for it if you can." >&2 exit 1 ;; esac state="present" conf_dir="/etc/consul-template/conf.d" conf_file="config.hcl" template_dir="/etc/consul-template/template" __directory /etc/consul-template \ --owner root --group root --mode 750 require="__directory/etc/consul-template" \ __directory "$conf_dir" \ --owner root --group root --mode 750 require="__directory/etc/consul-template" \ __directory "$template_dir" \ --owner root --group root --mode 750 __staged_file /usr/local/bin/consul-template \ --source https://github.com/hashicorp/consul-template/releases/download/v0.6.5/consul-template_0.6.5_linux_amd64.tar.gz \ --cksum '1356006333 8496656 consul-template' \ --fetch-command 'curl -s -L "%s"' \ --prepare-command 'tar -xzf "%s"; cat consul-template_*/consul-template' \ --state present \ --group root \ --owner root \ --mode 755 # Generate hcl config file ( for param in $(ls "$__object/parameter/"); do case "$param" in ssl|ssl-no-verify) # boolean key="$(echo "$param" | tr '-' '_')" printf '%s = true\n' "$key" ;; auth|batch-size|consul|max-stale|retry|token|wait) key="$(echo "$param" | tr '-' '_')" printf '%s = "%s"\n' "$key" "$(cat "$__object/parameter/$param")" ;; *) # ignore unknown parameters : ;; esac done ) | \ require="__directory${conf_dir}" \ __config_file "${conf_dir}/${conf_file}" \ --owner root --group root --mode 640 \ --state "$state" \ --onchange 'service consul-template status >/dev/null && service consul-template reload || true' \ --source - # Install init script to start on boot service="consul-template" case "$os" in centos|redhat) os_version="$(sed 's/[^0-9.]//g' "$__global/explorer/os_version")" major_version="${os_version%%.*}" case "$major_version" in 7) __file "/lib/systemd/system/${service}.service" \ --owner root --group root --mode 0555 \ --state "$state" \ --source "$__type/files/${service}.systemd" export require="__file/lib/systemd/system/${service}.service" ;; *) __file "/etc/init.d/${service}" \ --owner root --group root --mode 0555 \ --state "$state" \ --source "$__type/files/${service}.sysv" export require="__file/etc/init.d/${service}" ;; esac __start_on_boot "$service" --state "$state" ;; ubuntu) __file "/etc/init/${service}.conf" \ --owner root --group root --mode 0644 \ --state "$state" \ --source "$__type/files/${service}.upstart" export require="__file/etc/init/${service}.conf" __start_on_boot "$service" --state "$state" ;; esac