Add urpmi support
authorDaniel Hokka Zakrisson <daniel@hozac.com>
Thu, 5 May 2011 21:40:20 +0000 (23:40 +0200)
committerDaniel Hokka Zakrisson <daniel@hozac.com>
Thu, 5 May 2011 21:44:38 +0000 (23:44 +0200)
scripts/Makefile-files
scripts/functions
scripts/pkgmgmt
scripts/vserver-build
scripts/vserver-build.functions
scripts/vserver-build.urpmi [new file with mode: 0644]
scripts/vurpm [new file with mode: 0755]
scripts/vurpm-worker [new file with mode: 0755]

index 988d531..4422172 100644 (file)
@@ -44,6 +44,7 @@ scripts_pkglib_src_DTA =      scripts/functions \
                                scripts/vserver-build.debootstrap \
                                scripts/vserver-build.fai \
                                scripts/vserver-build.rpm \
+                               scripts/vserver-build.urpmi \
                                scripts/vserver-build.yum \
                                scripts/vserver-build.template \
                                scripts/vserver-build.rsync \
@@ -75,6 +76,7 @@ scripts_pkglib_src_SCRPTS =   scripts/pkgmgmt \
                                scripts/vservers.grabinfo.sh \
                                scripts/vshelper \
                                scripts/vsysvwrapper \
+                               scripts/vurpm-worker \
                                scripts/vyum-worker \
                                scripts/h2ext-worker
 
@@ -100,6 +102,7 @@ scripts_sbin_src_PRGS =             scripts/chbind \
                                scripts/vsomething \
                                scripts/vtop \
                                scripts/vupdateworld \
+                               scripts/vurpm \
                                scripts/vyum
 
 scripts_sbin_gen_PRGS =
index 7d6278b..f4cd1ff 100644 (file)
@@ -354,8 +354,10 @@ function _pkgSetVarsBase
 function _pkgSetVarsRPM
 {
     if test -n "$PKGDIR"; then
-       findDir RPMETCDIR    $PKGDIR/rpmetc      $PKGDIR/base/rpm/etc       /etc/rpm
-       findDir RPMSTATEDIR  $PKGDIR/rpmstate    $PKGDIR/base/rpm/state
+       findDir RPMETCDIR    $PKGDIR/rpmetc        $PKGDIR/base/rpm/etc   \
+                            $PKGDIR/base/etc/rpm  /etc/rpm
+       findDir RPMSTATEDIR  $PKGDIR/rpmstate      $PKGDIR/base/rpm/state \
+                            $PKGDIR/base/var/lib/rpm
 
        findDir RPMLIBDIR    $PKGDIR/rpmlib      /
 
@@ -398,6 +400,17 @@ function _pkgSetVarsYum
     fi
 }
 
+function _pkgSetVarsUrpmi
+{
+    if test -n "$PKGDIR"; then
+       findDir URPMIETCDIR    $PKGDIR/urpmietc    $PKGDIR/base/etc/urpmi       /etc/urpmi
+       findDir URPMISTATEDIR  $PKGDIR/urpmistate  $PKGDIR/base/var/lib/urpmi
+    else
+       findDir URPMIETCDIR    "$VDIR"/etc/urpmi     /etc/urpmi
+       findDir URPMISTATEDIR  "$VDIR"/var/lib/urpmi /var/lib/urpmi
+    fi
+}
+
 
 function _pkgMountBase
 {
@@ -414,6 +427,11 @@ function _pkgMountYum
     :
 }
 
+function _pkgMountUrpmi
+{
+    :
+}
+
 function _pkgMountRPM
 {
     _pkgMountBindDir "$RPMETCDIR" /etc/rpm
@@ -450,6 +468,11 @@ function _pkgSetEnvYum
     :
 }
 
+function _pkgSetEnvUrpmi
+{
+    :
+}
+
 function _pkgSetEnvRPM
 {
     CUR_VSERVER=$vserver
@@ -471,6 +494,7 @@ function pkgInit
            rpm)        _pkgSetVarsRPM;;
            apt)        _pkgSetVarsApt;;
            yum)        _pkgSetVarsYum;;
+           urpmi)      _pkgSetVarsUrpmi;;
            *)          echo "Unknown packaging flavor" >&2; exit 1;;
        esac
     done
@@ -481,6 +505,7 @@ function pkgInit
            rpm)        _pkgMountRPM;;
            apt)        _pkgMountApt;;
            yum)        _pkgMountYum;;
+           urpmi)      _pkgMountUrpmi;;
        esac
     done
 
@@ -490,6 +515,7 @@ function pkgInit
            rpm)        _pkgSetEnvRPM;;
            apt)        _pkgSetEnvApt;;
            yum)        _pkgSetEnvYum;;
+           urpmi)      _pkgSetEnvUrpmi;;
        esac
     done
 
@@ -890,6 +916,27 @@ function pkgmgmt.isYumAvailable
     test -n "$have_yum" && return 0 || return 1
 }
 
+## Usage: pkgmgmt.isUrpmiAvailable <cfgdir> <vdir> [<is-internal>]
+function pkgmgmt.isUrpmiAvailable
+{
+    local cfgdir="$1"
+    local vdir="$2"
+    local is_internal="$3"
+    
+    local have_urpmi i
+    if test -n "$is_internal"; then
+       have_urpmi=1
+       test -d "$cfgdir"/var/lib/urpmi || have_yum=
+    else
+       have_urpmi=
+       for i in /bin /usr/bin /usr/local/bin; do
+           test ! -x "$vdir$i"/urpmi || { have_urpmi=1; break; }
+       done
+    fi
+
+    test -n "$have_urpmi" && return 0 || return 1
+}
+
 
 function vshelper.doSanityCheck
 {
index d38c192..2da1b1e 100755 (executable)
@@ -195,7 +195,7 @@ packagemanagement:
 "
     
     case $2 in
-       (RH)    pkgs=$(vrpm "$1" -- -q --qf '---%{NAME}---\n' rpm apt yum "${YUM_RELEASEPKGS[@]}")
+       (RH)    pkgs=$(vrpm "$1" -- -q --qf '---%{NAME}---\n' rpm apt yum urpmi "${YUM_RELEASEPKGS[@]}")
                hasSubstring "$pkgs" ---rpm--- || {
                    warning "$ERR
 * The vserver does not seem to have the 'rpm' package which is required
@@ -205,7 +205,7 @@ packagemanagement:
                    ERR=
                }
                
-               hasSubstring "$pkgs"  ---apt--- ---yum--- || {
+               hasSubstring "$pkgs"  ---apt--- ---yum--- ---urpmi--- || {
                    warning "$ERR
 * The vserver does not seem to have a depsolver like 'apt' or 'yum'
   installed. It is suggested to install such a program before setting
@@ -214,7 +214,8 @@ packagemanagement:
                    ERR=
                }
 
-               test -n "$have_apt" || test -z "$have_yum"   || \
+               test -n "$have_apt" || test -n "$have_urpmi" ||
+               test -z "$have_yum" || \
                hasSubstring "$pkgs" "${YUM_RELEASEPKGS[@]}" || {
                    warning "$ERR
 * yum requires a special package which describes the version of the
@@ -235,6 +236,8 @@ function processVserver_RH()
     local vserver=$1
     local is_internalize=$2
     local have_apt
+    local have_yum
+    local have_urpmi
     local cfgdir
     local i
 
@@ -244,8 +247,10 @@ function processVserver_RH()
     ## Figure out the environment....
     have_apt=1
     have_yum=1
+    have_urpmi=1
     pkgmgmt.isAptAvailable "$cfgdir" "$vdir" "$is_internalize" || have_apt=
     pkgmgmt.isYumAvailable "$cfgdir" "$vdir" "$is_internalize" || have_yum=
+    pkgmgmt.isUrpmiAvailable "$cfgdir" "$vdir" "$is_internalize" || have_urpmi=
 
     local APTETCDIR=
     local APTSTATEDIR=
@@ -280,11 +285,16 @@ Can not continue; use '--force' to override this check"
        popd >/dev/null
        
        if test -n "$have_apt"; then
-           findDir APTETCDIR    "$cfgdir"/aptetc "$cfgdir"/base/apt/etc /etc/apt /
+           findDir APTETCDIR     "$cfgdir"/aptetc "$cfgdir"/base/apt/etc /etc/apt /
+       elif test -n "$have_urpmi"; then
+           findDir URPMISTATEDIR "$cfgdir"/base/var/lib/urpmi
+           findDir URPMIETCDIR   "$cfgdir"/base/etc/urpmi
        fi
 
-       findDir RPMETCDIR   "$cfgdir"/rpmetc   "$cfgdir"/base/rpm/etc    /etc/rpm /
-       findDir RPMSTATEDIR "$cfgdir"/rpmstate "$cfgdir"/base/rpm/state
+       findDir RPMETCDIR   "$cfgdir"/rpmetc   "$cfgdir"/base/rpm/etc    \
+                           "$cfgdir"/base/etc/rpm /etc/rpm /
+       findDir RPMSTATEDIR "$cfgdir"/rpmstate "$cfgdir"/base/rpm/state  \
+                           "$cfgdir"/base/var/lib/rpm
     else
        mkdir -m755 -p "$cfgdir"
        local need_base=
@@ -327,6 +337,9 @@ Can not continue; use '--force' to override this check"
            pushd "$vdir" >/dev/null
                _hashAuto /etc/apt/apt.conf '/'
            popd >/dev/null
+       elif test -n "$have_urpmi"; then
+           _copySecure "$vdir" "$URPMISTATEDIR" /var/lib/urpmi
+           _copySecure "$vdir" "$URPMIETCDIR" /etc/urpmi
        fi
 
        _copySecure "$vdir" "$RPMETCDIR"   /etc/rpm
index 72906da..f914b0d 100755 (executable)
@@ -54,9 +54,10 @@ Possible methods are:
     apt-rpm     ... -- -d <distribution>
                 ...  installs the base-packages of the given distribution with
                     help of 'vapt-get'
-    yum         ... -- -d <distribution>
+    yum         ... -- -d <distribution> [-- <packages>*]
                 ...  installs the base-packages of the given distribution with
                     help of 'vyum'
+    urpmi       ... -- -d <distribution> -m <mirror>
     rpm         ... -- [-d <distribution>] --empty|([--force] [--nodeps] <manifest>)+
                 ...  installs lists of rpm-packages
     skeleton    ... -- [<cmd> <args>*]
@@ -136,7 +137,7 @@ setup_setDefaults "$VSERVER_NAME"
 
 case x"$method" in
     (xlegacy)  exec $_VSERVER_LEGACY "$VSERVER_NAME" build "$@" ;;
-    (xapt-rpm|xcopy|xskeleton|xdebootstrap|xyum|xrpm|xtemplate|xfai|xrsync|xclone)
+    (xapt-rpm|xcopy|xskeleton|xdebootstrap|xyum|xrpm|xtemplate|xfai|xrsync|xclone|xurpmi)
                . $__PKGLIBDIR/vserver-build.$method
                ;;
     (x)                panic $"No build-method specified";;
index 55ee043..66b480a 100644 (file)
@@ -155,6 +155,9 @@ function getDistribution
        if test -e /etc/fedora-release; then
            set -- $(cat /etc/fedora-release)
            DISTRIBUTION=fdr$4
+       elif test -e /etc/mandrake-release; then
+           set -- $(cat /etc/mandrake-release)
+           DISTRIBUTION=mdv$4
        elif test -e /etc/redhat-release; then
            set -- $(cat /etc/redhat-release)
            DISTRIBUTION=rh$5
diff --git a/scripts/vserver-build.urpmi b/scripts/vserver-build.urpmi
new file mode 100644 (file)
index 0000000..4362fb5
--- /dev/null
@@ -0,0 +1,74 @@
+# $Id$ --*- sh -*--
+
+# Copyright (C) 2003 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
+#  
+# 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
+# the Free Software Foundation; version 2 of the License.
+#  
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#  
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+tmp=$(getopt -o '+d:m:o:' --long debug,mirror:,mirrorlist -n "$0" -- "$@") || exit 1
+eval set -- "$tmp"
+
+. "$_LIB_VSERVER_BUILD_FUNCTIONS_PKGMGMT"
+
+DISTRIBUTION=
+MIRROR=
+MIRRORLIST=
+PKGS=( basesystem-minimal )
+while true; do
+    case "$1" in
+       -d)             DISTRIBUTION=$2; shift;;
+       --debug)        set -x;;
+       -m|--mirror)    MIRROR="$2"; shift;;
+        --mirrorlist)  MIRRORLIST=$1;;
+       --)             shift; break ;;
+       *)              echo "vserver-build.urpmi: internal error: unrecognized option '$1'" >&2
+                       exit 1
+                       ;;
+    esac
+    shift
+done
+
+if test -z "$MIRROR"; then
+    panic $"vserver-build.urpmi: --mirror argument required"
+fi
+
+if test "$#" -gt 0; then
+    PKGS=( "$@" )
+fi
+
+getDistribution
+
+base.init
+pkgmgmt.initVariables
+
+
+base.initFilesystem "$OPTION_FORCE"
+pkgmgmt.initFilesystem "$OPTION_FORCE"
+
+
+setup_writeOption "$VSERVER_NAME"
+setup_writeInitialFstab
+
+test -z "$BUILD_INITPRE"  || "$BUILD_INITPRE" "$SETUP_CONFDIR"  "$UTIL_VSERVER_VARS"
+
+urpmi.addmedia --urpmi-root "$PKGCFGDIR"/ --distrib $MIRRORLIST "$MIRROR"
+urpmi --urpmi-root "$PKGCFGDIR"/ --root "$VDIR"/ "${PKGS[@]}"
+
+pushd "$VDIR"/ >/dev/null
+rm -rf dev
+populateDev
+popd >/dev/null
+
+test -z "$BUILD_INITPOST" || "$BUILD_INITPOST" "$SETUP_CONFDIR" "$UTIL_VSERVER_VARS"
+
+base.setSuccess
diff --git a/scripts/vurpm b/scripts/vurpm
new file mode 100755 (executable)
index 0000000..0e60186
--- /dev/null
@@ -0,0 +1,81 @@
+#! /bin/bash
+# $Id$
+
+# Copyright (C) 2011 Daniel Hokka Zakrisson <daniel@hozac.com>
+# Copyright (C) 2005 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
+#  
+# 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
+# the Free Software Foundation; version 2 of the License.
+#  
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#  
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+: ${UTIL_VSERVER_VARS:=/usr/lib/util-vserver/util-vserver-vars}
+test -e "$UTIL_VSERVER_VARS" || {
+    echo $"Can not find util-vserver installation (the file '$UTIL_VSERVER_VARS' would be expected); aborting..." >&2
+    exit 1
+}
+. "$UTIL_VSERVER_VARS"
+. "$_LIB_FUNCTIONS"
+
+
+function showHelp()
+{
+    echo \
+$"Usage: $0 <command> <vserver-name>* [--all] -- <params>+
+
+<command> is any of urpmi/urpme/urpmi.update/urpmf/etc
+
+Report bugs to <$PACKAGE_BUGREPORT>."
+    exit 0
+}
+
+function showVersion()
+{
+    echo \
+$"vurpm $PACKAGE_VERSION -- urpmi/urpme for vservers
+This program is part of $PACKAGE_STRING
+
+Copyright (C) 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
+}
+
+tmp=$(getopt -o +q --long help,version,debug,quiet,all -n "$0" -- "$@") || exit 1
+eval set -- "$tmp"
+
+declare -a send_through urpmi_opts
+
+while true; do
+    case "$1" in
+       (--help)        showHelp $0 ;;
+       (--version)     showVersion ;;
+       (--debug)       send_through=( "${send_through[@]}" "$1" ); set -x;;
+       (--quiet|-q)    send_through=( "${send_through[@]}" "$1" );;
+       (--all)         urpmi_opts=( "${yum_opts[@]}" "$1" );;
+       (--)            shift; break;;
+       (*)             echo $"vurpm: internal error; arg=='$1'" >&2; exit 1;;
+    esac
+    shift
+done
+
+VSOMETHING_TITLE=vurpm
+VSOMETHING_WORKER=$_VURPM_WORKER
+VSOMETHING_PKGMGMT=1
+
+export VSOMETHING_TITLE VSOMETHING_WORKER VSOMETHING_PKGMGMT
+
+cmd="$1"
+export VURPM_CMD="$cmd"
+shift
+
+test ${#urpmi_opts[@]} -eq 0 || urpmi_opts=( "${urpmi_opts[@]}" -- )
+exec $_VSOMETHING "${send_through[@]}" "$cmd" "${urpmi_opts[@]}" "$@"
diff --git a/scripts/vurpm-worker b/scripts/vurpm-worker
new file mode 100755 (executable)
index 0000000..5c8d547
--- /dev/null
@@ -0,0 +1,43 @@
+#! /bin/bash
+# $Id$
+
+# Copyright (C) 2011 Daniel Hokka Zakrisson <daniel@hozac.com>
+#  
+# 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
+# the Free Software Foundation; version 2 of the License.
+#  
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#  
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+set -e
+
+: ${UTIL_VSERVER_VARS:=/usr/lib/util-vserver/util-vserver-vars}
+test -e "$UTIL_VSERVER_VARS" || {
+    echo $"Can not find util-vserver installation (the file '$UTIL_VSERVER_VARS' would be expected); aborting..." >&2
+    exit 1
+}
+. "$UTIL_VSERVER_VARS"
+. "$_LIB_FUNCTIONS"
+
+vserver=$1
+shift
+
+pkgInit "$vserver" rpm urpmi
+rpmFake.init "$vserver"
+
+urpm="${VURPM_CMD:-urpmi}"
+
+args=( --urpmi-root "$PKGDIR/base" )
+if test "$urpm" = "urpmi" -o "$urpm" = "urpme"; then
+    args=( "${args[@]}" --root "$VDIR" )
+
+rpmFake.exec $urpm \
+    "${args[@]}" \
+    "$@"