9aa499dcaec1496a4afc08cfe0f4758851501d91
[util-vserver.git] / scripts / vserver-build.functions.rpm
1 # $Id: vserver-build.functions.rpm,v 1.8 2005/04/16 21:20:45 ensc Exp $ --*- sh -*--
2
3 # Copyright (C) 2003 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; version 2 of the License.
8 #  
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 # GNU General Public License for more details.
13 #  
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17
18 RPMDB_PATH=
19 RPMLIBDIR=
20
21 function rpm.importGPGPubKeys
22 {
23     local dst=$1
24     local pkgs
25     declare -a pkgs
26     local i
27     
28     shift
29     for i; do
30         local file=
31         for file in "$i"/*; do
32             isRegularFile "$file" || continue
33
34             pkgs=( "${pkgs[@]}" "$file" )
35         done
36     done
37
38     test -n "$pkgs" || return 0
39     "$_VRPM" "$dst" -- --import "${pkgs[@]}"
40 }
41
42 function rpm.initVariables
43 {
44     test -n "$WORKAROUND_106057" && \
45         RPMDB_PATH=/.rpmdb || \
46         RPMDB_PATH=/dev
47
48     findDir RPMLIBDIR "$__CONFDIR/.distributions/$DISTRIBUTION/rpmlib" "$__DISTRIBDIR/$DISTRIBUTION/rpmlib" /
49 }
50
51 function rpm.initFilesystem
52 {
53     test -z "$WORKAROUND_106057" || mkdir -p "$RPMDB_PATH"
54     mkdir -p "$VDIR$RPMDB_PATH"
55
56     test -z "$WORKAROUND_APT_DBPATH" || {
57         mkdir -p "$VDIR/var/lib"
58         ln -s "$RPMDB_PATH" "$VDIR/var/lib/rpm"
59     }
60
61     mkdir -p "$PKGCFGDIR"/rpm/{etc,state}
62     populateDirectory "$PKGCFGDIR/rpm/etc" \
63         "$__DISTRIBDIR/defaults/rpm" \
64         "$__DISTRIBDIR/$DISTRIBUTION/rpm" \
65         "$__CONFDIR/.distributions/$DISTRIBUTION/rpm"
66
67     echo "%_dbpath $RPMDB_PATH" >>"$PKGCFGDIR/rpm/etc/macros"
68
69     test "$RPMLIBDIR"  = / || ln -s "$RPMLIB"  "$SETUP_CONFDIR/apps/pkgmgmt/rpmlib"
70 }
71
72 function rpm.initDB
73 {
74     RPM_FLAVOR=d "$_VRPM" "$1" -- --initdb
75 }
76
77
78
79 ## Usage: rpmlist.install <vserver> <basedir> <tmpfile> <listfile> <rpm-options>*
80 function rpmlist.install()
81 {
82     local       cfgdir=$1
83     local       basedir=$2
84     local       manifest=$3
85     local       listfile=$4
86     shift 4
87
88     while read; do
89         case x"$REPLY" in
90             (x|\#*)     continue;;
91         esac
92         
93         echo "$basedir/$REPLY"
94     done >"$manifest" <"$listfile"
95
96     test "$OPTION_DEBUG" -eq 0 || cat "$manifest"
97     test ! -s "$manifest"      || $_VRPM "$cfgdir" -- -U "$@" "$manifest"
98 }
99
100
101 ## Usage: rpmlist.initByDistribution <result-var> <distribution>
102 function rpmlist.initByDistribution()
103 {
104     local       _rlid_listdir
105     declare -a  _rlid_res=() 
106     
107
108     findDir _rlid_listdir "$__CONFDIR/.distributions/$2/rpmlist.d" \
109                           "$__DISTRIBDIR/$2/rpmlist.d" \
110                           ''
111                     
112     test -d "$_rlid_listdir" || return 0
113
114     local       _rlid_lst
115     for _rlid_lst in "$_rlid_listdir"/*.lst; do
116         isRegularFile "$_rlid_lst" || continue
117
118         local           _rlid_opts=${_rlid_lst%%lst}cmd
119         declare -a      _rlid_tmp=()
120
121         test ! -e "$_rlid_opts" || getFileArray _rlid_tmp "$_rlid_opts"
122         _rlid_res=( "${_rlid_res[@]}" "${_rlid_tmp[@]}" "$_rlid_lst" )
123     done
124
125     eval "$1"='( "${_rlid_res[@]}" )'
126 }