2014-03-08 02:34:09 +00:00
|
|
|
#!/bin/bash
|
|
|
|
set -e
|
|
|
|
|
2014-03-08 05:23:06 +00:00
|
|
|
source common/ui.sh
|
2014-03-08 02:34:09 +00:00
|
|
|
|
2014-03-09 20:16:49 +00:00
|
|
|
export VAGRANT_KEY="ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA6NF8iallvQVp22WDkTkyrtvp9eWW6A8YVr+kz4TjGYe7gHzIw+niNltGEFHzD8+v1I2YJ6oXevct1YeS0o9HZyN1Q9qgCgzUFtdOKLv6IedplqoPkcmF0aYet2PkEDo3MlTBckFXPITAMzF8dJSIFo9D8HfdOV0IAdx4O7PtixWKn5y2hMNG0zQPyUecp4pzC6kivAIhyfHilFR61RGL+GPXQ2MWZWFYbAGjyiYJnAmCP3NOTd0jMZEnDkbUvxhMmBYSdETk1rRgm+R4LOzFUGaHqHDLKLX+FIPKcF96hrucXzcWyLbIbEgE98OHlnVYCzRdK8jlqm8tehUc9c9WhQ== vagrant insecure public key"
|
|
|
|
|
2014-03-08 05:23:06 +00:00
|
|
|
info "Preparing vagrant user..."
|
|
|
|
|
|
|
|
# Create vagrant user
|
|
|
|
if $(grep -q 'vagrant' ${ROOTFS}/etc/shadow); then
|
|
|
|
log 'Skipping vagrant user creation'
|
|
|
|
else
|
|
|
|
debug 'vagrant user does not exist, renaming ubuntu user...'
|
|
|
|
mv ${ROOTFS}/home/{ubuntu,vagrant}
|
|
|
|
chroot ${ROOTFS} usermod -l vagrant -d /home/vagrant ubuntu
|
|
|
|
chroot ${ROOTFS} groupmod -n vagrant ubuntu
|
|
|
|
echo -n 'vagrant:vagrant' | chroot ${ROOTFS} chpasswd
|
|
|
|
log 'Renamed ubuntu user to vagrant and changed password.'
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Configure SSH access
|
|
|
|
if [ -d ${ROOTFS}/home/vagrant/.ssh ]; then
|
|
|
|
log 'Skipping vagrant SSH credentials configuration'
|
|
|
|
else
|
|
|
|
debug 'SSH key has not been set'
|
|
|
|
mkdir -p ${ROOTFS}/home/vagrant/.ssh
|
|
|
|
echo $VAGRANT_KEY > ${ROOTFS}/home/vagrant/.ssh/authorized_keys
|
|
|
|
chroot ${ROOTFS} chown -R vagrant: /home/vagrant/.ssh
|
|
|
|
log 'SSH credentials configured for the vagrant user.'
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Enable passwordless sudo for the vagrant user
|
|
|
|
if [ -f ${ROOTFS}/etc/sudoers.d/vagrant ]; then
|
|
|
|
log 'Skipping sudoers file creation.'
|
|
|
|
else
|
|
|
|
debug 'Sudoers file was not found'
|
|
|
|
echo "vagrant ALL=(ALL) NOPASSWD:ALL" > ${ROOTFS}/etc/sudoers.d/vagrant
|
2014-03-09 06:50:33 +00:00
|
|
|
chmod 0440 ${ROOTFS}/etc/sudoers.d/vagrant
|
2014-03-08 05:23:06 +00:00
|
|
|
log 'Sudoers file created.'
|
|
|
|
fi
|