mirror of
https://github.com/deuill/coreos-home-server.git
synced 2024-09-21 13:40:45 +00:00
Correct issues with 'post-merge' hook
The use of 'rsync' is not compatible with the SELinux setup used in CoreOS, and thus simple use of 'cp' and 'rm' is required.
This commit is contained in:
parent
253deb7176
commit
67e8a28b8f
@ -9,7 +9,7 @@ SyslogIdentifier=%N
|
|||||||
PrivateTmp=true
|
PrivateTmp=true
|
||||||
Environment=GIT_REMOTE_URL=https://github.com/deuill/coreos-home-server.git
|
Environment=GIT_REMOTE_URL=https://github.com/deuill/coreos-home-server.git
|
||||||
ExecStartPre=/usr/bin/git clone --verbose --depth=1 -- $GIT_REMOTE_URL %T/coreos-home-server
|
ExecStartPre=/usr/bin/git clone --verbose --depth=1 -- $GIT_REMOTE_URL %T/coreos-home-server
|
||||||
ExecStart=/bin/sh %T/coreos-home-server/hooks/post-merge
|
ExecStart=/bin/bash %T/coreos-home-server/hooks/post-merge
|
||||||
|
|
||||||
[Install]
|
[Install]
|
||||||
WantedBy=multi-user.target
|
WantedBy=multi-user.target
|
||||||
|
@ -8,38 +8,63 @@
|
|||||||
|
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
# Base configuration variables.
|
# Global configuration variables.
|
||||||
ROOTDIR="$(git -C "$(dirname "$0")" rev-parse --show-toplevel)"
|
TEMP_CONFIG_PATH="$(git -C "$(dirname "$0")" rev-parse --show-toplevel)"
|
||||||
COREOS_CONFIG_DIR="/etc/coreos-home-server"
|
HOST_CONFIG_PATH="/etc/coreos-home-server"
|
||||||
SYSTEMD_CONFIG_DIR="/etc/systemd/system"
|
SYSTEMD_CONFIG_PATH="/etc/systemd/system"
|
||||||
|
|
||||||
function sync-coreos() {
|
# Synchronize CoreOS home-server configuration for specific path.
|
||||||
local from="${ROOTDIR}/config" to="${COREOS_CONFIG_DIR}"
|
function sync-coreos-config() {
|
||||||
rsync --recursive --update --links --times --perms --delete-after --delete-excluded \
|
local path="$1"
|
||||||
--exclude=.git --exclude=*.fcc --exclude=*.ign --filter='protect *.env' "${from}"/*/ "${to}/"
|
|
||||||
}
|
|
||||||
|
|
||||||
function sync-systemd() {
|
# Search for configuration in any of the local configuration sub-directories.
|
||||||
local from="${ROOTDIR}/config" to="${SYSTEMD_CONFIG_DIR}"
|
for dir in "$TEMP_CONFIG_PATH"/config/*/"$(basename "$path")"; do
|
||||||
rsync --info=name --recursive --update "${from}"/*/systemd/ "${from}"/*/*/systemd/ "${to}/"
|
if test ! -d "$dir"; then
|
||||||
}
|
echo "configuration not found, skipping."
|
||||||
|
return
|
||||||
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
|
fi
|
||||||
|
|
||||||
|
# Remove files that only exist in local configuration.
|
||||||
|
for n in $(comm -23 <(cd "$path"; find . | sort) <(cd "$dir"; find . | sort)); do
|
||||||
|
rm --verbose --recursive --force "$(realpath --quiet "$path/$n")"
|
||||||
|
done
|
||||||
|
|
||||||
|
cp --verbose --recursive --update --target-directory "$path" "$dir"/*
|
||||||
|
echo "done."
|
||||||
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
# Execute program body.
|
# Synchronize systemd service files from CoreOS home-server configuration.
|
||||||
main "$@"
|
function sync-systemd-services() {
|
||||||
|
local dest
|
||||||
|
local result=1
|
||||||
|
|
||||||
|
# Copy service files if newer than destination.
|
||||||
|
for src in "$HOST_CONFIG_PATH"/*/systemd/*; do
|
||||||
|
dest="$SYSTEMD_CONFIG_PATH/$(basename "$src")"
|
||||||
|
if test "$src" -nt "$dest"; then
|
||||||
|
cp --verbose --recursive "$src" "$dest"
|
||||||
|
result=0
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
echo "done."
|
||||||
|
return $result
|
||||||
|
}
|
||||||
|
|
||||||
|
# Synchronize all existing CoreOS home-server configuration.
|
||||||
|
for dir in "$HOST_CONFIG_PATH"/*; do
|
||||||
|
if test ! -d "$dir"; then
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo -n "Synchronizing host configuration for '$dir'... "
|
||||||
|
sync-coreos-config "$dir"
|
||||||
|
done
|
||||||
|
|
||||||
|
# Synchronize systemd services from local CoreOS home-server configuration.
|
||||||
|
echo -n "Synchronizing systemd service files... "
|
||||||
|
if sync-systemd-services; then
|
||||||
|
echo "Reloading systemd daemon after service updates."
|
||||||
|
systemctl daemon-reload
|
||||||
|
fi
|
||||||
|
Loading…
Reference in New Issue
Block a user