2012-09-08 17:32:36 +02:00
|
|
|
#!/bin/bash
|
2011-08-07 18:23:32 +02:00
|
|
|
# Emerge wrapper, uses matter lock file support to avoid
|
|
|
|
# concurrent execution
|
2012-09-08 17:32:36 +02:00
|
|
|
_exec_locked() {
|
2012-09-06 14:30:19 +02:00
|
|
|
snapshot_lock_file="/var/tmp/.emerge.snapshot.lock"
|
2011-08-07 18:23:32 +02:00
|
|
|
matter_lock_file="/var/tmp/.matter_resource.lock"
|
2012-09-06 15:36:16 +02:00
|
|
|
|
2011-08-07 18:23:32 +02:00
|
|
|
flock -x -n "${matter_lock_file}" true
|
|
|
|
rc=${?}
|
|
|
|
if [ "${rc}" != "0" ]; then
|
2012-09-06 14:29:11 +02:00
|
|
|
echo >&2
|
|
|
|
echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" >&2
|
2012-09-06 15:36:16 +02:00
|
|
|
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
|
2012-09-06 14:29:11 +02:00
|
|
|
echo "this emerge instance will terminate NOW" >&2
|
|
|
|
echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" >&2
|
|
|
|
echo >&2
|
2011-08-07 18:23:32 +02:00
|
|
|
return 1
|
|
|
|
else
|
2012-09-06 14:29:11 +02:00
|
|
|
# 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;
|
|
|
|
}
|
|
|
|
# eval $(portageq envvar -v FETCHCOMMAND RESUMECOMMAND PORTAGE_RSYNC_OPTS)
|
|
|
|
# add bandwidth limit here
|
2012-09-08 17:32:36 +02:00
|
|
|
"${@}"
|
2012-09-06 14:29:11 +02:00
|
|
|
exit ${?}
|
|
|
|
) 9> "${snapshot_lock_file}"
|
|
|
|
return "${?}"
|
2011-08-07 18:23:32 +02:00
|
|
|
fi
|
|
|
|
}
|
2012-09-08 17:32:36 +02:00
|
|
|
|
|
|
|
emerge() {
|
|
|
|
_exec_locked "/usr/bin/emerge" "${@}"
|
|
|
|
return ${?}
|
|
|
|
}
|
|
|
|
|
|
|
|
eit() {
|
|
|
|
_exec_locked "/usr/bin/eit" "${@}"
|
|
|
|
return ${?}
|
|
|
|
}
|