From 3e66d9345d677008d002e1cac7e868030368b714 Mon Sep 17 00:00:00 2001 From: "Dustin C. Hatch" Date: Mon, 14 Oct 2013 21:04:17 -0500 Subject: [PATCH] create-vmachine: Prompt for and set a root password --- create-vmachine.sh | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/create-vmachine.sh b/create-vmachine.sh index 844f4d4..be1c915 100755 --- a/create-vmachine.sh +++ b/create-vmachine.sh @@ -17,6 +17,17 @@ fi : ${MOUNTPOINT:=/mnt/new_vmachine} : ${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 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/ntp.conf "${MOUNTPOINT}"/etc/ntp.conf -echo "Blanking root password..." -sed -i 's/^root:.*/root::0:0:::::/' "${MOUNTPOINT}"/etc/shadow +echo "Setting root password..." +echo "root:${VM_ROOTPW}" | chroot "${MOUNTPOINT}" chpasswd echo "Enabling serial console..." sed -i 's/#s0/s0/' "${MOUNTPOINT}"/etc/inittab