25a28622685782d251c1f157087f7afb4fb34332
[util-vserver.git] / scripts / vserver-build.rpm
1 # $Id: vserver-build.rpm,v 1.6 2005/07/03 13:17:38 ensc Exp $   --*- 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
72 ######  init the filesystem
73
74 base.initFilesystem    "$OPTION_FORCE"
75 pkgmgmt.initFilesystem "$OPTION_FORCE"
76 rpm.initFilesystem
77
78 setup_writeOption "$VSERVER_NAME"
79 setup_writeInitialFstab
80
81
82 # when basedir is a non-local location, rpm will download it into the
83 # current directory. Therefore, create and go into a temporay directory
84 # before doing the operations.
85 tmpdir=$($_MKTEMPDIR /var/tmp/vserver-build.rpm.XXXXXX)
86 manifest=$($_MKTEMP /tmp/vserver-build.rpm.manifest.XXXXXX)
87 trap "rm -rf $tmpdir $manifest" EXIT
88 cd "$tmpdir"                    
89
90
91 ######  do the real work
92
93 test -z "$BUILD_INITPRE"  || "$BUILD_INITPRE" "$SETUP_CONFDIR"  "$UTIL_VSERVER_VARS"
94 rpm.initDB           "$SETUP_CONFDIR"
95 rpm.importGPGPubKeys "$SETUP_CONFDIR" \
96     "$__CONFDIR/.distributions/$DISTRIBUTION/pubkeys" \
97     "$__CONFDIR/.distributions/.common/pubkeys" \
98     "$__DISTRIBDIR/$DISTRIBUTION/pubkeys"
99
100 opts=()
101 for i; do
102     case "$i" in
103         (--force|--nodeps)      opts=( "${opts[@]}" "$i" ); continue;;
104     esac
105     
106     rpmlist.install "$VSERVER_NAME" "$BASEDIR" "$manifest" "$i" "${rpm_dflt_opts[@]}" "${opts[@]}" 
107     opts=()
108 done
109
110 test -z "$BUILD_INITPOST" || "$BUILD_INITPOST" "$SETUP_CONFDIR" "$UTIL_VSERVER_VARS"
111
112 base.setSuccess