minor optimizations
[util-vserver.git] / util-vserver / scripts / vserver-build.functions.pkgmgmt
1 # $Id$  --*- sh -*--
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; 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 PKGCFGBASE=
19 PKGCFGBASE_REL=
20
21 function pkgmgmt._setPkgCfgBase
22 {
23     test -z "$PKGCFGBASE" || return 0
24
25     for item in "\"$CONFDIR/.defaults/apps/pkgmgmt/base\" 1" ${ROOTDIR:+"$ROOTDIR/.pkg"} "$DEFAULT_VSERVERPKGDIR"; do
26         eval set -- "$item"
27         PKGCFGBASE=$1
28         PKGCFGBASE_REL=$2
29         test ! -d "$PKGCFGBASE" || break
30     done
31
32     test -d "$PKGCFGBASE"  || {
33         echo "pkgcfgbase-dir '$PKGCFGBASE' does not exists or is invalid" >&2
34         exit 1
35     }
36 }
37
38 function pkgmgmt._setPkgCfg
39 {
40     pkgmgmt._setPkgCfgBase
41
42     test -z "$PKGCFGDIR" || return 0
43     PKGCFGDIR="$PKGCFGBASE/$VSERVERDIRNAME"
44 }
45
46 function pkgmgmt._renameVserverPkgCfg
47 {
48     local suffix=.~$(date +'%s')~
49     local i
50     
51     for i in "$PKGCFGDIR"; do
52         test ! -e "$i" || {
53             mv "$i" "$i$suffix"
54             say "Renamed '$i' to '$i$suffix'"
55         }
56     done
57 }
58
59 function pkgmgmt.initFilesystem
60 {
61     test -z "$1" || pkgmgmt._renameVserverPkgCfg
62     test ! -d "$PKGCFGDIR" || {
63         echo $\
64 "vserver pkgmgmt-directory exists already; please try to use
65 '--force'; or remove it manually" >&2
66         exit 1
67     }
68
69     mkdir -p "$SETUP_CONFDIR"/apps/pkgmgmt
70
71     test -z "$PKGCFGDIR" || {
72         ln -s "$PKGCFGDIR" "$SETUP_CONFDIR/apps/pkgmgmt/base"
73
74         test "$_EXECDIR" = / || ln -s "$_EXECDIR" "$confdir/apps/pkgmgmt/execdir"
75     }
76
77 }
78
79 function pkgmgmt.initVariables
80 {
81     pkgmgmt._setPkgCfg
82     findDir  PKGDIR         "$CONFDIR/.distributions/$DISTRIBUTION/pkgs"      "$DISTRIBDIR/$DISTRIBUTION/pkgs"     /
83 }