Support --nopassword option to not prompt for the root password
authorMichael Prokop <mika@grml.org>
Thu, 13 Oct 2011 15:45:13 +0000 (17:45 +0200)
committerMichael Prokop <mika@grml.org>
Thu, 13 Oct 2011 16:35:11 +0000 (18:35 +0200)
chroot-script
cmdlineopts.clp
grml-debootstrap
grml-debootstrap.8.txt

index 294b749..84086cc 100755 (executable)
@@ -241,6 +241,11 @@ reconfigure() {
 # set password of user root {{{
 passwords()
 {
 # 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
 
   echo "Activating shadow passwords."
   shadowconfig on
 
@@ -249,7 +254,6 @@ passwords()
      CHPASSWD_OPTION='-m'
   fi
 
      CHPASSWD_OPTION='-m'
   fi
 
-
   if [ -n "$ROOTPASSWORD" ] ; then
      echo root:"$ROOTPASSWORD" | chpasswd $CHPASSWD_OPTION
      export ROOTPASSWORD=''
   if [ -n "$ROOTPASSWORD" ] ; then
      echo root:"$ROOTPASSWORD" | chpasswd $CHPASSWD_OPTION
      export ROOTPASSWORD=''
index 880b50d..cf8d08a 100644 (file)
@@ -12,7 +12,7 @@
 # should be handled in the main script, where it belongs.
 ################################################################################
 
 # 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 -- "$@"`
 
 _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"
     ;;
   --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"
     ;;
   --bootappend)        # Add specified appendline to kernel whilst booting
     shift; _opt_bootappend="$1"
     ;;
index df8af46..feb7aa1 100755 (executable)
@@ -73,6 +73,7 @@ Configuration options:
       --debconf <file>     Pre-seed packages using specified pre-seed db file.
       --keep_src_list      Do not overwrite user provided apt sources.list.
       --hostname <name>    Hostname of Debian system.
       --debconf <file>     Pre-seed packages using specified pre-seed db file.
       --keep_src_list      Do not overwrite user provided apt sources.list.
       --hostname <name>    Hostname of Debian system.
+      --nopassword         Do not prompt for the root password.
       --password <pwd>     Use specified password as password for user root.
       --bootappend <line>  Add specified appendline to kernel whilst booting.
       --chroot-scripts <d> Execute chroot scripts from specified directory.
       --password <pwd>     Use specified password as password for user root.
       --bootappend <line>  Add specified appendline to kernel whilst booting.
       --chroot-scripts <d> 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_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
 [ "$_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()
 {
 # 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 "$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
   [ -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
index a18ad84..1ae3ff7 100644 (file)
@@ -117,6 +117,12 @@ Options and environment variables
 
     Skip installation of packages defined in /etc/debootstrap/packages.
 
 
     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.
 *--insecure*::
 
     Do not download and check signatures for retrieved Release files.