PageRenderTime 25ms CodeModel.GetById 22ms RepoModel.GetById 1ms app.codeStats 0ms

/templates/CentOS-5.8-x86_64-reallyminimal/postinstall.sh

https://github.com/maestrodev/veewee
Shell | 132 lines | 98 code | 16 blank | 18 comment | 1 complexity | ff53682610cddb06145203205a31f46f MD5 | raw file
  1. #!/bin/bash
  2. ## responsible for installing all packages, configuring vagrant stuff
  3. # http://chrisadams.me.uk/2010/05/10/setting-up-a-centos-base-box-for-development-and-testing-with-vagrant/
  4. # http://vagrantup.com/v1/docs/base_boxes.html
  5. set -e
  6. set -u
  7. set -x
  8. echo "$0 $(date)" >> /etc/vagrant_box_build_time
  9. fail() {
  10. echo "FATAL: $*"
  11. exit 1
  12. }
  13. # remember path to this script so we can delete it later
  14. _this_script=$( readlink -e $0 )
  15. # clean up after kickstart
  16. rm -f /tmp/ks-script*
  17. # Make ssh faster by not waiting on DNS
  18. echo "UseDNS no" >> /etc/ssh/sshd_config
  19. echo "installing puppetlabs repo"
  20. rpm -i http://yum.puppetlabs.com/el/5/products/i386/puppetlabs-release-5-6.noarch.rpm
  21. ## getting these errors because we're not installing docs. we'll have to ignore
  22. ## yum install's failed exit code.
  23. ## install-info:
  24. ## No such file or directory for /usr/share/info/termcap.info.gz
  25. # kernel source is needed for vbox additions
  26. yum -y install \
  27. gcc kernel-devel-$(uname -r) \
  28. gcc-c++ zlib-devel openssl-devel readline-devel \
  29. make bzip2 which \
  30. || echo "ignored failed yum command"
  31. # install puppet
  32. echo "installing puppet"
  33. # puppet requires the 'puppet' group
  34. # http://projects.puppetlabs.com/issues/9862
  35. /usr/sbin/groupadd -r puppet
  36. yum -y install puppet
  37. # we'll install chef, too, even though it probably won't be used
  38. echo "installing chef"
  39. yum -y install ruby-devel
  40. gem install chef --no-ri --no-rdoc
  41. #Installing vagrant keys
  42. mkdir /home/vagrant/.ssh
  43. cd /home/vagrant/.ssh
  44. wget --no-check-certificate 'https://raw.github.com/mitchellh/vagrant/master/keys/vagrant.pub' -O authorized_keys
  45. chown -R vagrant:vagrant /home/vagrant/.ssh
  46. chmod 700 /home/vagrant/.ssh
  47. chmod 600 /home/vagrant/.ssh/*
  48. # Customize the message of the day
  49. echo 'Welcome to your Vagrant-built virtual machine.' > /etc/motd
  50. sed -i "s/^.*requiretty/#Defaults requiretty/" /etc/sudoers
  51. sed -i "s/^\(.*env_keep = \"\)/\1PATH SSH_AUTH_SOCK /" /etc/sudoers
  52. #Installing the virtualbox guest additions
  53. VBOX_VERSION=$(cat /home/vagrant/.vbox_version)
  54. cd /tmp
  55. mount -o loop /home/vagrant/VBoxGuestAdditions_${VBOX_VERSION}.iso /mnt
  56. sh /mnt/VBoxLinuxAdditions.run --nox11
  57. umount /mnt
  58. rm /home/vagrant/VBoxGuestAdditions_${VBOX_VERSION}.iso
  59. ## almost there. remove stuff we don't need
  60. rpm -qa | grep -- -devel | xargs yum -y erase
  61. yum -y erase \
  62. gtk2 \
  63. hicolor-icon-theme \
  64. freetype \
  65. bitstream-vera-fonts \
  66. kernel-devel \
  67. kernel-headers \
  68. cups-libs libgomp libhugetlbfs libtiff libjpeg libpng
  69. yum -y clean --enablerepo='*' all
  70. # return to level 3 as the default
  71. sed -i 's/^id:.*$/id:3:initdefault:/' /etc/inittab
  72. ## allow yum to install docs again
  73. sed -i '/^tsflags/d' /etc/yum.conf
  74. ## CLEAN ALL THE THINGS!
  75. # http://vstone.eu/reducing-vagrant-box-size/
  76. ## bash history
  77. unset HISTFILE
  78. [ -f /root/.bash_history ] && rm /root/.bash_history
  79. [ -f /home/vagrant/.bash_history ] && rm /home/vagrant/.bash_history
  80. ## log files
  81. find /var/log -type f | while read f; do echo -ne '' > $f; done;
  82. echo "whiteout root"
  83. count=$( df --sync -kP / | tail -n1 | awk '{print $4}' )
  84. let count--
  85. dd if=/dev/zero of=/whitespace bs=1024 count=${count}
  86. rm /whitespace
  87. echo "whiteout /boot"
  88. count=$( df --sync -kP /boot | tail -n1 | awk '{print $4}' )
  89. let count--
  90. dd if=/dev/zero of=/boot/whitespace bs=1024 count=${count}
  91. rm /boot/whitespace
  92. echo "whiteout swap"
  93. swappart=$( cat /proc/swaps | tail -n1 | awk '{print $1}' )
  94. /sbin/swapoff ${swappart}
  95. dd if=/dev/zero of=${swappart} || echo "ignored failed exit code from dd"
  96. /sbin/mkswap ${swappart}
  97. /sbin/swapon ${swappart}
  98. rm -f ${_this_script}
  99. reboot
  100. exit