30aa766b03b4a8fbe11c909fa5e040fc5fe139d1
[util-vserver.git] / scripts / vpkg
1 #!/bin/bash
2 # $Id: vpkg,v 1.11 2005/03/18 00:23:02 ensc Exp $
3
4 # Copyright (C) 2004 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
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 : ${UTIL_VSERVER_VARS:=/usr/lib/util-vserver/util-vserver-vars}
21 test -e "$UTIL_VSERVER_VARS" || {
22     echo $"Can not find util-vserver installation (the file '$UTIL_VSERVER_VARS' would be expected); aborting..." >&2
23     exit 1
24 }
25 . "$UTIL_VSERVER_VARS"
26 . "$_LIB_FUNCTIONS"
27
28 function showHelp()
29 {
30     echo \
31 $"Usage: $0 <vserver-name> <tag>
32
33 Report bugs to <$PACKAGE_BUGREPORT>."
34     exit 0
35 }
36
37 function showVersion()
38 {
39     echo $"\
40 vpkg $PACKAGE_VERSION -- shows information about packages in vservers
41 This program is part of $PACKAGE_STRING
42
43 Copyright (C) 2004 Enrico Scholz
44 This program is free software; you may redistribute it under the terms of
45 the GNU General Public License.  This program has absolutely no warranty."
46     exit 0
47 }
48
49
50 case "$1" in
51     (--help)    showHelp $(basename $0);;
52     (--version) showVersion ;;
53 esac
54
55 test "$1" -a "$2" || {
56     echo $"No vserver and/or tag given; use '--help' for more information" >&2
57     exit 1
58 }
59
60 vserver=$1
61 tag=$2
62 shift 2
63
64 case "$tag" in
65     get-conffiles|install)      ;;
66     *)          echo $"Unsupport tag '$tag'" >&2; exit 1;;
67 esac
68
69 cfgdir=$($_VSERVER_INFO "$vserver" APPDIR pkgmgmt) || :
70 vdir=$($_VSERVER_INFO "$1" VDIR) || :
71
72 style=
73 is_external=
74 pkgmgmt.guessStyle "$vserver" style || exit 2
75 pkgmgmt.isInternal "$vserver"       || is_external=1
76
77 cmd=()
78
79 case "$style" in
80     (redhat|mandrake)
81         rpm_param=
82         apt_param=
83         case "$tag" in
84             ## rpm outputs sometimes '(contains no files)', so return
85             ## only the valid output
86             (get-conffiles)
87                 rpm_param=( -qac --pipe "$_SED '\!^/!p;d'" );;
88             (install)
89                 rpm_param=( -Uvh "$@" )
90                 apt_param=( install "$@" )
91                 ;;
92         esac
93         
94         if test -n "$is_external"; then
95             have_apt=1
96             test -d "$cfgdir"/base/apt -o -d "$cfgdir"/aptetc || have_apt=
97         else
98             have_apt=
99             for i in /bin /usr/bin /usr/local/bin; do
100                 test ! -x "$vdir$i"/apt-get || { have_apt=1; break; }
101             done
102         fi
103         
104         if test -n "$is_external"; then
105             if test "$have_apt" -a "$apt_param"; then
106                 cmd=( "$_VAPT_GET" "$vserver" -- "${apt_param[@]}" )
107             else
108                 cmd=( "$_VRPM" "$vserver" -- "${rpm_param[@]}" )
109             fi
110         else
111             if test "$have_apt" -a "$apt_param"; then
112                 cmd=( "$_VSERVER" --silent "$vserver" exec apt-get "${apt_param[@]}" )
113             else
114                 cmd=( "$_VSERVER" --silent "$vserver" exec rpm "${rpm_param[@]}" )
115             fi
116         fi
117         ;;
118     (debian)
119         case "$tag" in
120             (get-conffiles)
121                 cmd=( sh -c "cat /var/lib/dpkg/info/*.conffiles 2>/dev/null" )
122                 ;;
123             (install)
124                 cmd=( apt-get install "$@" )
125                 ;;
126         esac
127
128         if test -n "$is_external"; then
129             echo $"'external' packagemanagement is not supported for Debian" >&2
130             exit 1
131         else
132             cmd=( "$_VSERVER" --silent "$vserver" exec "${cmd[@]}" )
133         fi
134         ;;
135     (*)
136         echo $"Packagemanagement is not supported for '$style' style" >&2
137         exit 2
138         ;;
139 esac
140
141 export LANG=C
142 exec "${cmd[@]}"