X-Git-Url: http://git.linux-vserver.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=util-vserver%2Fscripts%2Fpkgmgmt;h=397eca2ef42864ca4af5cf0fca1131edc1f708bf;hb=33eafdacf1a16bf8f1eadb88968f1d8166564490;hp=a641dfbddd652c3f40c0752fa751aa5aa156ced9;hpb=dfd7c5abfa53e81582a7ca7e88f6ab82dda39085;p=util-vserver.git diff --git a/util-vserver/scripts/pkgmgmt b/util-vserver/scripts/pkgmgmt index a641dfb..397eca2 100755 --- a/util-vserver/scripts/pkgmgmt +++ b/util-vserver/scripts/pkgmgmt @@ -1,7 +1,7 @@ #!/bin/bash # $Id$ -# Copyright (C) 2004 Enrico Scholz +# Copyright (C) 2004,2005 Enrico Scholz # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -24,6 +24,7 @@ test -e "$UTIL_VSERVER_VARS" || { . "$UTIL_VSERVER_VARS" . "$_LIB_FUNCTIONS" . "$_LIB_VSERVER_BUILD_FUNCTIONS_PKGMGMT" +. "$__PKGLIBDIR/vserver.functions" function showHelp() { @@ -40,7 +41,7 @@ function showVersion() vpkg $PACKAGE_VERSION -- shows information about packages in vservers This program is part of $PACKAGE_STRING -Copyright (C) 2004 Enrico Scholz +Copyright (C) 2004,2005 Enrico Scholz This program is free software; you may redistribute it under the terms of the GNU General Public License. This program has absolutely no warranty." exit 0 @@ -59,7 +60,7 @@ function init() function _createDirs() { for i; do - test "$i" || continue + test -n "$i" || continue mkdir -p -m755 "$i" done } @@ -85,24 +86,43 @@ function _copySecureRev() ( cd "$dstdir" && tar xf - ) } +## Usage: _substFile +function _substFile() +{ + local file=$1 + local expr=$2 + + $_CHROOT_SH testfile "$file" || return 0 + + local tmp=$($_MKTEMP /tmp/pkgmgmt_subst.XXXXXX) + trap "$_RM -f $tmp" EXIT + + $_CHROOT_SH cat "$file" | \ + $_SED -e "$expr" >$tmp + + $_CHROOT_SH cat "$file" | $_CMP -s $tmp - || \ + $_CHROOT_SH truncate "$file" <$tmp + + $_RM -f $tmp +} + function _hashAuto() { + local file=$1 local hash=$2 - local dir=$(dirname "$1") - local file=$(basename "$1") - $_EXEC_CD "$dir" "$(which test)" "$file" || return 0 + $_CHROOT_SH testfile "$file" || return 0 - local tmp=$(mktemp /tmp/apt.conf.XXXXXX) - trap "rm -f $tmp" EXIT + local tmp=$($_MKTEMP /tmp/apt.conf.XXXXXX) + trap "$_RM -f $tmp" EXIT - $_EXEC_CD "$dir" /bin/cat "$file" | \ - sed -e "s|^\([^$hash].*@autogenerated@\)|$hash$hash\1|" >$tmp + $_CHROOT_SH cat "$file" | \ + $_SED -e "s|^\([^$hash].*@autogenerated@\)|$hash$hash\1|" >$tmp - cat $tmp | $_EXEC_CD "$dir" "$(which cmp)" -s - "$file" || \ - $_CHROOT_CAT "$1" <$tmp + $_CHROOT_SH cat "$file" | $_CMP -s $tmp - || \ + $_CHROOT_SH truncate "$file" <$tmp - rm -f $tmp + $_RM -f $tmp } function _unhashAuto() @@ -110,14 +130,102 @@ function _unhashAuto() test -e "$1" || return 0 local hash=$2 - local tmp=$(mktemp /tmp/apt.conf.XXXXXX) - trap "rm -f $tmp" EXIT + local tmp=$($_MKTEMP /tmp/apt.conf.XXXXXX) + trap "$_RM -f $tmp" EXIT + + $_SED -e "s|^$hash$hash\(.*@autogenerated@\)|\1|" "$1" >$tmp + $_CMP -s "$tmp" "$1" || \ + $_CAT "$tmp" >"$1" + + $_RM -f $tmp +} + +function _mountFilesystemsInternal() +{ + local fstab="$1" + test -e "$fstab" || return 0 + shift + + pushd "$vdir" >/dev/null + "$@" $_SECURE_MOUNT -n -a --chroot --fstab "$fstab" + popd >/dev/null +} + +function _mountFilesystems() +{ + local cfgdir + cfgdir=$($_VSERVER_INFO "$1" CFGDIR) || { + echo "Can not determine configuration directory for '$1'; ..." >&2 + return 1 + } + test -n "$_HAVE_CHBIND_OPTIONS" || _generateChbindOptions "$1" + + _mountFilesystemsInternal "$cfgdir"/fstab $_CHBIND "${CHBIND_OPTS[@]}" || return 1 + _mountFilesystemsInternal "$cfgdir"/fstab.local $_CHBIND "${CHBIND_OPTS[@]}" || return 1 +} + +function _umountFilesystems() +{ + local cfgdir + cfgdir=$($_VSERVER_INFO "$1" CFGDIR) || { + echo "Can not determine configuration directory for '$1'; ..." >&2 + return 1 + } + local vdir=$cfgdir/vdir + local is_ok=1 + test -n "$_HAVE_CHBIND_OPTIONS" || _generateChbindOptions "$1" + + pushd "$vdir/" >/dev/null || return 1 + _umountVserverInternal "$cfgdir"/fstab.local || is_ok= + _umountVserverInternal "$cfgdir"/fstab $_CHBIND "${CHBIND_OPTS[@]}" || is_ok= + popd >/dev/null || return 1 + + test -n "$is_ok" +} - sed -e "s|^$hash$hash\(.*@autogenerated@\)|\1|" "$1" >$tmp - cmp -s "$tmp" "$1" || \ - cat "$tmp" >"$1" +# Usage: verifyInternalPackages