posix-shell config management?
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100# install a file, set permissions, and update# the apk reposmkdir -p /etc/apkcp "$zoa_root/files/repositories" /etc/apk/repositorieschown root:root /etc/apk/repositorieschmod 0644 /etc/apk/repositoriesapk update# this is pretty typical - the above works just fine.# however, zoa provides a useful helper to wrap the# above into a single line:# remember: file, owners, perms# and optionally: a command to run if the file is updatedfile='/etc/apk/repositories'zoa-file repositories $filechown root:root $filechmod 0644 $file# zoa-file will only run "apk update" if the file is changed, or if its permissions# change. zoa-file also gives you more pretty output.# install useful packages (this is idempotent already!)apk add ip6tables nano vim htop tmux tree curl wget prometheus-node-exporter@edge-community pigz# install another file# note that this time, we don't run a command!zoa-file motd /etc/motd root:root 0644# zoa keeps track of all file changes throughout the run (done via zoa-file)# so you can always reference themzoa-changed /etc/motd# exits 0 now since the file was modified this run :D# setup cron & metricsapk add chronyzoa-file prom_collect /usr/bin/prom-collect root:root 0755zoa-file cyberia-alpine-metrics /etc/periodic/daily/cyberia-alpine-metrics# and now, a directory...mkdir -p /var/lib/prometheus/textfile_collectorchown root:root /var/lib/prometheus/textfile_collectorchmod 0777 /var/lib/prometheus/textfile_collector# of course, there's a shortcut:zoa-directory /var/lib/prometheus/textfile_collector root:root 0777# and of course, the shortcut gives us the ability to run a command & prints# slightly prettier output when zoa runs.# and naturally, dirs show up in zoa-changed as wellzoa-changed /var/lib/prometheus/textfile_collector# exits 0zoa-file node-exporter /etc/conf.d/node-exporter root:root 0644# just handle service management via shell# per usual, bust out a little for loop evenfor service in chronyd crond syslog klogd node-exporter; do service $service start rc-update add $servicedone# if you want to do something more OS-specific:if [ "$DISTRO" = "debian" ]; then # these init commands are idempotent as well # since they'll just do nothing and exit cleanly # if the service is already started/enabled systemctl start docker systemctl enable dockerfi# ???what have we learned so far???# files and dirs - zoa wraps that & provides helpers# services and package management - DIYzoa-file cyberian_authorized_ssh_keys \ /home/cyberian/.ssh/authorized_keys \ cyberian:cyberian \ 0600# here we can see the use of our first "var" - all of the vars in the /vars# dir are automatically applied to the nodes within the files.for operator in $operators; do # adduser is not in zoa because there's no POSIX standard # thus it would be very costly to capture all possible OS permutations # and the author of zoa values his time # # besides, it's pretty easy to automate: adduser -D "$operator" || true zoa-directory "/home/$operator/.ssh" "$operator:$operator" 0700 zoa-file "ssh_keys/$operator" "/home/$operator/.ssh/authorized_keys" "$operator:$operator" 0600doneif [ "$make_backup_user" = "true" ]; then useradd -S backup_userfi