X-Git-Url: http://git.grml.org/?p=grml-debootstrap.git;a=blobdiff_plain;f=grml-debootstrap;h=380bcd48e55d3519ff6609d04047ff98cdcd6219;hp=4957e8f7d46135bfbe9f59bd284e4038d0fda992;hb=3865f3eeb7510ee90c03f65b1b1ae85d731b4600;hpb=64250ae43bc04872dff70f971d6cb04bb6056ca7 diff --git a/grml-debootstrap b/grml-debootstrap index 4957e8f..380bcd4 100755 --- a/grml-debootstrap +++ b/grml-debootstrap @@ -155,6 +155,7 @@ Configuration options: --hostname Hostname of Debian system. --nopassword Do not prompt for the root password. --password Use specified password as password for user root. + --sshcopyauth Use ${HOME}/.ssh/authorized_keys to authorise root login on the target system. --sshcopyid Use locally available public keys to authorise root login on the target system. --bootappend Add specified appendline to kernel whilst booting. --chroot-scripts Execute chroot scripts from specified directory. @@ -343,7 +344,7 @@ fi # }}} # cmdline handling {{{ -CMDLINE_OPTS=mirror:,iso:,release:,target:,mntpoint:,debopt:,defaultinterfaces,interactive,nodebootstrap,nointerfaces,nokernel,nopackages,filesystem:,config:,confdir:,packages:,chroot-scripts:,scripts:,post-scripts:,pre-scripts:,debconf:,vm,vmfile,vmsize:,keep_src_list,hostname:,password:,nopassword,grmlrepos,backportrepos,bootappend:,grub:,efi:,arch:,insecure,verbose,help,version,force,debug,contrib,non-free,remove-configs,sshcopyid +CMDLINE_OPTS=mirror:,iso:,release:,target:,mntpoint:,debopt:,defaultinterfaces,interactive,nodebootstrap,nointerfaces,nokernel,nopackages,filesystem:,config:,confdir:,packages:,chroot-scripts:,scripts:,post-scripts:,pre-scripts:,debconf:,vm,vmfile,vmsize:,keep_src_list,hostname:,password:,nopassword,grmlrepos,backportrepos,bootappend:,grub:,efi:,arch:,insecure,verbose,help,version,force,debug,contrib,non-free,remove-configs,sshcopyid,sshcopyauth _opt_temp=$(getopt --name grml-debootstrap -o +m:i:r:t:p:c:d:vhV --long \ $CMDLINE_OPTS -- "$@") @@ -460,6 +461,9 @@ while :; do --sshcopyid) # Use locally available public keys to authorise root login on the target system _opt_sshcopyid=T ;; + --sshcopyauth) # Use .ssh/authorized_keys to authorise root login on the target system + _opt_sshcopyauth=T + ;; --grmlrepos) # Enable Grml repository _opt_grmlrepos=T ;; @@ -561,6 +565,7 @@ done [ "$_opt_nointerfaces" ] && NOINTERFACES="true" [ "$_opt_nokernel" ] && NOKERNEL="true" [ "$_opt_sshcopyid" ] && SSHCOPYID="true" +[ "$_opt_sshcopyauth" ] && SSHCOPYAUTH="true" [ "$_opt_bootappend" ] && BOOT_APPEND=$_opt_bootappend [ "$_opt_grub" ] && GRUB=$_opt_grub [ "$_opt_efi" ] && EFI=$_opt_efi @@ -589,6 +594,12 @@ if [ "$_opt_grub" ] && [ "$_opt_vmfile" ] ; then bailout 1 fi +if [ "${_opt_sshcopyid}" ] && [ "${_opt_sshcopyauth}" ] ; then + eerror "The --sshcopyid option is incompatible with --sshcopyauth, please drop either of them from your command line." + eend 1 + bailout 1 +fi + if [ -n "$ISO" ] && [[ "$DEBOOTSTRAP" =~ mmdebstrap$ ]] ; then eerror "The ISO option is incompatible with usage of mmdebstrap for bootstrapping." eerror "Either drop the --iso ... option or use plain debootstrap instead." @@ -1810,7 +1821,28 @@ iface ${interface} inet dhcp bailout 1 fi else - eerror "Could not open a connection to your authentication agent or the agent has no identites." + eerror "Error: Could not open a connection to your authentication agent or the agent has no identities." + eend 1 + bailout 1 + fi + fi + + if [ -n "${SSHCOPYAUTH}" ] ; then + AUTHORIZED_KEYS_SOURCE=${AUTHORIZED_KEYS_SOURCE:-${HOME}/.ssh/authorized_keys} + + if ! [ -f "${AUTHORIZED_KEYS_SOURCE}" ]; then + eerror "Error: could not read '${AUTHORIZED_KEYS_SOURCE}' for setting up SSH key login." + eend 1 + bailout 1 + fi + + AUTHORIZED_KEYS_TARGET="${MNTPOINT}/root/.ssh/" + einfo "Copying '${AUTHORIZED_KEYS_SOURCE}' to '${AUTHORIZED_KEYS_TARGET}' as requested via --sshcopyauth option." + mkdir -m 0700 -p "${AUTHORIZED_KEYS_TARGET}" + if cp "${AUTHORIZED_KEYS_SOURCE}" "${AUTHORIZED_KEYS_TARGET}" ; then + eend 0 + else + eerror "Error: copying '${AUTHORIZED_KEYS_SOURCE}' to '${AUTHORIZED_KEYS_TARGET}' failed." eend 1 bailout 1 fi