#!/bin/bash # Old versions of yum-builddep leave a stale yum.pid file behind. # Remove that file if necessary after yum-builddep exits # find yum-builddep YUM_BUILDDEP=$(which yum-builddep 2>/dev/null) # dnf: call it directly if [[ -z $YUM_BUILDDEP ]] || grep -q -F dnf.cli "$YUM_BUILDDEP" ; then yum-builddep "$@" exit $? fi # old yum: scan command line for --installroot ROOT_PREFIX= YUM_CONF=/etc/yum.conf find_root_prefix() { while [[ "$#" -gt 0 ]] ; do case "$1" in --installroot) ROOT_PREFIX="$2" shift ;; --installroot=*) ROOT_PREFIX="${1#*=}" ;; -c|--config) YUM_CONF="$2" shift ;; --config=*) YUM_CONF="${1#*=}" ;; esac shift done if [[ -z "$ROOT_PREFIX" ]] && [[ -f "$YUM_CONF" ]] ; then ROOT_PREFIX=$(sed -rn 's/^\s*installroot\s*=\s*(\S+)\s*$/\1/p' $YUM_CONF) fi } find_root_prefix "$@" # ignore signals -- always wait for yum-builddep trap "" INT TERM HUP PIPE # run it in the background to get its PID "$YUM_BUILDDEP" "$@" & pid="$!" # wait for it wait "$pid" res="$?" # if yum.pid remains and contains yum-builddep's PID, delete it if [[ -f "${ROOT_PREFIX}/run/yum.pid" ]] ; then lock_owner= read lock_owner <"${ROOT_PREFIX}/run/yum.pid" || : if [[ -n $lock_owner && $lock_owner == $pid ]] ; then rm -f "${ROOT_PREFIX}/run/yum.pid" fi fi # done exit $res