refine strategy to spot ip address, keep on calling guest_ipv4
[build.git] / config.mlab / nodeimage.post
1 #!/bin/bash
2
3 vdir=$1
4 if [ -z "${vdir}" ] ; then
5         echo "ERROR: $0"
6         echo "Provide the directory of the root filesystem to operate on"
7         exit
8 fi
9
10 # Cleanup yum config entirely, waiting for the config files to populate this
11 rm -rf ${vdir}/etc/yum.conf ${vdir}/etc/yum.repos.d
12
13 # Tweaking services
14 # turn OFF firstboot if present, might cause the node to hang
15 chroot ${vdir} /sbin/chkconfig firstboot off || :
16 # NOTE: we're enabling util-vserver to allow it to help shutdown all slices
17 # before rebooting.  This has been problematic in the past
18 chroot ${vdir} /sbin/chkconfig util-vserver on || :
19 # enabling network as it ends up turned off on systems that come with NetworkManager, starting with fedora9
20 chroot ${vdir} /sbin/chkconfig network on || :
21 # and turn off NetworkManager if present, as it quite obviously messes with network
22 chroot ${vdir} /sbin/chkconfig NetworkManager off || :
23
24 # turn OFF vservers-default ; this is to automatically restart vservers, let nm do that
25 chroot ${vdir} /sbin/chkconfig vservers-default off || :
26 # turn ON vprocunhide ; is required with kernels that have CONFIG_VSERVER_PROC_SECURE enabled
27 # which is the case for our k32 kernel
28 chroot ${vdir} /sbin/chkconfig vprocunhide on || :
29
30 # turn OFF selinux if set
31 # this may happen accidentally if you mention too much stuff in bootstrapfs.pkgs
32 for file in /etc/sysconfig/selinux /sbin/load_policy; do
33     [ -f ${vdir}/${file} ] || { echo "$file not found in $vdir - fine" ; continue; }
34     selinuxrpm=$(chroot ${vdir} rpm -qf ${file})
35     if [ -z "$selinuxrpm" ] ; then 
36         echo "SElinux: warning : could not rpm for file $file"
37     else
38         echo "Force-removing package ${selinuxrpm}" 
39         chroot ${vdir} rpm -e --nodeps ${selinuxrpm}
40     fi
41 done
42
43 # Disable splaying of cron.
44 echo > ${vdir}/etc/sysconfig/crontab
45
46 # Add site_admin account
47 chroot ${vdir} /usr/sbin/useradd -p "" -u 502 -m site_admin
48
49 # Remove 32bit packages from 64bit system (http://wiki.centos.org/FAQ/General#head-357346ff0bf7c14b0849c3bcce39677aaca528e9) 
50 # use rpm instead of yum as /proc is not mounted at that poing 
51 if echo ${vdir} | grep -q x86_64 ; then
52     chroot ${vdir} rpm -qa --qf '%{name}.%{arch}\n' | grep 'i[36]86$' | xargs chroot ${vdir} rpm -e
53 fi
54
55 # Add a logrotate script for btmp, which logs failed ssh logins, which can
56 # grow unbounded on public plnodes and fill the root fs.
57 cat <<EOF > ${vdir}/etc/logrotate.d/btmp
58 /var/log/btmp {
59     weekly
60     minsize 1M
61     create 0600 root utmp
62     rotate 2
63     compress
64     notifempty
65 }
66 EOF
67
68 # NOTE: Force package into crucial-rpm-list for NodeUpdate
69 echo "nodebase" > ${vdir}/etc/planetlab/crucial-rpm-list
70 cat <<EOF > /tmp/nodebase.spec
71 Summary: Dummy Package for initial nodebase
72 Name: nodebase
73 Version: 0.1
74 Release: 0
75 Group: System Environment/Base
76 License: Apache 2.0
77 BuildArch: noarch
78
79 %description
80 This meta-package with no content allows 'yum update' to work on the m-lab
81 nodebase. 
82
83 %files
84 EOF
85 rpmbuild -bb /tmp/nodebase.spec
86 cp /root/rpmbuild/RPMS/noarch/nodebase-0.1-0.noarch.rpm ${vdir}/root/
87 chroot ${vdir} rpm -ihv /root/nodebase-0.1-0.noarch.rpm