7 # lst parsing utilities
8 PATH=$(dirname $0):$PATH . build.common
11 echo "$COMMAND : Bailing out"
15 # overwrite vserver's internal yum config from what is in
16 # .distributions/<distrib>/yum/yum.conf and /yum.repos.d
18 function configure_yum_in_vserver () {
26 cd /etc/vservers/.distributions/${fcdistro}
27 if [ -f yum/yum.conf ] ; then
28 echo "Initializing yum.conf in $vserver from $(pwd)/yum"
29 sed -e "s!@YUMETCDIR@!/etc!g;
30 s!@YUMCACHEDIR@!/var/cache/yum!g;
31 s!@YUMLOGDIR@!/var/log!g;
32 s!@YUMLOCKDIR@!/var/lock!g;
33 " yum/yum.conf > /vservers/$vserver/etc/yum.conf
35 # post process the various @...@ variables from this yum.conf file.
37 echo "Using $fcdistro default for yum.conf"
40 if [ -d yum.repos.d ] ; then
41 echo "Initializing yum.repos.d in $vserver from $(pwd)/yum.repos.d"
42 rm -rf /vservers/$vserver/etc/yum.repos.d
43 tar cf - yum.repos.d | tar -C /vservers/$vserver/etc -xvf -
45 echo "Cannot initialize yum.repos.d in $vserver"
48 if [ -n "$MYPLC_MODE" ] ; then
49 if [ ! -d /vservers/$vserver/etc/yum.repos.d ] ; then
50 echo "WARNING : cannot create myplc repo"
52 # exclude kernel from fedora repos
53 for i in /vservers/$vserver/etc/yum.repos.d/* ; do
54 echo "exclude=kernel* ulogd iptables" >> $i
56 # the build repo is not signed at this stage
57 cat > /vservers/$vserver/etc/yum.repos.d/myplc.repo <<EOF
69 function setup_vserver () {
79 if [ -d /etc/vservers/$vserver ] ; then
80 echo "$COMMAND : vserver $vserver seems to exist - bailing out"
85 $personality vserver $VERBOSE $vserver build -m yum -- -d $fcdistro
87 if [ ! -z "$personality" ] ; then
88 l32=$(grep $personality /etc/vservers/$vserver/personality | wc -l)
89 [ $l32 -eq 0 ] && echo $personality >> /etc/vservers/$vserver/personality
92 if [ -n "$VBUILD_MODE" ] ; then
93 # set up appropriate vserver capabilities to mount, mknod and IPC_LOCK
94 BCAPFILE=/etc/vservers/$vserver/bcapabilities
96 cap=$(grep ^CAP_SYS_ADMIN /etc/vservers/$vserver/bcapabilities | wc -l)
97 [ $cap -eq 0 ] && echo 'CAP_SYS_ADMIN' >> /etc/vservers/$vserver/bcapabilities
98 cap=$(grep ^CAP_MKNOD /etc/vservers/$vserver/bcapabilities | wc -l)
99 [ $cap -eq 0 ] && echo 'CAP_MKNOD' >> /etc/vservers/$vserver/bcapabilities
100 cap=$(grep ^CAP_IPC_LOCK /etc/vservers/$vserver/bcapabilities | wc -l)
101 [ $cap -eq 0 ] && echo 'CAP_IPC_LOCK' >> /etc/vservers/$vserver/bcapabilities
104 # start the vserver so we can do the following operations
105 if [ $CLONED -eq 0 ] ; then
106 $personality vyum $vserver -- -y install yum
107 $personality vserver $VERBOSE $vserver pkgmgmt internalize
109 $personality vserver $VERBOSE $vserver start
110 $personality vserver $VERBOSE $vserver exec rm -f /var/lib/rpm/__db*
111 $personality vserver $VERBOSE $vserver exec rpm --rebuilddb
113 # minimal config in the vserver for yum to work
114 configure_yum_in_vserver $vserver $fcdistro
117 cp /etc/resolv.conf /vservers/$vserver/etc/resolv.conf
120 function devel_tools () {
129 personality=$1; shift
131 # check for .lst file based on pldistro
132 if [ -n "$VBUILD_MODE" ] ; then
133 lst=${pldistro}-devel.lst
135 lst=${pldistro}-shell.lst
137 if [ -f $lst ] ; then
138 echo "$COMMAND: Using $lst"
139 elif [ -f $DIRNAME/$lst ] ; then
141 echo "$COMMAND: Using $lst"
143 echo "$COMMAND : Cannot locate $lst - exiting"
147 # install individual packages, then groups
148 packages=$(pl_getPackages2 ${fcdistro} $lst)
149 groups=$(pl_getGroups2 ${fcdistro} $lst)
151 [ -n "$packages" ] && $personality vserver $vserver exec yum -y install $packages
152 [ -n "$groups" ] && $personality vserver $vserver exec yum -y groupinstall $groups
156 function post_install () {
157 if [ -n "$VBUILD_MODE" ] ; then
158 post_install_vbuild "$@"
160 post_install_myplc "$@"
164 function post_install_vbuild () {
171 personality=$1; shift
173 ### From myplc-devel-native.spec
174 # be careful to backslash $ in this, otherwise it's the root context that's going to do the evaluation
175 cat << EOF | $personality vserver $VERBOSE $vserver exec bash -x
176 # set up /dev/loop* in vserver
177 for i in \$(seq 0 255) ; do
178 mknod -m 640 /dev/loop\$i b 7 \$i
181 # create symlink for /dev/fd
182 ln -fs /proc/self/fd /dev/fd
184 # modify /etc/rpm/macros to not use /sbin/new-kernel-pkg
185 sed -i 's,/sbin/new-kernel-pkg:,,' /etc/rpm/macros
186 if [ -h "/sbin/new-kernel-pkg" ] ; then
187 filename=\$(readlink -f /sbin/new-kernel-pkg)
188 if [ "\$filename" == "/sbin/true" ] ; then
189 echo "WARNING: /sbin/new-kernel-pkg symlinked to /sbin/true"
190 echo "\tmost likely /etc/rpm/macros has /sbin/new-kernel-pkg declared in _netsharedpath."
191 echo "\tPlease remove /sbin/new-kernel-pkg from _netsharedpath and reintall mkinitrd."
196 # customize root's prompt
197 cat << PROFILE > /root/.profile
198 export PS1="[$vserver] \\w # "
204 # add a "build" user to the system
205 builduser=\$(grep "^build:" /etc/passwd | wc -l)
206 if [ \$builduser -eq 0 ] ; then
207 groupadd -o -g \$gid build;
208 useradd -o -c 'Automated Build' -u \$uid -g \$gid -n -M -s /bin/bash build;
211 # Allow build user to build certain RPMs as root
212 if [ -f /etc/sudoers ] ; then
213 buildsudo=\$(grep "^build.*ALL=(ALL).*NOPASSWD:.*ALL" /etc/sudoers | wc -l)
214 if [ \$buildsudo -eq 0 ] ; then
215 echo "build ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
217 sed -i 's,^Defaults.*requiretty,#Defaults requiretty,' /etc/sudoers
224 function post_install_myplc () {
230 personality=$1; shift
232 # be careful to backslash $ in this, otherwise it's the root context that's going to do the evaluation
233 cat << EOF | $personality vserver $VERBOSE $vserver exec bash -x
235 # customize root's prompt
236 cat << PROFILE > /root/.profile
237 export PS1="[$vserver] \\w # "
243 COMMAND_VBUILD="vbuild-init-vserver.sh"
244 COMMAND_MYPLC="myplc-init-vserver.sh"
247 echo "Usage: $COMMAND_VBUILD [-s|s|p] [-v] vserver-name distribution pldistro [personality]"
248 echo "Usage: $COMMAND_MYPLC [-s|s|p] [-v] vserver-name distribution pldistro repo-url [personality]"
249 echo "Requirements: you need to have a vserver-compliant kernel,"
250 echo " as well as the util-vserver RPM installed"
252 echo " This command creates a fresh vserver instance"
253 echo " . vserver-name : the vserver's name"
254 echo " . distribution : for creating the root filesystem, e.g. fc6"
255 echo " . pldistro: e.g. onelab"
256 echo " . repo-url: for myplc vserver, used to create a yum repository"
257 echo " . personality: last, optional, argument defaults to linux32"
258 echo "This is done in three steps"
259 echo " (*) setup phase : vserver creation, yum internalization and config (from /etc/vservers)"
260 echo " (*) tools install the tools required for building are installed"
261 echo " based on the folowing file for the actual set of packages and groups"
262 echo " vbuild mode : <pldistro>-devel.lst"
263 echo " myplc mode : <pldistro>-shell.lst"
264 echo " (*) post-install : various tunings required, as well as create a build user (vbuild only)"
266 echo " -s : skips the setup phase"
267 echo " -t : skips the tools phase"
268 echo " -p : skips the post-install"
269 echo " -v : passes -v to calls to vserver"
292 while getopts "stpvh" opt ; do
302 shift $(($OPTIND - 1))
304 [[ -z "$@" ]] && usage
306 [[ -z "$@" ]] && usage
308 [[ -z "$@" ]] && usage
310 if [ -n "$MYPLC_MODE" ] ; then
311 [[ -z "$@" ]] && usage
314 if [[ -z "$@" ]] ; then
317 personality=$1; shift
319 [[ -n "$@" ]] && usage
321 [ -n "$DO_SETUP" ] && setup_vserver $vserver $fcdistro $personality
322 [ -n "$DO_TOOLS" ] && devel_tools $vserver $fcdistro $pldistro $personality
323 [ -n "$DO_POST" ] && post_install $vserver $personality