2013-04-09 15:31:56 +02:00
|
|
|
#!/bin/bash +x
|
|
|
|
|
|
2019-02-11 20:18:02 -05:00
|
|
|
# This script should help to prepare Red Hat and Red Hat-like OS (CentOS,
|
2013-04-09 15:31:56 +02:00
|
|
|
# Scientific Linux, ...) for Vagrant box usage.
|
|
|
|
|
|
|
|
|
|
# To create new box image, just install minimal base system in VM on top of not
|
|
|
|
|
# fully allocated qcow2 image. Then upload this script to the VM and run it.
|
|
|
|
|
# After script has finished, nothing else than halting machine should be done.
|
|
|
|
|
|
|
|
|
|
# For more info about creating custom box refer to
|
2016-04-27 14:08:25 +02:00
|
|
|
# https://github.com/vagrant-libvirt/vagrant-libvirt/tree/master/example_box
|
2013-04-09 15:31:56 +02:00
|
|
|
|
2013-07-24 15:44:30 +02:00
|
|
|
# We need to set a hostname.
|
2013-04-09 15:31:56 +02:00
|
|
|
if [ $# -ne 1 ]; then
|
2016-09-06 16:26:33 +01:00
|
|
|
echo "Usage: $0 <hostname>"
|
|
|
|
|
echo "Hostname should be in format vagrant-[os-name], e.g. vagrant-redhat63."
|
|
|
|
|
exit 1
|
2013-04-09 15:31:56 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
2019-02-11 20:18:02 -05:00
|
|
|
# On which version of Red Hat are we running?
|
2013-04-09 15:31:56 +02:00
|
|
|
RHEL_MAJOR_VERSION=$(sed 's/.*release \([0-9]\)\..*/\1/' /etc/redhat-release)
|
|
|
|
|
if [ $? -ne 0 ]; then
|
2019-02-11 20:18:02 -05:00
|
|
|
echo "Is this a Red Hat distro?"
|
2016-09-06 16:26:33 +01:00
|
|
|
exit 1
|
2013-04-09 15:31:56 +02:00
|
|
|
fi
|
2019-02-11 20:18:02 -05:00
|
|
|
echo "* Found Red Hat ${RHEL_MAJOR_VERSION} version."
|
2013-04-09 15:31:56 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
# Setup hostname vagrant-something.
|
|
|
|
|
FQDN="$1.vagrantup.com"
|
|
|
|
|
if grep '^HOSTNAME=' /etc/sysconfig/network > /dev/null; then
|
2016-09-06 16:26:33 +01:00
|
|
|
sed -i 's/HOSTNAME=\(.*\)/HOSTNAME='${FQDN}'/' /etc/sysconfig/network
|
2013-04-09 15:31:56 +02:00
|
|
|
else
|
2016-09-06 16:26:33 +01:00
|
|
|
echo "HOSTNAME=${FQDN}" >> /etc/sysconfig/network
|
2013-04-09 15:31:56 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Enable EPEL repository.
|
|
|
|
|
yum -y install wget
|
|
|
|
|
cd ~root
|
|
|
|
|
if [ $RHEL_MAJOR_VERSION -eq 5 ]; then
|
2016-09-06 16:26:33 +01:00
|
|
|
wget http://ftp.astral.ro/mirrors/fedora/pub/epel/5/i386/epel-release-5-4.noarch.rpm
|
|
|
|
|
EPEL_PKG="epel-release-5-4.noarch.rpm"
|
2013-04-09 15:31:56 +02:00
|
|
|
else
|
2016-09-06 16:26:33 +01:00
|
|
|
wget http://ftp.astral.ro/mirrors/fedora/pub/epel/6/i386/epel-release-6-8.noarch.rpm
|
|
|
|
|
EPEL_PKG="epel-release-6-8.noarch.rpm"
|
2013-04-09 15:31:56 +02:00
|
|
|
fi
|
|
|
|
|
rpm -i ~root/${EPEL_PKG}
|
|
|
|
|
rm -f ~root/${EPEL_PKG}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Install some required software.
|
|
|
|
|
yum -y install openssh-server openssh-clients sudo \
|
|
|
|
|
ruby ruby-devel make gcc rubygems rsync
|
|
|
|
|
chkconfig sshd on
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Users, groups, passwords and sudoers.
|
|
|
|
|
echo 'vagrant' | passwd --stdin root
|
|
|
|
|
grep 'vagrant' /etc/passwd > /dev/null
|
|
|
|
|
if [ $? -ne 0 ]; then
|
2016-09-06 16:26:33 +01:00
|
|
|
echo '* Creating user vagrant.'
|
|
|
|
|
useradd vagrant
|
|
|
|
|
echo 'vagrant' | passwd --stdin vagrant
|
2013-04-09 15:31:56 +02:00
|
|
|
fi
|
|
|
|
|
grep '^admin:' /etc/group > /dev/null || groupadd admin
|
|
|
|
|
usermod -G admin vagrant
|
|
|
|
|
|
|
|
|
|
echo 'Defaults env_keep += "SSH_AUTH_SOCK"' >> /etc/sudoers
|
|
|
|
|
echo '%admin ALL=NOPASSWD: ALL' >> /etc/sudoers
|
2013-04-10 13:15:20 +02:00
|
|
|
sed -i 's/Defaults\s*requiretty/Defaults !requiretty/' /etc/sudoers
|
2013-04-09 15:31:56 +02:00
|
|
|
|
|
|
|
|
|
2013-04-10 13:15:20 +02:00
|
|
|
# SSH setup
|
2013-07-24 15:44:30 +02:00
|
|
|
# Add Vagrant ssh key for root and vagrant accouts.
|
2013-04-10 13:15:20 +02:00
|
|
|
sed -i 's/.*UseDNS.*/UseDNS no/' /etc/ssh/sshd_config
|
|
|
|
|
|
2013-04-09 15:31:56 +02:00
|
|
|
[ -d ~root/.ssh ] || mkdir ~root/.ssh
|
|
|
|
|
chmod 700 ~root/.ssh
|
|
|
|
|
cat > ~root/.ssh/authorized_keys << EOF
|
|
|
|
|
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA6NF8iallvQVp22WDkTkyrtvp9eWW6A8YVr+kz4TjGYe7gHzIw+niNltGEFHzD8+v1I2YJ6oXevct1YeS0o9HZyN1Q9qgCgzUFtdOKLv6IedplqoPkcmF0aYet2PkEDo3MlTBckFXPITAMzF8dJSIFo9D8HfdOV0IAdx4O7PtixWKn5y2hMNG0zQPyUecp4pzC6kivAIhyfHilFR61RGL+GPXQ2MWZWFYbAGjyiYJnAmCP3NOTd0jMZEnDkbUvxhMmBYSdETk1rRgm+R4LOzFUGaHqHDLKLX+FIPKcF96hrucXzcWyLbIbEgE98OHlnVYCzRdK8jlqm8tehUc9c9WhQ== vagrant insecure public key
|
|
|
|
|
EOF
|
|
|
|
|
chmod 600 ~root/.ssh/authorized_keys
|
|
|
|
|
|
2013-07-24 15:44:30 +02:00
|
|
|
[ -d ~vagrant/.ssh ] || mkdir ~vagrant/.ssh
|
|
|
|
|
chmod 700 ~vagrant/.ssh
|
|
|
|
|
cat > ~vagrant/.ssh/authorized_keys << EOF
|
|
|
|
|
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA6NF8iallvQVp22WDkTkyrtvp9eWW6A8YVr+kz4TjGYe7gHzIw+niNltGEFHzD8+v1I2YJ6oXevct1YeS0o9HZyN1Q9qgCgzUFtdOKLv6IedplqoPkcmF0aYet2PkEDo3MlTBckFXPITAMzF8dJSIFo9D8HfdOV0IAdx4O7PtixWKn5y2hMNG0zQPyUecp4pzC6kivAIhyfHilFR61RGL+GPXQ2MWZWFYbAGjyiYJnAmCP3NOTd0jMZEnDkbUvxhMmBYSdETk1rRgm+R4LOzFUGaHqHDLKLX+FIPKcF96hrucXzcWyLbIbEgE98OHlnVYCzRdK8jlqm8tehUc9c9WhQ== vagrant insecure public key
|
|
|
|
|
EOF
|
|
|
|
|
chmod 600 ~vagrant/.ssh/authorized_keys
|
|
|
|
|
|
2013-04-09 15:31:56 +02:00
|
|
|
|
2013-04-10 14:11:27 +02:00
|
|
|
# Disable firewall and switch SELinux to permissive mode.
|
|
|
|
|
chkconfig iptables off
|
|
|
|
|
chkconfig ip6tables off
|
|
|
|
|
|
|
|
|
|
|
2013-04-09 15:31:56 +02:00
|
|
|
# Networking setup..
|
|
|
|
|
# Don't fix ethX names to hw address.
|
|
|
|
|
rm -f /etc/udev/rules.d/*persistent-net.rules
|
|
|
|
|
rm -f /etc/udev/rules.d/*-net.rules
|
|
|
|
|
rm -fr /var/lib/dhclient/*
|
|
|
|
|
|
|
|
|
|
# Interface eth0 should get IP address via dhcp.
|
|
|
|
|
cat > /etc/sysconfig/network-scripts/ifcfg-eth0 << EOF
|
|
|
|
|
DEVICE="eth0"
|
|
|
|
|
BOOTPROTO="dhcp"
|
|
|
|
|
ONBOOT="yes"
|
|
|
|
|
NM_CONTROLLED="no"
|
|
|
|
|
EOF
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Do some cleanup..
|
|
|
|
|
rm -f ~root/.bash_history
|
|
|
|
|
rm -r "$(gem env gemdir)"/doc/*
|
|
|
|
|
yum clean all
|
|
|
|
|
|
2015-09-23 18:27:28 -06:00
|
|
|
halt
|