Cleaned up dependencies check functions in makepkg

Signed-off-by: Andrew Fyfe <andrew@neptune-one.net>
Signed-off-by: Dan McGee <dan@archlinux.org>
This commit is contained in:
Andrew Fyfe 2007-05-30 17:47:47 +01:00 committed by Dan McGee
parent 80237630af
commit 85fbf528bb

View file

@ -239,141 +239,131 @@ checkdeps() {
} }
handledeps() { handledeps() {
local missingdeps=0 local R_DEPS_SATISFIED=0
local deplist="$*" local R_DEPS_MISSING=1
local depstrip=""
local striplist=""
local haveperm=0
if [ "$EUID" = "0" -o "$SUDO" = 1 ]; then
haveperm=1
fi
[ $# -eq 0 ] && return $R_DEPS_SATISFIED
local deplist="$*"
local striplist dep depstrip
for dep in $deplist; do for dep in $deplist; do
depstrip=$(echo $dep | sed 's|=.*$||' | sed 's|>.*$||' | sed 's|<.*$||') depstrip="$(echo $dep | sed -e 's|=.*$||' -e 's|>.&$||' -e 's|<.*$||')"
striplist="$striplist $depstrip" striplist="$striplist $depstrip"
done done
if [ "$deplist" != "" -a $haveperm -eq 1 ]; then if [ "$DEP_SRC" = "0" -a "$DEP_BIN" = "0" ]; then
if [ "$DEP_BIN" = "1" -a "$SUDO" = "1" ]; then return $R_DEPS_MISSING
# install missing deps from binary packages (using pacman -S and sudo) elif [ "$SUDO" = 0 -a $EUID -gt 0 ]; then
msg "$(gettext "Installing missing dependencies...")" warning "$(gettext "Cannot auto-install missing dependencies as a normal user without sudo!")"
sudo pacman $PACMAN_OPTS -S $striplist plain "$(gettext "Run makepkg as root or with -S to resolve dependencies automatically.")"
if [ $? -eq 1 ]; then return $R_DEPS_MISSING
error "$(gettext "Pacman failed to install missing dependencies.")"
exit 1
fi fi
elif [ "$DEP_BIN" = "1" ]; then
if [ "$DEP_BIN" = "1" ]; then
# install missing deps from binary packages (using pacman -S) # install missing deps from binary packages (using pacman -S)
msg "$(gettext "Installing missing dependencies...")" msg "$(gettext "Installing missing dependencies...")"
pacman $PACMAN_OPTS -S $striplist local ret=0
if [ $? -eq 1 ]; then
if [ "$SUDO" = 1 ]; then
sudo pacman $PACMAN_OPTS -S $striplist || ret=$?
else
pacman $PACMAN_OPTS -S $striplist || ret=$?
fi
if [ $ret -ne 0 ]; then
error "$(gettext "Pacman failed to install missing dependencies.")" error "$(gettext "Pacman failed to install missing dependencies.")"
exit 1 exit 1 # TODO: error code
fi fi
elif [ "$DEP_SRC" = "1" ]; then elif [ "$DEP_SRC" = "1" ]; then
msg "$(gettext "Building missing dependencies...")"
# install missing deps by building them from source. # install missing deps by building them from source.
# we look for each package name in $SRCROOT and build it. # we look for each package name in $SRCROOT and build it.
if [ "$SRCROOT" = "" ]; then if [ "$SRCROOT" = "" ]; then
error "$(gettext "Source root cannot be found - ensure it is specified in makepkg.conf.")" error "$(gettext "Source root cannot be found - please make sure it is specified in makepkg.conf")"
exit 1 exit 1 # TODO: error code
fi fi
# TODO: handle version comparators (eg, glibc>=2.2.5) # TODO: handle version comparators (eg, glibc>=2.2.5)
msg "$(gettext "Building missing dependencies...")"
for dep in $striplist; do for dep in $striplist; do
candidates=$(find $SRCROOT -type d -name "$dep") local candidates="$(find "$SRCROOT" -type d -name "$dep")"
if [ "$candidates" = "" ]; then if [ "$candidates" = "" ]; then
error "$(gettext "Could not find \"%s\" under %s")" "$dep" "$SRCROOT" error "$(gettext "Could not find '%s' under %s")" "$dep" "$SRCROOT"
exit 1 exit 1 # TODO: error code
fi fi
success=0
local makepkg_opts='-i -c -b'
[ "$RMDEPS" = "1" ] && makepkg_opts="$makepkg_opts -r"
local ret packagedir
for packagedir in $candidates; do for packagedir in $candidates; do
if [ -f "$packagedir/$BUILDSCRIPT" ]; then if [ -f "$packagedir/$BUILDSCRIPT" ]; then
cd "$packagedir" cd "$packagedir"
if [ "$RMDEPS" = "1" ]; then ret=0
PKGDEST="$PKGDEST" makepkg -i -c -b -r PKGDEST="$PKGDEST" makepkg $makepkg_opts || ret=$?
else [ $ret -eq 0 ] && continue 2
PKGDEST="$PKGDEST" makepkg -i -c -b
fi
if [ $? -eq 0 ]; then
success=1
break
fi
fi fi
done done
if [ "$success" = "0" ]; then
error "$(gettext "Failed to build \"%s\"")" "$dep" error "$(gettext "Failed to build '%s'")" "$dep"
exit 1 exit 1 # TODO: error code
fi
done done
else
missingdeps=1
fi
elif [ "$deplist" != "" -a $haveperm -eq 0 ]; then
if [ "$DEP_SRC" = "1" -o "$DEP_BIN" = "1" ]; then
warning "$(gettext "Cannot auto-install missing dependencies as a normal user without sudo!")"
plain "$(gettext "Run makepkg as root or with -S to resolve dependencies automatically.")"
fi
missingdeps=1
fi fi
# rerun any additional sh scripts found in /etc/profile.d/ # rerun any additional sh scripts found in /etc/profile.d/
for i in /etc/profile.d/*.sh local script
do for script in /etc/profile.d/*.sh; do
if [ -x $i ]; then if [ -x $script ]; then
. $i &>/dev/null source $script &>/dev/null
fi fi
done done
return $missingdeps return $R_DEPS_SATISFIED
} }
resolvedeps() { resolvedeps() {
deplist="" local R_DEPS_SATISFIED=0
newdeplist="" local R_DEPS_MISSING=0
deplist=$(checkdeps $*) deplist="$(checkdeps $*)"
if [ -n "${deplist}" ]; then [ "$deplist" = "" ] && return $R_DEPS_SATISFIED
handledeps $deplist
if [ $? -eq 0 ]; then if handledeps $deplist; then
# check deps again to make sure they were resolved # check deps again to make sure they were resolved
newdeplist=$(checkdeps $*) deplist="$(checkdeps $*)"
if [ -n "${newdeplist}" ]; then [ "$deplist" = "" ] && return $R_DEPS_SATISFIED
elif [ "$DEP_BIN" = "1" -o "$DEP_SRC" = "1" ]; then
error "$(gettext "Failed to install all missing dependencies.")" error "$(gettext "Failed to install all missing dependencies.")"
fi fi
else
newdeplist="$deplist"
fi
fi
# if new dep list is not empty, print the list
if [ -n "${newdeplist}" ]; then
msg "$(gettext "Missing Dependencies:")" msg "$(gettext "Missing Dependencies:")"
for dep in ${newdeplist}; do local dep
msg2 "${dep}" for dep in $deplist; do
msg2 "$dep"
done done
return 1
else return $R_DEPS_MISSING
return 0
fi
} }
# fix flyspray bug #5923 # fix flyspray bug #5923
removedeps() { removedeps() {
[ "$RMDEPS" = "0" ] && return
[ "$SUDO" = "0" -a $EUID -gt 0 ] && return
# runtimedeps and buildtimedeps are set when resolving deps # runtimedeps and buildtimedeps are set when resolving deps
local deplist="$runtimedeps $buildtimedeps" local deplist="$runtimedeps $buildtimedeps"
local depstrip=""
local striplist=""
[ "$deplist" = "" ] && return
local striplist dep depstrip
for dep in $deplist; do for dep in $deplist; do
depstrip=$(echo $dep | sed 's|=.*$||' | sed 's|>.*$||' | sed 's|<.*$||') depstrip="$(echo $dep | sed -e 's|=.*$||' -e 's|>.&$||' -e 's|<.*$||')"
striplist="$striplist $depstrip" striplist="$striplist $depstrip"
done done
if [ "$RMDEPS" = "1" -a "$SUDO" = "1" -a -n "$deplist" ]; then msg "Removing installed dependencies..."
msg "$(gettext "Removing installed dependencies...")" if [ "$SUDO" = "1" ]; then
sudo pacman $PACMAN_OPTS -Rs $striplist sudo pacman $PACMAN_OPTS -Rs $striplist
elif [ "$RMDEPS" = "1" -a "$EUID" = "0" -a "$INFAKEROOT" != "1" -a -n "$deplist" ]; then else
msg "$(gettext "Removing installed dependencies...")"
pacman $PACMAN_OPTS -Rs $striplist pacman $PACMAN_OPTS -Rs $striplist
fi fi
} }