ready for tagging
[util-vserver.git] / scripts / legacy / distrib-info
1 #!/bin/bash
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 : ${UTIL_VSERVER_VARS:=/usr/lib/util-vserver/util-vserver-vars}
29 test -e "$UTIL_VSERVER_VARS" || {
30     echo $"Can not find util-vserver installation (the file '$UTIL_VSERVER_VARS' would be expected); aborting..." >&2
31     exit 1
32 }
33 . "$UTIL_VSERVER_VARS"
34
35 if [ "$1" = "" ] ; then
36         echo distrib-info vserver-name command [ args ... ] >&2
37         echo Commands are: >&2
38         echo dumpfiles: Shows all files owned by a package >&2
39         echo pkgversion: reports all packages and their version/release >&2
40         echo unifiles: reports all unify-able file of a package >&2
41         exit 1
42 fi
43 if [ "$1" = "/" ] ; then
44         DISTDIR=/
45         CHROOTCMD=
46 elif [ -d "$1" ] ; then
47         DISTDIR=$1
48         CHROOTCMD="$__SBINDIR/chroot $DISTDIR"
49 else
50         DISTDIR=$__DEFAULT_VSERVERDIR/$1
51         CHROOTCMD="$__SBINDIR/chroot $DISTDIR"
52 fi
53 KEY=$2
54 shift
55 shift
56 if [ -f $DIRDIR/etc/redhat-release -o -f $DISTDIR/etc/mandrake-release ] ; then
57         case $KEY in
58         pkgversion)
59                 $CHROOTCMD /bin/rpm -qa --queryformat "%{name}=%{version}-%{release}\n"
60                 ;;
61         unifiles)
62                 # We remove /etc and /var/log to make sure no special file
63                 # there will be unified
64                 $CHROOTCMD /bin/rpm -ql --dump $* \
65                         | $_PARSERPMDUMP /etc/
66                 ;;
67         dumpfiles)
68                 $CHROOTCMD /bin/rpm -ql $*
69                 ;;
70         *)
71                 echo unknown request $KEY >&2
72                 ;;
73         esac
74 else
75         echo Distribution not supported yet >&2
76 fi