merge with 0.30.213
[util-vserver.git] / scripts / vserver-build.functions.rpm
1 # $Id: vserver-build.functions.rpm 2311 2006-09-13 22:18:55Z dhozac $   --*- 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     mkdir -p "$VDIR/var/lock/rpm"
56
57     test -z "$WORKAROUND_APT_DBPATH" || {
58         mkdir -p "$VDIR/var/lib"
59         ln -s "$RPMDB_PATH" "$VDIR/var/lib/rpm"
60     }
61
62     mkdir -p "$PKGCFGDIR"/rpm/{etc,state}
63     populateDirectory "$PKGCFGDIR/rpm/etc" \
64         "$__DISTRIBDIR/defaults/rpm" \
65         "$__DISTRIBDIR/$DISTRIBUTION/rpm" \
66         "$__CONFDIR/.distributions/$DISTRIBUTION/rpm"
67
68     echo "%_dbpath $RPMDB_PATH" >>"$PKGCFGDIR/rpm/etc/macros"
69
70     test "$RPMLIBDIR"  = / || ln -s "$RPMLIB"  "$SETUP_CONFDIR/apps/pkgmgmt/rpmlib"
71 }
72
73 function rpm.initDB
74 {
75     RPM_FLAVOR=d "$_VRPM" "$1" -- --initdb
76 }
77
78
79
80 ## Usage: rpmlist.install <vserver> <basedir> <tmpfile> <listfile> <rpm-options>*
81 function rpmlist.install()
82 {
83     local       cfgdir=$1
84     local       basedir=$2
85     local       manifest=$3
86     local       listfile=$4
87     shift 4
88
89     while read; do
90         case x"$REPLY" in
91             (x|\#*)     continue;;
92         esac
93         
94         echo "$basedir/$REPLY"
95     done >"$manifest" <"$listfile"
96
97     test "$OPTION_DEBUG" -eq 0 || cat "$manifest"
98     test ! -s "$manifest"      || $_VRPM "$cfgdir" -- -U "$@" "$manifest"
99 }
100
101
102 ## Usage: rpmlist.initByDistribution <result-var> <distribution>
103 function rpmlist.initByDistribution()
104 {
105     local       _rlid_listdir
106     declare -a  _rlid_res=() 
107     
108
109     findDir _rlid_listdir "$__CONFDIR/.distributions/$2/rpmlist.d" \
110                           "$__DISTRIBDIR/$2/rpmlist.d" \
111                           ''
112                     
113     test -d "$_rlid_listdir" || return 0
114
115     local       _rlid_lst
116     for _rlid_lst in "$_rlid_listdir"/*.lst; do
117         isRegularFile "$_rlid_lst" || continue
118
119         local           _rlid_opts=${_rlid_lst%%lst}cmd
120         declare -a      _rlid_tmp=()
121
122         test ! -e "$_rlid_opts" || getFileArray _rlid_tmp "$_rlid_opts"
123         _rlid_res=( "${_rlid_res[@]}" "${_rlid_tmp[@]}" "$_rlid_lst" )
124     done
125
126     eval "$1"='( "${_rlid_res[@]}" )'
127 }
128
129
130 ## Usage: rpm.sanityCheck
131 function rpm.sanityCheck
132 {
133     test -x "$BUILD_INITPRE" || colorize warn warning $"\
134 WARNING: you are going to use an rpm-based installation method without
135   having an 'initpre' script. Such a script is highly recommend to
136   workaround bugs in rpm which can cause messages like
137
138   | error: unpacking of archive failed on file /usr/bin/X11;42dd8791:
139
140   Please read http://linux-vserver.org/HowToRegisterNewDistributions
141   for information how to add support for your own distribution."
142 }