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 registered_personality=$(grep $personality /etc/vservers/$vserver/personality | wc -l)
89 if [ $registered_personality -eq 0 -a "$personality" != "linux64" ] ;
90 echo $personality >> /etc/vservers/$vserver/personality
94 if [ -n "$VBUILD_MODE" ] ; then
95 # set up appropriate vserver capabilities to mount, mknod and IPC_LOCK
96 BCAPFILE=/etc/vservers/$vserver/bcapabilities
98 cap=$(grep ^CAP_SYS_ADMIN /etc/vservers/$vserver/bcapabilities | wc -l)
99 [ $cap -eq 0 ] && echo 'CAP_SYS_ADMIN' >> /etc/vservers/$vserver/bcapabilities
100 cap=$(grep ^CAP_MKNOD /etc/vservers/$vserver/bcapabilities | wc -l)
101 [ $cap -eq 0 ] && echo 'CAP_MKNOD' >> /etc/vservers/$vserver/bcapabilities
102 cap=$(grep ^CAP_IPC_LOCK /etc/vservers/$vserver/bcapabilities | wc -l)
103 [ $cap -eq 0 ] && echo 'CAP_IPC_LOCK' >> /etc/vservers/$vserver/bcapabilities
106 $personality vyum $vserver -- -y install yum
107 $personality vserver $VERBOSE $vserver pkgmgmt internalize
109 # start the vserver so we can do the following operations
110 $personality vserver $VERBOSE $vserver start
111 $personality vserver $VERBOSE $vserver exec rm -f /var/lib/rpm/__db*
112 $personality vserver $VERBOSE $vserver exec rpm --rebuilddb
114 # minimal config in the vserver for yum to work
115 configure_yum_in_vserver $vserver $fcdistro
118 cp /etc/resolv.conf /vservers/$vserver/etc/resolv.conf
121 function devel_tools () {
130 personality=$1; shift
132 # check for .lst file based on pldistro
133 if [ -n "$VBUILD_MODE" ] ; then
134 lst=${pldistro}-devel.lst
136 lst=${pldistro}-shell.lst
138 if [ -f $lst ] ; then
139 echo "$COMMAND: Using $lst"
140 elif [ -f $DIRNAME/$lst ] ; then
142 echo "$COMMAND: Using $lst"
144 echo "$COMMAND : Cannot locate $lst - exiting"
148 # install individual packages, then groups
149 packages=$(pl_getPackages2 ${fcdistro} $lst)
150 groups=$(pl_getGroups2 ${fcdistro} $lst)
152 [ -n "$packages" ] && $personality vserver $vserver exec yum -y install $packages
153 [ -n "$groups" ] && $personality vserver $vserver exec yum -y groupinstall $groups
157 function post_install () {
158 if [ -n "$VBUILD_MODE" ] ; then
159 post_install_vbuild "$@"
161 post_install_myplc "$@"
165 function post_install_vbuild () {
172 personality=$1; shift
174 ### From myplc-devel-native.spec
175 # be careful to backslash $ in this, otherwise it's the root context that's going to do the evaluation
176 cat << EOF | $personality vserver $VERBOSE $vserver exec bash -x
177 # set up /dev/loop* in vserver
178 for i in \$(seq 0 255) ; do
179 mknod -m 640 /dev/loop\$i b 7 \$i
182 # create symlink for /dev/fd
183 ln -fs /proc/self/fd /dev/fd
185 # modify /etc/rpm/macros to not use /sbin/new-kernel-pkg
186 sed -i 's,/sbin/new-kernel-pkg:,,' /etc/rpm/macros
187 if [ -h "/sbin/new-kernel-pkg" ] ; then
188 filename=\$(readlink -f /sbin/new-kernel-pkg)
189 if [ "\$filename" == "/sbin/true" ] ; then
190 echo "WARNING: /sbin/new-kernel-pkg symlinked to /sbin/true"
191 echo "\tmost likely /etc/rpm/macros has /sbin/new-kernel-pkg declared in _netsharedpath."
192 echo "\tPlease remove /sbin/new-kernel-pkg from _netsharedpath and reintall mkinitrd."
197 # customize root's prompt
198 cat << PROFILE > /root/.profile
199 export PS1="[$vserver] \\w # "
205 # add a "build" user to the system
206 builduser=\$(grep "^build:" /etc/passwd | wc -l)
207 if [ \$builduser -eq 0 ] ; then
208 groupadd -o -g \$gid build;
209 useradd -o -c 'Automated Build' -u \$uid -g \$gid -n -M -s /bin/bash build;
212 # Allow build user to build certain RPMs as root
213 if [ -f /etc/sudoers ] ; then
214 buildsudo=\$(grep "^build.*ALL=(ALL).*NOPASSWD:.*ALL" /etc/sudoers | wc -l)
215 if [ \$buildsudo -eq 0 ] ; then
216 echo "build ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
218 sed -i 's,^Defaults.*requiretty,#Defaults requiretty,' /etc/sudoers
225 function post_install_myplc () {
231 personality=$1; shift
233 # be careful to backslash $ in this, otherwise it's the root context that's going to do the evaluation
234 cat << EOF | $personality vserver $VERBOSE $vserver exec bash -x
236 # customize root's prompt
237 cat << PROFILE > /root/.profile
238 export PS1="[$vserver] \\w # "
244 COMMAND_VBUILD="vbuild-init-vserver.sh"
245 COMMAND_MYPLC="myplc-init-vserver.sh"
248 echo "Usage: $COMMAND_VBUILD [-s|s|p] [-v] vserver-name distribution pldistro [personality]"
249 echo "Usage: $COMMAND_MYPLC [-s|s|p] [-v] vserver-name distribution pldistro repo-url [personality]"
250 echo "Requirements: you need to have a vserver-compliant kernel,"
251 echo " as well as the util-vserver RPM installed"
253 echo " This command creates a fresh vserver instance"
254 echo " . vserver-name : the vserver's name"
255 echo " . distribution : for creating the root filesystem, e.g. fc6"
256 echo " . pldistro: e.g. onelab"
257 echo " . repo-url: for myplc vserver, used to create a yum repository"
258 echo " . personality: last, optional, argument defaults to linux32"
259 echo "This is done in three steps"
260 echo " (*) setup phase : vserver creation, yum internalization and config (from /etc/vservers)"
261 echo " (*) tools install the tools required for building are installed"
262 echo " based on the folowing file for the actual set of packages and groups"
263 echo " vbuild mode : <pldistro>-devel.lst"
264 echo " myplc mode : <pldistro>-shell.lst"
265 echo " (*) post-install : various tunings required, as well as create a build user (vbuild only)"
267 echo " -s : skips the setup phase"
268 echo " -t : skips the tools phase"
269 echo " -p : skips the post-install"
270 echo " -v : passes -v to calls to vserver"
293 while getopts "stpvh" opt ; do
303 shift $(($OPTIND - 1))
305 [[ -z "$@" ]] && usage
307 [[ -z "$@" ]] && usage
309 [[ -z "$@" ]] && usage
311 if [ -n "$MYPLC_MODE" ] ; then
312 [[ -z "$@" ]] && usage
315 if [[ -z "$@" ]] ; then
318 personality=$1; shift
320 [[ -n "$@" ]] && usage
322 [ -n "$DO_SETUP" ] && setup_vserver $vserver $fcdistro $personality
323 [ -n "$DO_TOOLS" ] && devel_tools $vserver $fcdistro $pldistro $personality
324 [ -n "$DO_POST" ] && post_install $vserver $personality