Files
fun_with_env/copy_to_servers.sh
2026-02-27 20:35:23 +01:00

39 lines
858 B
Bash
Executable File

#!/usr/bin/env bash
WHEREAMI="$( cd -- "$( dirname -- "${BASH_SOURCE[0]:-$0}"; )" &> /dev/null && pwd 2> /dev/null; )";
#Get all the target servers
SERVERLIST=$(grep -v '#' "${WHEREAMI}/copy_to_servers.ini")
[ -z "${SERVERLIST}" ] \
&& echo "Server list empty." \
&& exit 1
#If you make it dirty, clean it up
cleanup() {
if [[ -n "${TMP}" && -d "${TMP}" ]]; then
rm -rf "${TMP}"
fi
}
trap cleanup EXIT INT TERM
#Find some tmpfs
TMP=""
if [ -e /dev/shm/ ] && [ "$(findmnt -n -o FSTYPE --target /dev/shm)" == "tmpfs" ]; then
TMP="$(mktemp -d -p /dev/shm/)"
else
TMP="$(mktemp -d)"
fi
FUNTMP="${TMP}/fun_with_env"
#Prepare the files to copy over
mkdir "${FUNTMP}"
cd "${WHEREAMI}" \
&& git archive --format=tar HEAD | tar xf - -C "${FUNTMP}"
#Copy it
for host in ${SERVERLIST}; do
rsync -az "${FUNTMP}/" ${host}:~/.fun_with_env
done