X-Git-Url: https://git.grml.org/?p=grml-debootstrap.git;a=blobdiff_plain;f=grml-debootstrap;h=823d876768eadab34bb5ae766e38043ac909feae;hp=103946cde7cef28471a709fe025ac78767ccbee3;hb=d59f0ebfda66926978b24482ede6b43e9ad51d5a;hpb=c8f145cb918ecb84d855af3bde6d484a43876212 diff --git a/grml-debootstrap b/grml-debootstrap index 103946c..823d876 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. @@ -335,10 +336,6 @@ stage() { } # }}} -# make sure we have what we need {{{ -check4progs "${DEBOOTSTRAP}" || bailout 1 -# }}} - # source main configuration file {{{ if [ -r /etc/debootstrap/config ] ; then # shellcheck disable=SC1091 @@ -347,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 -- "$@") @@ -464,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 ;; @@ -565,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 @@ -593,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." @@ -626,6 +633,8 @@ fi # }}} # make sure we have what we need {{{ +check4progs "${DEBOOTSTRAP}" || bailout 1 + if [ -n "$VIRTUAL" ] ; then check4progs kpartx parted qemu-img || bailout 1 fi @@ -1515,6 +1524,15 @@ if [[ -z "${GRUB}" ]] || ! dd if="${GRUB}" bs=512 count=1 2>/dev/null | cat -v | rm -f "${MNTPOINT}/tmp/core.img" fi + # workaround for Debian bug #918590 with lvm + udev: + # WARNING: Device /dev/... not initialized in udev database even after waiting 10000000 microseconds + if [ -d /run/udev ] ; then + einfo "Setting up bind-mount /run/udev" + mkdir -p "${MNTPOINT}"/run/udev + mount --bind /run/udev "${MNTPOINT}"/run/udev + eend $? + fi + einfo "Updating grub configuration file." chroot "${MNTPOINT}" update-grub @@ -1534,6 +1552,14 @@ fi sed -i "s;root=[^ ]\\+;root=UUID=$TARGET_UUID;" "${MNTPOINT}"/boot/grub/grub.cfg fi + # workaround for Debian bug #918590 with lvm + udev: + # WARNING: Device /dev/... not initialized in udev database even after waiting 10000000 microseconds + if mountpoint "${MNTPOINT}"/run/udev &>/dev/null ; then + einfo "Unmounting bind-mount /run/udev" + umount "${MNTPOINT}"/run/udev + eend $? + fi + umount "${MNTPOINT}"/proc umount "${MNTPOINT}"/sys umount "${MNTPOINT}"/dev/pts @@ -1783,6 +1809,8 @@ iface ${interface} inet dhcp fi if [ -n "${SSHCOPYID}" ] ; then + AUTHORIZED_KEYS_SOURCE=${AUTHORIZED_KEYS_SOURCE:-$HOME/.ssh/authorized_keys} + AUTHORIZED_KEYS_TARGET=${AUTHORIZED_KEYS_TARGET:-$MNTPOINT/root/.ssh/} if ssh-add -L >/dev/null 2>&1 ; then einfo "Use locally available public keys to authorise root login on the target system as requested via --sshcopyid option." mkdir -p "${MNTPOINT}"/root/.ssh @@ -1794,8 +1822,40 @@ iface ${interface} inet dhcp eend 1 bailout 1 fi + elif [ -f "$AUTHORIZED_KEYS_SOURCE" ]; then + einfo "copying '$AUTHORIZED_KEYS_SOURCE' to '$AUTHORIZED_KEYS_TARGET' as requested via --sshcopyid option." + mkdir -p "$AUTHORIZED_KEYS_TARGET" + chmod 0700 "$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 + else + 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 "Could not open a connection to your authentication agent or the agent has no identites." + eerror "Error: copying '${AUTHORIZED_KEYS_SOURCE}' to '${AUTHORIZED_KEYS_TARGET}' failed." eend 1 bailout 1 fi