File: vserver-build.fai

package info (click to toggle)
util-vserver 0.30.216-pre3054-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 10,556 kB
  • ctags: 3,909
  • sloc: ansic: 23,121; sh: 16,905; xml: 1,972; makefile: 383; python: 301; perl: 85; awk: 4
file content (171 lines) | stat: -rw-r--r-- 5,024 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
#
# Copyright (C) 2006 Sam Vilain <sam.vilain@catalyst.net.nz>
#  
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#  
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#  
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

tmp=$(getopt -o '+d:f:n:a' --long debug,pkgmgmt -n "$0" -- "$@") || exit 1
eval set -- "$tmp"

. "$_LIB_VSERVER_BUILD_FUNCTIONS_PKGMGMT"
. "$_LIB_VSERVER_FUNCTIONS"

DISTRIBUTION=:

FAI_VSERVER=
FAI_NFSROOT=/usr/lib/fai/nfsroot
FAI_DIR=/usr/local/share/fai
AUTO=1

use_pkgmgmt=
while true; do
    case "$1" in
	-f)		FAI_VSERVER=$2; shift; ;;
	-n)		FAI_NFSROOT=$2; shift; ;;
	-d)		FAI_DIR=$2; shift; ;;
	-a)		AUTO=;;
	--debug)	DEBUG=1; SH_DEBUG=-x; set -x;;
	--)		shift; break ;;
	*)		echo "vserver-build.fai: internal error: unrecognized option '$1'" >&2
			exit 1
			;;
    esac
    shift
done

getDistribution '' 1

base.init
base.initFilesystem "$OPTION_FORCE"

setup_writeOption "$VSERVER_NAME"
setup_writeInitialFstab

test -z "$BUILD_INITPRE"  || "$BUILD_INITPRE" "$SETUP_CONFDIR"  "$UTIL_VSERVER_VARS"

# migrate is a 2.6 feature, we need 2.6 for the secure_mount ccap
if ! $_VSERVER_INFO - FEATURE migrate; then
    panic $"\
The fai build method requires kernel features that are not present
in your kernel."
fi

# if they specified a vserver where FAI is installed, then prefix its
# root to the FAI_NFSROOT etc (unless they have already specified a
# $ROOTDIR-relative path)
REAL_ROOTDIR=`getPhysicalDir "$ROOTDIR"`
REAL_VDIR=`getPhysicalDir "$VDIR"`
echo $"ROOTDIR is $REAL_ROOTDIR"
echo $"VDIR    is $REAL_VDIR"
if [ -n "$FAI_VSERVER" ]
then
    echo "FAI_VSERVER is $FAI_VSERVER"
    if [ `expr "$FAI_NFSROOT" : "$REAL_ROOTDIR"` -eq 0 ]
    then
        FAI_NFSROOT="$REAL_ROOTDIR/$FAI_VSERVER$FAI_NFSROOT"
    fi
    if [ `expr "$FAI_DIR" : "$REAL_ROOTDIR"` -eq 0 ]
    then
        FAI_DIR="$REAL_ROOTDIR/$FAI_VSERVER$FAI_DIR"
    fi
fi
echo $"FAI_NFSROOT is $FAI_NFSROOT"
echo $"FAI_DIR     is $FAI_DIR"
FAI_ROOT=/tmp/target

if [ ! -e "$FAI_NFSROOT/usr/sbin/fai" ]
then
    panic $"NFSROOT not found - did you run fai-setup?"
fi

if ! grep -qw VIRTUAL "$FAI_NFSROOT/usr/sbin/fai"
then
    panic $"\
ERROR: Looks like you don't have the patched FAI.
See http://faiwiki.informatik.uni-koeln.de/index.php/Using_FAI_as_a_vserver_build_method
for information on where to get it."
fi

set -e

# suppresses color logo, as it does not leave the terminal in a nice
# state.
console=dummy

killprocs() {
    set +e
    S_CONTEXT=
    if isVserverRunning "$SETUP_CONFDIR" S_CONTEXT
    then
	$_VKILL -c "$S_CONTEXT" -s 15
	sleep 2
	$_VKILL -c "$S_CONTEXT" -s 9
	sleep 2
	isVserverRunning "$SETUP_CONFDIR" && warning $"\
Vserver '$VSERVER_NAME' still running unexpectedly; please investigate it
manually."
    fi
    [ -n "$HAVE_INTERFACES" ] && disableInterfaces "$SETUP_CONFDIR"
    base.__cleanup
}

trap killprocs INT EXIT

# last chance to abort!
if [ -z "$AUTO" ]
then
    echo -n "Press ENTER to begin, or Ctrl+C to cancel: "
    read junk
fi

# set up interfaces, so that the vserver can be built with restricted
# network access.
generateOptions "$SETUP_CONFDIR"
enableInterfaces "$SETUP_CONFDIR"
HAVE_INTERFACES=1

rwpaths="/var/lock /var/log /dev /var/run /etc/sysconfig"
[ -d "$FAI_NFSROOT/etc/network/run" ] && rwpaths="$rwpaths /etc/network/run"

export VDIR ROOTDIR FAI_VSERVER FAI_DIR FAI_NFSROOT FAI_ROOT console

[ -z "$AUTO" ] && FINAL_SHELL="exec /bin/sh -i"

# set up /mnt with all the mounts required
$_SECURE_MOUNT -n -o ro,dev --bind "$FAI_NFSROOT" /mnt
$_SECURE_MOUNT -n -t tmpfs -o size=64m,mode=1777 vm /mnt/tmp
$_MKDIR -p /mnt/tmp/target
$_SECURE_MOUNT -n -o rw,dev --bind "$VDIR" /mnt/tmp/target
$_MKDIR -p /mnt/tmp/target/proc
$_SECURE_MOUNT -n -t proc proc /mnt/tmp/target/proc
for x in $rwpaths
do
    /mnt/usr/lib/fai/mkrw -n "/mnt$x"
done
$_SECURE_MOUNT -n -o ro --bind "$FAI_DIR" /mnt/fai
$_SECURE_MOUNT -n -t proc proc /mnt/proc

cd /mnt
"${CHBIND_CMD[@]}" \
    $_VCONTEXT --create "${OPTS_VCONTEXT_CREATE[@]}" -- \
    $_VUNAME --xid self --set -t nodename="${SETUP_HOSTNAME:-fai-build}" \
	-t context="$SETUP_CONFDIR" -- \
    $_VATTRIBUTE --set --xid self "${OPTS_VATTRIBUTE[@]}" --ccap secure_mount \
    $_SAVE_CTXINFO "$SETUP_CONFDIR" \
    $_VCONTEXT --migrate-self --endsetup --chroot $SILENT_OPT \
	"${OPTS_VCONTEXT_MIGRATE[@]}" "${OPTS_VCONTEXT_ENTER[@]}" -- \
    /bin/sh -c "/bin/sh $SH_DEBUG /etc/init.d/rcS -N vschild_build; $FINAL_SHELL"

test -z "$BUILD_INITPOST" || "$BUILD_INITPOST" "$SETUP_CONFDIR" "$UTIL_VSERVER_VARS"

base.setSuccess