Skip to content

Instantly share code, notes, and snippets.

@ueokande ueokande/bachef.sh
Last active Mar 21, 2019

Embed
What would you like to do?
Bachef - Chef like bash DSL
abort() {
>&2 echo $@
exit 1
}
declare_resources() {
for r in $@; do
eval ${r}'() { echo "['${r}']=${1:?}"; }'
done
}
_cp() { echo " - cp $@"; }
change_mode() { echo " - chmod $@"; }
change_owner() { echo " - chown $@"; }
change_group() { echo " - chgrp $@"; }
remote_file() {
target="$1"
shift
declare -A params='('"$@"')'
required_params="source"
optional_params="mode owner group"
echo "remote_file[${target}]"
for p in $required_params; do
test -z ${params[$p]} && abort "no ${p} parameter"
done
_cp "${params[source]}" "${target}"
for p in $optional_params; do
val=${params[${p}]}
test -z $val && continue
change_${p} "$val" "$target"
done
}
declare_resources source mode owner group
#!/bin/bash
source 'bachef.sh'
remote_file '/etc/nginx/nginx.conf' $(
source 'templates/nginx.conf'
mode '755'
)
remote_file '/etc/ssh/sshd_config' $(
source 'templates/nginx.conf'
mode '700'
owner 'root'
group 'root'
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.