merge with 0.30.213
[util-vserver.git] / scripts / vserver-build.rpm
1 # $Id: vserver-build.rpm 2263 2006-01-22 12:24:25Z ensc $       --*- sh -*--
2
3 # Copyright (C) 2005 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 tmp=$(getopt -o +d:b:e --long debug,empty -n "$0" -- "$@") || exit 1
19 eval set -- "$tmp"
20
21 . "$_LIB_VSERVER_BUILD_FUNCTIONS_RPM"
22 . "$_LIB_VSERVER_BUILD_FUNCTIONS_PKGMGMT"
23
24 set -e
25
26
27 BASEDIR=$(pwd)
28 DISTRIBUTION=
29 EMPTY=
30
31 echo "$@"
32
33 while true; do
34     case "$1" in
35         (-d)            DISTRIBUTION=$2; shift;;
36         (-b)            BASEDIR=$2; shift;;
37         (-e|--empty)    EMPTY=1;;
38         (--debug)       set -x;;
39         (--)            shift; break ;;
40         (*)             echo "vserver-build.rpm: internal error: unrecognized option '$1'" >&2
41                         exit 1
42                         ;;
43     esac
44     shift
45 done
46
47
48 ####### some basic initializations
49
50 getDistribution "template"
51
52 base.init
53 pkgmgmt.initVariables
54 rpm.initVariables
55
56 if test -z "$EMPTY" -a "$#" -eq 0; then
57     rpmlist.initByDistribution rpm_lists "$DISTRIBUTION"
58     set -- "${rpm_lists[@]}"
59 fi
60
61 test -n "$EMPTY" -o "$#" -gt 0 || \
62     panic $"\
63 No rpm-lists specified and no list found for distribution '$DISTRIBUTION'.
64 When this is really indented, please use the '--empty' option."
65
66 rpm_dflt_opts=()
67 test "$OPTION_DEBUG" -lt 2 || rpm_dflt_opts=( "${rpm_dflt_opts[@]}" -v  )
68 test "$OPTION_DEBUG" -lt 3 || rpm_dflt_opts=( "${rpm_dflt_opts[@]}" -v  )
69 test -n "$OPTION_SILENT"   || rpm_dflt_opts=( "${rpm_dflt_opts[@]}" -vh )
70
71 rpm.sanityCheck
72
73
74 ######  init the filesystem
75
76 base.initFilesystem    "$OPTION_FORCE"
77 pkgmgmt.initFilesystem "$OPTION_FORCE"
78 rpm.initFilesystem
79
80
81 setup_writeOption "$VSERVER_NAME"
82 setup_writeInitialFstab
83
84
85 # when basedir is a non-local location, rpm will download it into the
86 # current directory. Therefore, create and go into a temporay directory
87 # before doing the operations.
88 tmpdir=$($_MKTEMPDIR -p /var/tmp vserver-build.rpm.XXXXXX)
89 manifest=$($_MKTEMP vserver-build.rpm.manifest.XXXXXX)
90 trap "rm -rf $tmpdir $manifest" EXIT
91 cd "$tmpdir"                    
92
93 ######  do the real work
94
95 test -z "$BUILD_INITPRE"  || "$BUILD_INITPRE" "$SETUP_CONFDIR"  "$UTIL_VSERVER_VARS"
96 rpm.initDB           "$SETUP_CONFDIR"
97 rpm.importGPGPubKeys "$SETUP_CONFDIR" \
98     "$__CONFDIR/.distributions/$DISTRIBUTION/pubkeys" \
99     "$__CONFDIR/.distributions/.common/pubkeys" \
100     "$__DISTRIBDIR/$DISTRIBUTION/pubkeys"
101
102 opts=()
103 for i; do
104     case "$i" in
105         (--force|--nodeps)      opts=( "${opts[@]}" "$i" ); continue;;
106     esac
107     
108     rpmlist.install "$VSERVER_NAME" "$BASEDIR" "$manifest" "$i" "${rpm_dflt_opts[@]}" "${opts[@]}" 
109     opts=()
110 done
111
112 test -z "$BUILD_INITPOST" || "$BUILD_INITPOST" "$SETUP_CONFDIR" "$UTIL_VSERVER_VARS"
113
114 base.setSuccess