From ad7c3cfdaa7c6354c951a9dbbad6ada40a1dc082 Mon Sep 17 00:00:00 2001 From: Michael Prokop Date: Thu, 13 Oct 2011 17:45:13 +0200 Subject: [PATCH 1/1] Support --nopassword option to not prompt for the root password --- chroot-script | 6 +++++- cmdlineopts.clp | 5 ++++- grml-debootstrap | 42 +++++++++++++++++++++++++----------------- grml-debootstrap.8.txt | 6 ++++++ 4 files changed, 40 insertions(+), 19 deletions(-) diff --git a/chroot-script b/chroot-script index 294b749..84086cc 100755 --- a/chroot-script +++ b/chroot-script @@ -241,6 +241,11 @@ reconfigure() { # set password of user root {{{ passwords() { + if [ -n "$NOPASSWORD" ] ; then + echo "Skip setting root password as requested." + return 0 + fi + echo "Activating shadow passwords." shadowconfig on @@ -249,7 +254,6 @@ passwords() CHPASSWD_OPTION='-m' fi - if [ -n "$ROOTPASSWORD" ] ; then echo root:"$ROOTPASSWORD" | chpasswd $CHPASSWD_OPTION export ROOTPASSWORD='' diff --git a/cmdlineopts.clp b/cmdlineopts.clp index 880b50d..cf8d08a 100644 --- a/cmdlineopts.clp +++ b/cmdlineopts.clp @@ -12,7 +12,7 @@ # should be handled in the main script, where it belongs. ################################################################################ -CMDLINE_OPTS=mirror:,iso:,release:,target:,mntpoint:,debopt:,interactive,nodebootstrap,nopackages,filesystem:,config:,confdir:,packages:,chroot-scripts:,scripts:,pre-scripts:,debconf:,vmfile,vmsize:,keep_src_list,hostname:,password:,bootappend:,grub:,arch:,insecure,verbose,help,version,force +CMDLINE_OPTS=mirror:,iso:,release:,target:,mntpoint:,debopt:,interactive,nodebootstrap,nopackages,filesystem:,config:,confdir:,packages:,chroot-scripts:,scripts:,pre-scripts:,debconf:,vmfile,vmsize:,keep_src_list,hostname:,password:,nopassword,bootappend:,grub:,arch:,insecure,verbose,help,version,force _opt_temp=`getopt --name grml-debootstrap -o +m:i:r:t:p:c:d:vhV --long \ $CMDLINE_OPTS -- "$@"` @@ -106,6 +106,9 @@ while :; do --password) # Use specified password as password for user root shift; _opt_password="$1" ;; + --nopassword) # Use specified password as password for user root + _opt_nopassword=T + ;; --bootappend) # Add specified appendline to kernel whilst booting shift; _opt_bootappend="$1" ;; diff --git a/grml-debootstrap b/grml-debootstrap index df8af46..feb7aa1 100755 --- a/grml-debootstrap +++ b/grml-debootstrap @@ -73,6 +73,7 @@ Configuration options: --debconf Pre-seed packages using specified pre-seed db file. --keep_src_list Do not overwrite user provided apt sources.list. --hostname Hostname of Debian system. + --nopassword Do not prompt for the root password. --password Use specified password as password for user root. --bootappend Add specified appendline to kernel whilst booting. --chroot-scripts Execute chroot scripts from specified directory. @@ -270,6 +271,7 @@ fi [ "$_opt_keep_src_list" ] && KEEP_SRC_LIST='yes' [ "$_opt_hostname" ] && HOSTNAME=$_opt_hostname [ "$_opt_password" ] && ROOTPASSWORD=$_opt_password +[ "$_opt_nopassword" ] && NOPASSWORD='yes' [ "$_opt_bootappend" ] && BOOT_APPEND=$_opt_bootappend [ "$_opt_grub" ] && GRUB=$_opt_grub [ "$_opt_arch" ] && ARCH=$_opt_arch @@ -465,23 +467,28 @@ prompt_for_hostname() # ask for password {{{ prompt_for_password() { - ROOTPW1='PW1' - ROOTPW2='PW2' - while [ "$ROOTPW1" != "$ROOTPW2" ]; do - ROOTPW1=$(dialog --insecure --stdout --title "${PN}" --passwordbox \ - "Please enter the password for the root account:" 10 60) - [ $? -eq 0 ] || bailout - ROOTPW2=$(dialog --insecure --stdout --title "${PN}" --passwordbox \ - "Please enter the password for the root account again for \ - confirmation:" 10 60) - [ $? -eq 0 ] || bailout - - if [ "$ROOTPW1" != "$ROOTPW2" ]; then - $(dialog --stdout --title "${PN}" --ok-label \ - "Retry" --msgbox "Passwords do not match!" 10 60) - fi - done - ROOTPASSWORD="$ROOTPW1" + if [ "$_opt_nopassword" ] ; then + einfo "Skip asking for root password as requested." + return 0 + fi + + ROOTPW1='PW1' + ROOTPW2='PW2' + while [ "$ROOTPW1" != "$ROOTPW2" ]; do + ROOTPW1=$(dialog --insecure --stdout --title "${PN}" --passwordbox \ + "Please enter the password for the root account:" 10 60) + [ $? -eq 0 ] || bailout + ROOTPW2=$(dialog --insecure --stdout --title "${PN}" --passwordbox \ + "Please enter the password for the root account again for \ + confirmation:" 10 60) + [ $? -eq 0 ] || bailout + + if [ "$ROOTPW1" != "$ROOTPW2" ]; then + $(dialog --stdout --title "${PN}" --ok-label \ + "Retry" --msgbox "Passwords do not match!" 10 60) + fi + done + ROOTPASSWORD="$ROOTPW1" } # }}} @@ -1002,6 +1009,7 @@ preparechroot() { [ -n "$PACKAGES" ] && echo "PACKAGES=$PACKAGES" >> $CHROOT_VARIABLES [ -n "$RM_APTCACHE" ] && echo "RM_APTCACHE=$RM_APTCACHE" >> $CHROOT_VARIABLES [ -n "$ROOTPASSWORD" ] && echo "ROOTPASSWORD=$ROOTPASSWORD" >> $CHROOT_VARIABLES + [ -n "$NOPASSWORD" ] && echo "NOPASSWORD=true" >> $CHROOT_VARIABLES [ -n "$SELECTED_PARTITIONS" ] && echo "SELECTED_PARTITIONS=$SELECTED_PARTITIONS" >> $CHROOT_VARIABLES [ -n "$TARGET" ] && echo "TARGET=$TARGET" >> $CHROOT_VARIABLES [ -n "$TARGET_UUID" ] && echo "TARGET_UUID=$TARGET_UUID" >> $CHROOT_VARIABLES diff --git a/grml-debootstrap.8.txt b/grml-debootstrap.8.txt index a18ad84..1ae3ff7 100644 --- a/grml-debootstrap.8.txt +++ b/grml-debootstrap.8.txt @@ -117,6 +117,12 @@ Options and environment variables Skip installation of packages defined in /etc/debootstrap/packages. +*--nopassword*:: + + Do not prompt for the root password. Note: Use the '--password' option if + you want to set the root password during an automatic installation but don't + want to use the interactive dialog. + *--insecure*:: Do not download and check signatures for retrieved Release files. -- 2.1.4