Last active
March 21, 2019 00:47
-
-
Save ueokande/0b37a673b63781e65ed3 to your computer and use it in GitHub Desktop.
Bachef - Chef like bash DSL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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