[Users] vzemerge

Philipp Wehrheim flipstar at gmx.net
Tue Dec 15 03:03:25 EST 2009


Hey folks,

just wanted to share this small script Im using
to install precompiled packages into my Gentoo-based CTs.

The idea behind this script is that there is a "BuildHost"-CT
where all pkgs get compiled and a number of more or less
equal CTs where the pkgs get installed.

One could argue that 'ROOT="<path>" emerge -K <pkg>' should be used
which is not working since the Gentoo emerge/ebuild scripts have a bug where
pkg_postinst() gets executed outside $ROOT.

cheers
flip



-------------- next part --------------
#!/bin/bash
#
# PW 20091030
#
# This script "emerges" prebuild tbz2 archives into a given container
#
#  - the container family (use-flags and cflags) should be equal
#  - $PKGDIR in make.conf should point to /usr/local/portage/packages

#VZDIR="/vz/ve"
VZDIR="/vz"


function usage() {
   cat << EOF

  Usage: $0 OPTIONS PORTAGE-PARAM EBUILD  

  Options:
  	-s | --source 	    VEID of the source container
	-d | --destination  VEID of the destination container

  PORTAGE-PARAM only -e and -p are supported 
  	-e -> --emptytree
	-p -> --pretend

  like: $0 -s 211 -d 234 -pv freeradius

EOF

  exit 0
}

error() {

  $ECHO "Error: $1"
  exit 1

}



if [ $# -eq 0 ]; then
  usage
fi

while [ $# -gt 0 ]; do    # Until you run out of parameters . . .

   case "$1" in

     -h|--help)
                usage
     ;;
     -s|--source)
      SRC_CT_ID="$2"
      shift
      if [ ! -d $VZDIR/$SRC_CT_ID/private ]; then
        error "source $VZDIR/$SRC_CT_ID/private does not exists on this system"
      fi
     ;;

     -d|--destination)
      DST_CT_ID="$2"
      shift
      if [ ! -d $VZDIR/$DST_CT_ID/private ]; then
        error "destination $VZDIR/$DST_CT_ID/private does not exists on this system"
      fi
     ;;

     -e|--emptytree)
      PORTAGEPARAM="$1"
      shift
      break
     ;;

     -p|--pretend)
      PORTAGEPARAM="$1"
      shift
      break
     ;;

     *)
#      if [ -z "$1" -o -z "$2" ]; then
       if [ -z "$1" ]; then
        usage;
      fi
      #shift
      break
      ;;

   esac

   shift
done   

#
#
#

SRC_PKGDIR=$VZDIR/$SRC_CT_ID/private/usr/local/portage/packages
DST_PKGDIR=$VZDIR/$DST_CT_ID/root/usr/local/portage/packages


[ -d $SRC_PKGDIR ] || exit -1
[ -d $DST_PKGDIR ] || mkdir -p $DST_PKGDIR

echo "mount --bind $SRC_PKGDIR $DST_PKGDIR"
echo "mount --bind -o remount,ro $DST_PKGDIR"

sleep 2

mount --bind $SRC_PKGDIR $DST_PKGDIR
mount --bind -o remount,ro $DST_PKGDIR

echo -e "\n  PKG Source: $VZDIR/$SRC_CT_ID/private/usr/local/portage/packages"
echo -e   "  PKG Destination: $VZDIR/$DST_CT_ID/private\n"

echo "vzctl exec $DST_CT_ID emerge --usepkgonly ${@}"
vzctl exec $DST_CT_ID emerge --usepkgonly ${@}

echo "umount $DST_PKGDIR"
umount $DST_PKGDIR


More information about the Users mailing list