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
|
#Get all the target servers
|
||||||
SERVERLIST=$(grep -v '#' "${WHEREAMI}/copy_to_servers.ini")
|
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
|
#Find some tmpfs
|
||||||
TMP=""
|
TMP=""
|
||||||
if [ -e /dev/shm/ ] && [ "$(findmnt -n -o FSTYPE --target /dev/shm)" == "tmpfs" ]; then
|
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
|
else
|
||||||
TMP="$(mktemp -d)/fun_with_env"
|
TMP="$(mktemp -d)"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
FUNTMP="${TMP}/fun_with_env"
|
||||||
|
|
||||||
#Prepare the files to copy over
|
#Prepare the files to copy over
|
||||||
mkdir "${TMP}"
|
mkdir "${FUNTMP}"
|
||||||
cd "${WHEREAMI}" \
|
cd "${WHEREAMI}" \
|
||||||
&& git archive --format=tar HEAD | tar xf - -C "${TMP}"
|
&& git archive --format=tar HEAD | tar xf - -C "${FUNTMP}"
|
||||||
|
|
||||||
#Copy it
|
#Copy it
|
||||||
for host in ${SERVERLIST}; do
|
for host in ${SERVERLIST}; do
|
||||||
rsync -az "${TMP}/" ${host}:~/.fun_with_env
|
rsync -az "${FUNTMP}/" ${host}:~/.fun_with_env
|
||||||
done
|
done
|
||||||
|
|||||||
Reference in New Issue
Block a user