combined/revised install_package()/do_install()

* do_install(): moved a revised form into install_package(), removing
  this one.
* install_package(): tried to make sure we local-ized all the vars we
  need; saved two variables and two stat calls with one find; put a
  missing loop around our read prompt; made the key line the argument of
  read's -p flag; put the breaks and returns in the right places; and,
  in terms of what was brought in from do_install(): removed the unused
  loop from around the rename check and upgradepkg call; modified
  variables to use install_package()s and dequoted the surviving
  PKG_NAME.
This commit is contained in:
slakmagik 2010-06-14 23:54:21 +00:00
parent 2ee1c2345a
commit a21d663040

View file

@ -3147,51 +3147,45 @@ add_options() {
fi
}
do_install() {
# This is mostly equivalent to "upgradepkg --reinstall --install-new $@",
# but also checks for renames
local PKG OLDPKG
local PKG_NAME PKG_VER PKG_ARCH PKG_BUILD PKG_TAG
for PKG in "$@"; do
split_pkg_name $PKG
get_old_name OLDNAME "$PKG_NAME"
# we grep ls's output rather than have ls return a glob so 'foo'
# doesn't match 'foo-bar'
if ! OLDPKG=$(ls /var/log/packages/ |
grep -m1 "^$OLDNAME-[^-]*-[^-]*-[^-]*$REPO_TAG$"); then
OLDPKG=$PKG
fi
upgradepkg --reinstall --install-new $OLDPKG%"$PKG"
done
}
install_package() {
# Install the package.
# This is mostly equivalent to "upgradepkg --reinstall --install-new $1",
# but also checks for package ownership and renames
local INSTDIR=$1
local INSTPKG=$2
local OWNER=$(stat -c %U $INSTDIR/$INSTPKG)
local GROUP=$(stat -c %G $INSTDIR/$INSTPKG)
local REPLY
local REPLY OLDPKG
# keep the variables we pull up with split_pkg_name() here
local PKG_NAME PKG_VER PKG_ARCH PKG_BUILD PKG_TAG
# ditto the one from get_old_name()
local OLDNAME
if [[ $OWNER != root && $GROUP != root ]]; then
if [[ $(find $INSTDIR/$INSTPKG ! -user root -o ! -group root) ]]; then
crunch_fmt "WARNING: The file $INSTPKG is not set with root:root \
permissions! Do you want to proceed? Here is the \
output of ls -l:"
permissions! Do you want to proceed? Here is the output of \
ls -l:"
echo
ls -l $INSTDIR/$INSTPKG
echo
echo "Press (Y)es to proceed or (N)o to abort."
read
case $REPLY in
y* | Y* ) echo "Proceeding..." ;;
n* | N* ) echo "Aborting..."; return 0 ;;
* ) unknown_response; break ;;
esac
while :; do
read -n1 -ep "Press (Y)es to proceed or (N)o to abort: "
case $REPLY in
y* | Y* ) echo "Proceeding..."; break ;;
n* | N* ) echo "Aborting..."; return ;;
* ) unknown_response ;;
esac
done
fi
do_install $INSTDIR/$INSTPKG
split_pkg_name $INSTPKG
get_old_name OLDNAME $PKG_NAME
# we grep ls's output rather than have ls return a glob so 'foo'
# doesn't match 'foo-bar'
if ! OLDPKG=$(ls /var/log/packages/ |
grep -m1 "^$OLDNAME-[^-]*-[^-]*-[^-]*$REPO_TAG$"); then
OLDPKG=$INSTPKG
fi
upgradepkg --reinstall --install-new $OLDPKG%$INSTDIR/$INSTPKG
echo "Done upgrading/installing package."
}