added basic support for Debian
[util-vserver.git] / util-vserver / scripts / vpkg
1 #!/bin/bash
2
3 # Copyright (C) 2004 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
4 #  
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2, or (at your option)
8 # any later version.
9 #  
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 # GNU General Public License for more details.
14 #  
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18
19 : ${UTIL_VSERVER_VARS:=/usr/lib/util-vserver/util-vserver-vars}
20 test -e "$UTIL_VSERVER_VARS" || {
21     echo "Can not find util-vserver installation; aborting..."
22     exit 1
23 }
24 . "$UTIL_VSERVER_VARS"
25
26 function showHelp()
27 {
28     echo \
29 $"Usage: $0 <vserver-name> <tag>
30
31 Report bugs to <$PACKAGE_BUGREPORT>."
32     exit 0
33 }
34
35 function showVersion()
36 {
37     echo $"\
38 pkgmgmt-info $PACKAGE_VERSION -- shows information about packages in vservers
39 This program is part of $PACKAGE_STRING
40
41 Copyright (C) 2004 Enrico Scholz
42 This program is free software; you may redistribute it under the terms of
43 the GNU General Public License.  This program has absolutely no warranty."
44     exit 0
45 }
46
47 function guessStyle()
48 {
49     local vdir=$($_VSERVER_INFO "$1" VDIR) || {
50         echo $"Can not determine vserver-root" >&2
51         exit 1
52     }
53
54     if test -e "$vdir"/etc/redhat-release -o -e "$vdir"/etc/fedora-release; then
55         style=redhat
56     elif test -e "$vdir"/etc/mandrake-release; then
57         style=mandrake
58     elif test -e "$vdir"/etc/debian_version; then
59         style=debian
60     else
61         echo $"Can not determine packagemanagement style" >&2
62     fi
63 }
64
65 case "$1" in
66     (--help)    showHelp $(basename $0);;
67     (--version) showVersion ;;
68 esac
69
70 test "$1" -a "$2" || {
71     echo $"No vserver and/or tag given; use '--help' for more information" >&2
72     exit 1
73 }
74
75 vserver=$1
76 tag=$2
77 shift 2
78
79 case "$tag" in
80     get-conffiles|install)      ;;
81     *)          echo $"Unsupport tag '$tag'" >&2; exit 1;;
82 esac
83
84 cfgdir=$($_VSERVER_INFO "$vserver" APPDIR pkgmgmt) || {
85     echo $"Package management not configured for vserver '$vserver'" >&2
86     exit 1
87 }
88
89 vdir=$($_VSERVER_INFO "$1" VDIR) || :
90
91 style=
92 is_external=
93 {   read style <"$cfgdir"/style; } 2>/dev/null
94 test "$style" || guessStyle "$vserver"
95
96 test -e "$cfgdir"/internal || is_external=1
97
98
99 cmd=()
100
101 case "$style" in
102     (redhat|mandrake)
103         rpm_param=
104         apt_param=
105         case "$tag" in
106             ## rpm outputs sometimes '(contains no files)', so return
107             ## only the valid output
108             (get-conffiles)
109                 rpm_param=( -qac --pipe "sed '\!^/!p;d'" );;
110             (install)
111                 rpm_param=( -Uvh "$@" )
112                 apt_param=( install "$@" )
113                 ;;
114         esac
115         
116         if test "$is_external"; then
117             have_apt=1
118             test -d "$cfgdir"/base/apt -o -d "$cfgdir"/aptetc || have_apt=
119         else
120             have_apt=
121             for i in /bin /usr/bin /usr/local/bin; do
122                 test ! -x "$vdir$i"/apt-get || { have_apt=1; break; }
123             done
124         fi
125         
126         if test "$is_external"; then
127             if test "$have_apt" -a "$apt_param"; then
128                 cmd=( "$_VAPT_GET" "$vserver" -- "${apt_param[@]}" )
129             else
130                 cmd=( "$_VRPM" "$vserver" -- "${rpm_param[@]}" )
131             fi
132         else
133             if test "$have_apt" -a "$apt_param"; then
134                 cmd=( "$_VSERVER" --silent "$vserver" exec apt-get "${apt_param[@]}" )
135             else
136                 cmd=( "$_VSERVER" --silent "$vserver" exec rpm "${rpm_param[@]}" )
137             fi
138         fi
139         ;;
140     (debian)
141         exit 1
142         ;;
143 esac
144
145 export LANG=C
146 exec "${cmd[@]}"