X-Git-Url: https://git.grml.org/?p=grml-debootstrap.git;a=blobdiff_plain;f=grml-debootstrap;h=7246c4588e6ae87fcd5a00133e03c472eb867aa4;hp=9b04baace209784a272c3e0fff6816d492f03e17;hb=refs%2Fheads%2Fmika%2Fc-utf8;hpb=7291d0574567d25404915333bad581b4cf82cdf6 diff --git a/grml-debootstrap b/grml-debootstrap index 9b04baa..7246c45 100755 --- a/grml-debootstrap +++ b/grml-debootstrap @@ -54,8 +54,6 @@ MNTPOINT="/mnt/debootstrap.$$" [ -n "$DEBCONF" ] || DEBCONF='yes' [ -n "$DEBIAN_FRONTEND" ] || DEBIAN_FRONTEND='noninteractive' [ -n "$DEBOOTSTRAP" ] || DEBOOTSTRAP='debootstrap' -[ -n "$DEFAULT_LANGUAGE" ] || DEFAULT_LANGUAGE='en_US:en' -[ -n "$DEFAULT_LOCALES" ] || DEFAULT_LOCALES='en_US.UTF-8' [ -n "$DISK_IDENTIFIER" ] || DISK_IDENTIFIER='26ada0c0-1165-4098-884d-aafd2220c2c6' [ -n "$EXTRAPACKAGES" ] || EXTRAPACKAGES='yes' [ -n "$FALLBACK_MIRROR" ] || FALLBACK_MIRROR='http://deb.debian.org/debian' @@ -64,7 +62,6 @@ MNTPOINT="/mnt/debootstrap.$$" [ -n "$HOSTNAME" ] || HOSTNAME='grml' [ -n "$INITRD" ] || INITRD='yes' [ -n "$INSTALL_NOTES" ] || INSTALL_NOTES='/etc/debootstrap/install_notes' -[ -n "$LOCALES" ] || LOCALES='yes' [ -n "$MIRROR" ] || MIRROR="$FALLBACK_MIRROR" [ -n "$MKFS" ] || MKFS='mkfs.ext4' [ -n "$MKFS_OPTS" ] || MKFS_OPTS='' @@ -155,6 +152,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. + --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. --pre-scripts Execute scripts from specified directory (before chroot-scripts). @@ -346,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 +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 _opt_temp=$(getopt --name grml-debootstrap -o +m:i:r:t:p:c:d:vhV --long \ $CMDLINE_OPTS -- "$@") @@ -460,6 +458,9 @@ while :; do --nopassword) # Skip password dialog _opt_nopassword=T ;; + --sshcopyid) # Use locally available public keys to authorise root login on the target system + _opt_sshcopyid=T + ;; --grmlrepos) # Enable Grml repository _opt_grmlrepos=T ;; @@ -560,6 +561,7 @@ done [ "$_opt_defaultinterfaces" ] && USE_DEFAULT_INTERFACES="true" [ "$_opt_nointerfaces" ] && NOINTERFACES="true" [ "$_opt_nokernel" ] && NOKERNEL="true" +[ "$_opt_sshcopyid" ] && SSHCOPYID="true" [ "$_opt_bootappend" ] && BOOT_APPEND=$_opt_bootappend [ "$_opt_grub" ] && GRUB=$_opt_grub [ "$_opt_efi" ] && EFI=$_opt_efi @@ -575,6 +577,23 @@ done [ "$_opt_contrib" ] && COMPONENTS="$COMPONENTS contrib" [ "$_opt_non_free" ] && COMPONENTS="$COMPONENTS non-free" +# variable checks +if [ -n "${LOCALES:-}" ] ; then + ewarn "Deprecation NOTE: LOCALES handling is deprecated, please customize locale handling via post scripts instead." +fi + +if [ -n "${DEFAULT_LOCALES:-}" ] ; then + ewarn "Deprecation NOTE: DEFAULT_LOCALES handling is deprecated, please customize locale handling via post scripts instead." +fi + +if [ -n "${DEFAULT_DEFAULT_LANGUAGE:-}" ] ; then + ewarn "Deprecation NOTE: DEFAULT_DEFAULT_LANGUAGE handling is deprecated, please customize locale handling via post scripts instead." +fi + +if [ -r "${CONFFILES:-}"/locale.gen ] ; then + ewarn "Deprecation NOTE: ${CONFFILES}/locale.gen handling is deprecated, please customize locale handling via post scripts instead." +fi + # command line option checks if [ "$_opt_scripts_set" ] ; then ewarn "Deprecation NOTE: --scripts option is deprecated, please switch to --post-scripts instead." @@ -607,7 +626,7 @@ fi [ "$_opt_version" ] && { einfo "$PN - version $VERSION" - einfo "Send bug reports to bugs@grml.org or http://grml.org/bugs/" + einfo "Report bugs via https://github.com/grml/grml-debootstrap/ or https://grml.org/bugs/" eend 0 exit 0 } @@ -1616,8 +1635,6 @@ preparechroot() { [ -n "$DEBCONF" ] && echo "DEBCONF='$(sed "s,','\\\\'',g" <<<"${DEBCONF}")'" >> "$CHROOT_VARIABLES" [ -n "$DEBIAN_FRONTEND" ] && echo "DEBIAN_FRONTEND='$(sed "s,','\\\\'',g" <<<"${DEBIAN_FRONTEND}")'" >> "$CHROOT_VARIABLES" [ -n "$DEBOOTSTRAP" ] && echo "DEBOOTSTRAP='$(sed "s,','\\\\'',g" <<<"${DEBOOTSTRAP}")'" >> "$CHROOT_VARIABLES" - [ -n "$DEFAULT_LOCALES" ] && echo "DEFAULT_LOCALES='$(sed "s,','\\\\'',g" <<<"${DEFAULT_LOCALES}")'" >> "$CHROOT_VARIABLES" - [ -n "$DEFAULT_LANGUAGE" ] && echo "DEFAULT_LANGUAGE='$(sed "s,','\\\\'',g" <<<"${DEFAULT_LANGUAGE}")'" >> "$CHROOT_VARIABLES" [ -n "$EXTRAPACKAGES" ] && echo "EXTRAPACKAGES='$(sed "s,','\\\\'',g" <<<"${EXTRAPACKAGES}")'" >> "$CHROOT_VARIABLES" [ -n "$EFI" ] && echo "EFI='$(sed "s,','\\\\'',g" <<<"${EFI}")'" >> "$CHROOT_VARIABLES" [ -n "$FALLBACK_MIRROR" ] && echo "FALLBACK_MIRROR='$(sed "s,','\\\\'',g" <<<"${FALLBACK_MIRROR}")'" >> "$CHROOT_VARIABLES" @@ -1630,7 +1647,6 @@ preparechroot() { [ -n "$ISODIR" ] && echo "ISODIR='$(sed "s,','\\\\'',g" <<<"${ISO}")'" >> "$CHROOT_VARIABLES" [ -n "$ISO" ] && echo "ISO='$(sed "s,','\\\\'',g" <<<"${ISO}")'" >> "$CHROOT_VARIABLES" [ -n "$KEEP_SRC_LIST" ] && echo "KEEP_SRC_LIST='$(sed "s,','\\\\'',g" <<<"${KEEP_SRC_LIST}")'" >> "$CHROOT_VARIABLES" - [ -n "$LOCALES" ] && echo "LOCALES='$(sed "s,','\\\\'',g" <<<"${LOCALES}")'" >> "$CHROOT_VARIABLES" [ -n "$MIRROR" ] && echo "MIRROR='$(sed "s,','\\\\'',g" <<<"${MIRROR}")'" >> "$CHROOT_VARIABLES" [ -n "$MKFS" ] && echo "MKFS='$(sed "s,','\\\\'',g" <<<"${MKFS}")'" >> "$CHROOT_VARIABLES" [ -n "$NOPASSWORD" ] && echo "NOPASSWORD=\"true\"" >> "$CHROOT_VARIABLES" @@ -1694,9 +1710,6 @@ preparechroot() { # make sure we can access network [relevant for cdebootstrap/mmdebstrap] [ -f "${MNTPOINT}"/etc/resolv.conf ] || cp $VERBOSE /etc/resolv.conf "${MNTPOINT}"/etc/resolv.conf - # setup default locales - [ -n "$LOCALES" ] && cp $VERBOSE "${CONFFILES}"/locale.gen "${MNTPOINT}"/etc/locale.gen - # MAKEDEV is just a forking bomb crap, let's do it on our own instead :) ( cd "${MNTPOINT}"/dev && tar zxf /etc/debootstrap/devices.tar.gz ) @@ -1723,29 +1736,79 @@ allow-hotplug eth0 iface eth0 inet dhcp " + # add dhcp setting for Predictable Network Interface Names + if [ -x /bin/udevadm ]; then + tmpfile=$(mktemp) + for interface in /sys/class/net/*; do + udevadm info --query=all --path="${interface}" > "${tmpfile}" + # skip virtual devices, like bridges, vboxnet,... + if grep -q 'P: /devices/virtual/net/' "${tmpfile}" ; then + continue + fi + + # iterate over possible naming policies by precedence (see udev/net/link-config.c), + # use and stop on first match to have same behavior as udev's link_config_apply() + for property in ID_NET_NAME_FROM_DATABASE ID_NET_NAME_ONBOARD ID_NET_NAME_SLOT ID_NET_NAME_PATH ID_NET_NAME_MAC ; do + if grep -q "${property}" "${tmpfile}" ; then + interface=$(grep "${property}" "${tmpfile}" | sed -n -e "s/E: ${property}=\([^\$*]\)/\1/p") + DEFAULT_INTERFACES="${DEFAULT_INTERFACES} +allow-hotplug ${interface} +iface ${interface} inet dhcp +" + break + fi + done + done + rm -f "${tmpfile}" + fi + if [ -n "$NOINTERFACES" ] ; then einfo "Not installing /etc/network/interfaces as requested via --nointerfaces option" ; eend 0 elif [ -n "$USE_DEFAULT_INTERFACES" ] ; then einfo "Installing default /etc/network/interfaces as requested via --defaultinterfaces options." + mkdir -p "${MNTPOINT}/etc/network" echo "$DEFAULT_INTERFACES" > "${MNTPOINT}/etc/network/interfaces" eend $? elif [ -n "$VIRTUAL" ] ; then einfo "Setting up Virtual Machine, installing default /etc/network/interfaces" + mkdir -p "${MNTPOINT}/etc/network" echo "$DEFAULT_INTERFACES" > "${MNTPOINT}/etc/network/interfaces" eend $? elif [ -r /etc/network/interfaces ] ; then einfo "Copying /etc/network/interfaces from host to target system" + mkdir -p "${MNTPOINT}/etc/network" cp $VERBOSE /etc/network/interfaces "${MNTPOINT}/etc/network/interfaces" eend $? else ewarn "Couldn't read /etc/network/interfaces, installing default /etc/network/interfaces" + mkdir -p "${MNTPOINT}/etc/network" echo "$DEFAULT_INTERFACES" > "${MNTPOINT}/etc/network/interfaces" eend $? fi # install config file providing some example entries if [ -r /etc/network/interfaces.examples ] && [ ! -r "$MNTPOINT/etc/network/interfaces.examples" ] ; then - cp /etc/network/interfaces.examples "$MNTPOINT/etc/network/interfaces.examples" + mkdir -p "${MNTPOINT}/etc/network" + cp /etc/network/interfaces.examples "$MNTPOINT/etc/network/interfaces.examples" + fi + + if [ -n "${SSHCOPYID}" ] ; then + 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 + chmod 0700 "${MNTPOINT}"/root/.ssh + if ssh-add -L >> "${MNTPOINT}"/root/.ssh/authorized_keys ; then + eend 0 + else + eerror "Error: executing 'ssh-add -L' failed." + eend 1 + bailout 1 + fi + else + eerror "Could not open a connection to your authentication agent or the agent has no identites." + eend 1 + bailout 1 + fi fi if [ -d /run/udev ] ; then