create-vmachine: Prompt for and set a root password

master
Dustin C. Hatch 2013-10-14 21:04:17 -05:00
parent 1cc87ab55d
commit 3e66d9345d
1 changed files with 13 additions and 2 deletions

View File

@ -17,6 +17,17 @@ fi
: ${MOUNTPOINT:=/mnt/new_vmachine} : ${MOUNTPOINT:=/mnt/new_vmachine}
: ${PORTAGE_PROFILE:="default/linux/amd64/13.0"} : ${PORTAGE_PROFILE:="default/linux/amd64/13.0"}
while [[ -z ${VM_ROOTPW} ]]; do
read -sp 'New VM root password: ' VM_ROOTPW
echo
read -sp 'Confirm root password: ' confirm_rootpw
echo
if [[ ${VM_ROOTPW} != ${confirm_rootpw} ]]; then
echo "Passwords don't match" >&2
unset VM_ROOTPW
fi
done
set -e set -e
PORTDIR=$(portageq envvar PORTDIR) PORTDIR=$(portageq envvar PORTDIR)
@ -116,8 +127,8 @@ ln -s /proc/mounts "${MOUNTPOINT}"/etc/mtab
ln -s /run/resolv.conf "${MOUNTPOINT}"/etc/resolv.conf ln -s /run/resolv.conf "${MOUNTPOINT}"/etc/resolv.conf
ln -s /run/ntp.conf "${MOUNTPOINT}"/etc/ntp.conf ln -s /run/ntp.conf "${MOUNTPOINT}"/etc/ntp.conf
echo "Blanking root password..." echo "Setting root password..."
sed -i 's/^root:.*/root::0:0:::::/' "${MOUNTPOINT}"/etc/shadow echo "root:${VM_ROOTPW}" | chroot "${MOUNTPOINT}" chpasswd
echo "Enabling serial console..." echo "Enabling serial console..."
sed -i 's/#s0/s0/' "${MOUNTPOINT}"/etc/inittab sed -i 's/#s0/s0/' "${MOUNTPOINT}"/etc/inittab