7 # pkgs parsing utilities
8 PATH=$(dirname $0):$PATH . build.common
11 DEFAULT_PLDISTRO=planetlab
12 DEFAULT_PERSONALITY=linux32
15 echo "$COMMAND : Bailing out"
19 # overwrite vserver's internal yum config from what is in
20 # .distributions/<distrib>/yum/yum.conf and /yum.repos.d
22 function configure_yum_in_vserver () {
30 cd /etc/vservers/.distributions/${fcdistro}
31 if [ -f yum/yum.conf ] ; then
32 echo "Initializing yum.conf in $vserver from $(pwd)/yum"
33 sed -e "s!@YUMETCDIR@!/etc!g;
34 s!@YUMCACHEDIR@!/var/cache/yum!g;
35 s!@YUMLOGDIR@!/var/log!g;
36 s!@YUMLOCKDIR@!/var/lock!g;
37 " yum/yum.conf > /vservers/$vserver/etc/yum.conf
39 # post process the various @...@ variables from this yum.conf file.
41 echo "Using $fcdistro default for yum.conf"
44 if [ -d yum.repos.d ] ; then
45 echo "Initializing yum.repos.d in $vserver from $(pwd)/yum.repos.d"
46 rm -rf /vservers/$vserver/etc/yum.repos.d
47 tar cf - yum.repos.d | tar -C /vservers/$vserver/etc -xvf -
49 echo "Cannot initialize yum.repos.d in $vserver"
52 if [ -n "$MYPLC_MODE" ] ; then
53 if [ ! -d /vservers/$vserver/etc/yum.repos.d ] ; then
54 echo "WARNING : cannot create myplc repo"
56 # exclude kernel from fedora repos
57 for i in /vservers/$vserver/etc/yum.repos.d/* ; do
58 echo "exclude=kernel* ulogd iptables" >> $i
60 # the build repo is not signed at this stage
61 cat > /vservers/$vserver/etc/yum.repos.d/myplc.repo <<EOF
73 function setup_vserver () {
83 if [ -d /vservers/$vserver ] ; then
84 echo "$COMMAND : vserver $vserver seems to exist - bailing out"
89 # try to work around the vserver issue:
90 # vc_ctx_migrate: No such process
91 # rpm-fake.so: failed to initialize communication with resolver
92 for i in 1 2 3 4 5 ; do
93 $personality vserver $VERBOSE $vserver build $VSERVER_OPTIONS -m yum -- -d $fcdistro && break || true
94 echo "Waiting for one minute"
98 [ -d /vservers/$vserver ]
100 if [ ! -z "$personality" ] ; then
101 registered_personality=$(grep $personality /etc/vservers/$vserver/personality | wc -l)
102 if [ $registered_personality -eq 0 -a "$personality" != "linux64" ] ; then
103 echo $personality >> /etc/vservers/$vserver/personality
107 if [ -n "$VBUILD_MODE" ] ; then
108 # set up appropriate vserver capabilities to mount, mknod and IPC_LOCK
109 BCAPFILE=/etc/vservers/$vserver/bcapabilities
111 cap=$(grep ^CAP_SYS_ADMIN /etc/vservers/$vserver/bcapabilities | wc -l)
112 [ $cap -eq 0 ] && echo 'CAP_SYS_ADMIN' >> /etc/vservers/$vserver/bcapabilities
113 cap=$(grep ^CAP_MKNOD /etc/vservers/$vserver/bcapabilities | wc -l)
114 [ $cap -eq 0 ] && echo 'CAP_MKNOD' >> /etc/vservers/$vserver/bcapabilities
115 cap=$(grep ^CAP_IPC_LOCK /etc/vservers/$vserver/bcapabilities | wc -l)
116 [ $cap -eq 0 ] && echo 'CAP_IPC_LOCK' >> /etc/vservers/$vserver/bcapabilities
119 $personality vyum $vserver -- -y install yum
120 $personality vserver $VERBOSE $vserver pkgmgmt internalize
122 # start the vserver so we can do the following operations
123 $personality vserver $VERBOSE $vserver start
124 $personality vserver $VERBOSE $vserver exec rm -f /var/lib/rpm/__db*
125 $personality vserver $VERBOSE $vserver exec rpm --rebuilddb
127 # minimal config in the vserver for yum to work
128 configure_yum_in_vserver $vserver $fcdistro
131 cp /etc/resolv.conf /vservers/$vserver/etc/resolv.conf
134 function devel_tools () {
143 personality=$1; shift
145 # check for .pkgs file based on pldistro
146 if [ -n "$VBUILD_MODE" ] ; then
149 pkgsname=native-shell.pkgs
151 pkgsfile=$(pl_locateDistroFile $DIRNAME $pldistro $pkgsname)
153 # install individual packages, then groups
154 packages=$(pl_getPackages ${fcdistro} $pkgsfile)
155 groups=$(pl_getGroups ${fcdistro} $pkgsfile)
157 [ -n "$packages" ] && $personality vserver $vserver exec yum -y install $packages
158 [ -n "$groups" ] && $personality vserver $vserver exec yum -y groupinstall $groups
162 function post_install () {
163 if [ -n "$VBUILD_MODE" ] ; then
164 post_install_vbuild "$@"
166 post_install_myplc "$@"
170 function post_install_vbuild () {
177 personality=$1; shift
179 ### From myplc-devel-native.spec
180 # be careful to backslash $ in this, otherwise it's the root context that's going to do the evaluation
181 cat << EOF | $personality vserver $VERBOSE $vserver exec bash -x
182 # set up /dev/loop* in vserver
183 for i in \$(seq 0 255) ; do
184 mknod -m 640 /dev/loop\$i b 7 \$i
187 # create symlink for /dev/fd
188 ln -fs /proc/self/fd /dev/fd
190 # modify /etc/rpm/macros to not use /sbin/new-kernel-pkg
191 sed -i 's,/sbin/new-kernel-pkg:,,' /etc/rpm/macros
192 if [ -h "/sbin/new-kernel-pkg" ] ; then
193 filename=\$(readlink -f /sbin/new-kernel-pkg)
194 if [ "\$filename" == "/sbin/true" ] ; then
195 echo "WARNING: /sbin/new-kernel-pkg symlinked to /sbin/true"
196 echo "\tmost likely /etc/rpm/macros has /sbin/new-kernel-pkg declared in _netsharedpath."
197 echo "\tPlease remove /sbin/new-kernel-pkg from _netsharedpath and reintall mkinitrd."
202 # customize root's prompt
203 cat << PROFILE > /root/.profile
204 export PS1="[$vserver] \\w # "
210 # add a "build" user to the system
211 builduser=\$(grep "^build:" /etc/passwd | wc -l)
212 if [ \$builduser -eq 0 ] ; then
213 groupadd -o -g \$gid build;
214 useradd -o -c 'Automated Build' -u \$uid -g \$gid -n -M -s /bin/bash build;
217 # Allow build user to build certain RPMs as root
218 if [ -f /etc/sudoers ] ; then
219 buildsudo=\$(grep "^build.*ALL=(ALL).*NOPASSWD:.*ALL" /etc/sudoers | wc -l)
220 if [ \$buildsudo -eq 0 ] ; then
221 echo "build ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
223 sed -i 's,^Defaults.*requiretty,#Defaults requiretty,' /etc/sudoers
230 function post_install_myplc () {
236 personality=$1; shift
238 # be careful to backslash $ in this, otherwise it's the root context that's going to do the evaluation
239 cat << EOF | $personality vserver $VERBOSE $vserver exec bash -x
241 # customize root's prompt
242 cat << PROFILE > /root/.profile
243 export PS1="[$vserver] \\w # "
249 COMMAND_VBUILD="vbuild-init-vserver.sh"
250 COMMAND_MYPLC="myplc-init-vserver.sh"
253 echo "Usage: $COMMAND_VBUILD [options] vserver-name [ -- vserver-options ]"
254 echo "Usage: $COMMAND_MYPLC [options] vserver-name repo-url [ -- vserver-options ]"
255 echo "Requirements: you need to have a vserver-compliant kernel,"
256 echo " as well as the util-vserver RPM installed"
258 echo " This command creates a fresh vserver instance, for building, or running, myplc"
259 echo "Supported options"
260 echo " -f fcdistro - for creating the root filesystem - defaults to $DEFAULT_FCDISTRO"
261 echo " -d pldistro - defaults to $DEFAULT_PLDISTRO"
262 echo " -p personality - defaults to $DEFAULT_PERSONALITY"
263 echo " -v : verbose - passes -v to calls to vserver"
264 echo "vserver-options"
265 echo " all args after the optional -- are passed to vserver <name> build <options>"
266 echo " typical usage is e.g. --interface eth0:200.150.100.10/24"
286 while getopts "f:d:p:v" opt ; do
288 f) fcdistro=$OPTARG;;
289 d) pldistro=$OPTARG;;
290 p) personality=$OPTARG;;
296 shift $(($OPTIND - 1))
298 # parse fixed arguments
299 [[ -z "$@" ]] && usage
301 if [ -n "$MYPLC_MODE" ] ; then
302 [[ -z "$@" ]] && usage
306 # parse vserver options
307 if [[ -n "$@" ]] ; then
308 if [ "$1" == "--" ] ; then
316 [ -z "$fcdistro" ] && fcdistro=$DEFAULT_FCDISTRO
317 [ -z "$pldistro" ] && pldistro=$DEFAULT_PLDISTRO
318 [ -z "$personality" ] && personality=$DEFAULT_PERSONALITY
320 setup_vserver $vserver $fcdistro $personality
321 devel_tools $vserver $fcdistro $pldistro $personality
322 post_install $vserver $personality