This commit was generated by cvs2svn to compensate for changes in r120,
[util-vserver.git] / scripts / vrpm
1 #!/bin/sh
2
3 # Copyright (C) 2003 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
4 # based on vrpm by Jacques Gelinas
5 #  
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2, or (at your option)
9 # any later version.
10 #  
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 # GNU General Public License for more details.
15 #  
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19
20 # Wrapper to update/install package in many vservers at once
21
22 : ${UTIL_VSERVER_VARS:=$(dirname $0)/util-vserver-vars}
23 test -e "$UTIL_VSERVER_VARS" || {
24     echo "Can not find util-vserver installation; aborting..."
25     exit 1
26 }
27 . "$UTIL_VSERVER_VARS"
28
29 usage(){
30         echo vrpm: Install/Updates packages in several vservers at once
31         echo vrpm vservers ... -- rpm options and packages
32         echo vrpm \[--unify\] ALL -- rpm options and packages
33         echo vrpm \[--unify\] server1 server2 -- -Uvh package.rpm
34         echo
35         echo vrpm is executed in the root server
36         echo "--unify run vunify on the vserver for the updated packages"
37 }
38 UNIFY=no
39 if [ "$1" = "--unify" ] ; then
40         UNIFY=yes
41         shift
42 fi
43 if [ $# = 0 ] ; then
44         usage
45 else
46         SERVERS=
47         while [ $# -gt 0 -a "$1" != "--" ]
48         do
49                 if [ "$1" = "ALL" ] ; then
50                         SERVERS=`cd $VROOTDIR && ls`
51                 else
52                         SERVERS="$SERVERS $1"
53                 fi
54                 shift
55         done
56         if [ "$1" != "--" ] ; then
57                 usage
58         elif [ "$SERVERS" = "" ] ; then
59                 echo no server specified
60                 echo
61                 usage
62         else
63                 shift
64                 for serv in $SERVERS
65                 do
66                         # We try to run the rpm command in the same security
67                         # context than the vserver, if running.
68                         # This way, process operations will be done in the proper
69                         # context
70                         # If the vserver is not running, chcontext will
71                         # pick an unused one.
72                         CTXOPT=""
73                         CTXFILE=/var/run/vservers/$serv.ctx
74                         if [ -f $CTXFILE ] ; then
75                                 source $CTXFILE
76                                 CTXOPT="--ctx $S_CONTEXT"
77                         fi
78                         #echo rpm --root $VROOTDIR/$serv $*
79                         echo Updating server $serv
80                         $SBINDIR/chcontext --silent $CTXOPT rpm --root $VROOTDIR/$serv $*
81                 done
82                 if [ "$UNIFY" = "yes" ] ; then
83                         PACKAGES=
84                         for pkg in $*
85                         do
86                                 case $pkg in
87                                 -*)
88                                         # RPM options ?
89                                         ;;
90                                 --*)
91                                         # RPM options ?
92                                         ;;
93                                 *)
94                                         pkg=`rpm -qp $pkg --queryformat %{name}`
95                                         PACKAGES="$PACKAGES $pkg"
96                                         ;;
97                                 esac
98                         done
99                         echo Unification
100                         $PKGLIBDIR/vunify --excldir /var/log $SERVERS -- $PACKAGES
101                 fi
102         fi
103 fi
104         
105