build/bin/buildrc
2014-11-02 09:42:47 +01:00

74 lines
2.0 KiB
Bash

#!/bin/bash
_exec_locked() {
local tmp_dir="/var/tmp"
local lvm_snapshot_lock_file="/.entropy_locks/vg_chroots-lv_chroots-snapshot.lock"
local snapshot_lock_file="${tmp_dir}/.emerge.snapshot.lock"
local matter_lock_file="${tmp_dir}/.matter_resource.lock"
if [ ! -d "${tmp_dir}" ]; then
echo "${tmp_dir} is missing, creating it..." >&2
mkdir -p "${tmp_dir}"
fi
flock -x -n "${matter_lock_file}" true
rc=${?}
if [ "${rc}" != "0" ]; then
echo >&2
echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" >&2
echo "Matter or the Backup Script is running on this chroot" >&2
echo "Please be patient, it will eventually terminate..." >&2
echo "Snapshot lock file = ${snapshot_lock_file}" >&2
echo "Matter lock file = ${matter_lock_file}" >&2
echo >&2
echo "This ${1} instance will terminate NOW" >&2
echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" >&2
echo >&2
return 1
else
# acquire snapshot read lock in non-blocking, shared mode
(
flock -s -n 9 || {
echo "Hello there," >&2;
echo "a chroot snapshot is in progress..." >&2;
echo "Try again later." >&2;
exit 1;
}
flock -s --timeout=120 10
if [ "${?}" != "0" ]; then
echo >&2
echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" >&2
echo "The LVM lock of the Backup Script is being held for 2 minutes" >&2
echo "This should not happen. Please contact lxnay@sabayon.org and" >&2
echo "stop any activity NOW. However, if you're in an emergency" >&2
echo "Just rm ${lvm_snapshot_lock_file} and continue." >&2
echo "Please note that this will cause inconsistent backups." >&2
echo >&2
echo "This instance will terminate NOW" >&2
echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" >&2
echo >&2
exit 1
fi
"${@}"
exit ${?}
) 9> "${snapshot_lock_file}" 10>"${lvm_snapshot_lock_file}"
return ${?}
fi
}
emerge() {
_exec_locked "/usr/bin/emerge" --quiet-build=y --oneshot "${@}"
return ${?}
}
eit() {
_exec_locked "/usr/bin/eit" "${@}"
return ${?}
}
# Alias configuration
alias cosmos=/particles/cosmos/cosmos