Added trap to clean up
This commit is contained in:
@@ -5,20 +5,34 @@ WHEREAMI="$( cd -- "$( dirname -- "${BASH_SOURCE[0]:-$0}"; )" &> /dev/null && pw
|
||||
#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/)/fun_with_env"
|
||||
TMP="$(mktemp -d -p /dev/shm/)"
|
||||
else
|
||||
TMP="$(mktemp -d)/fun_with_env"
|
||||
TMP="$(mktemp -d)"
|
||||
fi
|
||||
|
||||
FUNTMP="${TMP}/fun_with_env"
|
||||
|
||||
#Prepare the files to copy over
|
||||
mkdir "${TMP}"
|
||||
mkdir "${FUNTMP}"
|
||||
cd "${WHEREAMI}" \
|
||||
&& git archive --format=tar HEAD | tar xf - -C "${TMP}"
|
||||
&& git archive --format=tar HEAD | tar xf - -C "${FUNTMP}"
|
||||
|
||||
#Copy it
|
||||
for host in ${SERVERLIST}; do
|
||||
rsync -az "${TMP}/" ${host}:~/.fun_with_env
|
||||
rsync -az "${FUNTMP}/" ${host}:~/.fun_with_env
|
||||
done
|
||||
|
||||
Reference in New Issue
Block a user