6bbddfb2163bff4957fc5dfdbcfdb0ddd8334cf2
[util-vserver.git] / util-vserver / scripts / distrib-info
1 #!/bin/sh
2
3 # Copyright (C) 2003 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
4 # based on distrib-info 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
21 # This scripts knows about every possible distribution (well, it should)
22 # It is passed a vserver name and a key (a command). The key represent a task.
23 # It executes the command and output on stdout.
24 # For example
25 # distrib-info vserver1 pkgversion
26 # If vserver1 is a redhat system, it executes
27 # rpm -qa --queryformat "%{name}=%{version}-%{release}
28 USR_LIB_VSERVER=$(dirname $0)
29
30 if [ "$1" = "" ] ; then
31         echo distrib-info vserver-name command [ args ... ] >&2
32         echo Commands are: >&2
33         echo dumpfiles: Shows all files owned by a package >&2
34         echo pkgversion: reports all packages and their version/release >&2
35         echo unifiles: reports all unify-able file of a package >&2
36         exit 1
37 fi
38 if [ "$1" = "/" ] ; then
39         DISTDIR=/
40         CHROOTCMD=
41 elif [ -d "$1" ] ; then
42         DISTDIR=$1
43         CHROOTCMD="/usr/sbin/chroot $DISTDIR"
44 else
45         DISTDIR=/vservers/$1
46         CHROOTCMD="/usr/sbin/chroot $DISTDIR"
47 fi
48 KEY=$2
49 shift
50 shift
51 if [ -f $DIRDIR/etc/redhat-release -o -f $DISTDIR/etc/mandrake-release ] ; then
52         case $KEY in
53         pkgversion)
54                 $CHROOTCMD /bin/rpm -qa --queryformat "%{name}=%{version}-%{release}\n"
55                 ;;
56         unifiles)
57                 # We remove /etc and /var/log to make sure no special file
58                 # there will be unified
59                 $CHROOTCMD /bin/rpm -ql --dump $* \
60                         | $USR_LIB_VSERVER/parserpmdump /etc/
61                 ;;
62         dumpfiles)
63                 $CHROOTCMD /bin/rpm -ql $*
64                 ;;
65         *)
66                 echo unknown request $KEY >&2
67                 ;;
68         esac
69 else
70         echo Distribution not supported yet >&2
71 fi
72