#!/usr/bin/env bash # # Hook for updating local configuration on each pull. This will automatically put files in their # right places, but will not enable or start any services automatically; this is left to the user. # # Move this to '.git/hooks/post-merge' to have to run automatically after every 'git pull' operation. # The script assumes write access to host directories, and a CoreOS host. Don't run on other systems! set -euo pipefail # Base configuration variables. ROOTDIR="$(dirname "$(git rev-parse --git-dir)")" COREOS_CONFIG_DIR="/etc/coreos-home-server" SYSTEMD_CONFIG_DIR="/etc/systemd/system" function sync-coreos() { local from="${ROOTDIR}/config" to="${COREOS_CONFIG_DIR}" rsync --recursive --update --links --times --perms --delete-after --delete-excluded \ --exclude=.git --exclude=*.fcc --exclude=*.ign --filter='protect *.env' "${from}"/*/ "${to}/" } function sync-systemd() { local from="${ROOTDIR}/config" to="${SYSTEMD_CONFIG_DIR}" rsync --info=name --recursive --update "${from}"/*/systemd/ "${from}"/*/*/systemd/ "${to}/" } function main() { local buffer # Synchronize local configuration into host directory. echo "Synchronizing host configuration in '${COREOS_CONFIG_DIR}'..." sync-coreos echo "Synchronizing systemd configuration in '${SYSTEMD_CONFIG_DIR}'..." buffer=$(sync-systemd) if test -n "${buffer}"; then echo "Systemd services updated, reloading daemon..." echo "${buffer}" sudo systemctl daemon-reload fi } # Execute program body. main "$@"