diff -Nru initramfs-tools-0.122ubuntu8/debian/changelog initramfs-tools-0.122ubuntu8.14/debian/changelog --- initramfs-tools-0.122ubuntu8/debian/changelog 2016-04-15 20:44:51.000000000 +0000 +++ initramfs-tools-0.122ubuntu8.14/debian/changelog 2018-12-12 20:42:05.000000000 +0000 @@ -1,3 +1,147 @@ +initramfs-tools (0.122ubuntu8.14) xenial-security; urgency=medium + + * scripts/functions: include a new option to skip enslaved network + devices. (LP: #1802591) + Include the new variable NETWORK_SKIP_ENSLAVED. When set to a + value different than "0", this variable will cause any enslaved + network devices to be skipped from the list of netbootable + devices. This variable can be set via the configuration files + under /etc/initramfs-tools/ or via any configuration file under + the initrd directory /conf/conf.d/ via a hook script. + + -- Marcelo Henrique Cerri Wed, 12 Dec 2018 11:35:20 -0200 + +initramfs-tools (0.122ubuntu8.13) xenial; urgency=medium + + [ Colin Watson ] + * [b4804dd] Only sync the filesystem containing the initramfs + (Closes: #882380) (LP: #1667512) + + [ Tiago Stürmer Daitx ] + * debian/initramfs-tools.postinst: remove orphaned old-dkms initrd files + in /boot. (LP: #1791959) + + -- Tiago Stürmer Daitx Tue, 18 Sep 2018 09:18:47 +0000 + +initramfs-tools (0.122ubuntu8.12) xenial; urgency=medium + + [ Scott Moser ] + * scripts/functions: write netplan config files to /run/netplan for + network devices configured with configure_networking. (LP: #1769682) + + [ Mathieu Trudel-Lapierre ] + * scripts/functions: add 'critical: true' parameter; requires netplan + 0.32~16.04.5. (LP: #1769682) + * debian/rules: skip tests on non-x86 architectures, where they then to be + false negatives (extra macaddress matching makes the tests fail to match + expected values). + + -- Mathieu Trudel-Lapierre Wed, 16 May 2018 16:10:19 -0400 + +initramfs-tools (0.122ubuntu8.11) xenial; urgency=medium + + [ Oliver Grawert ] + * make fixrtc catch "n/a" string and fall back to a sane value for the date + command instead (LP: #1623125) + + -- Michael Vogt Wed, 20 Dec 2017 09:38:07 +0100 + +initramfs-tools (0.122ubuntu8.10) xenial; urgency=medium + + * mkinitramfs: Delete or report temporary files in /var/tmp/ on failure. + (LP: #1713004) + + -- Brian Murray Tue, 05 Dec 2017 11:17:43 -0800 + +initramfs-tools (0.122ubuntu8.9) xenial; urgency=low + + * hook-functions: include backported bnxt driver. (LP: #1712491) + + -- Andy Whitcroft Wed, 30 Aug 2017 11:10:40 +0100 + +initramfs-tools (0.122ubuntu8.8) xenial; urgency=medium + + * hook-functions: include xhci-plat-hcd in auto_add_modules_list + (LP: #1649213) + + -- Ike Panhc Wed, 14 Dec 2016 13:59:43 +0800 + +initramfs-tools (0.122ubuntu8.7) xenial; urgency=medium + + * scripts/functions: clean up configure_networking and the function + all_netbootable_interfaces to not have side-effects. (LP: #1621507) + + -- Mathieu Trudel-Lapierre Thu, 08 Dec 2016 18:01:45 +0100 + +initramfs-tools (0.122ubuntu8.6) xenial; urgency=medium + + [ Mathieu Trudel-Lapierre ] + * scripts/functions: for configure_networking: + - split out IPv6 options in its own cmdline parameter: ip6= ; always use + dhclient in this case if the value set is anything other than 'off' or + 'none'. Furthermore, parse anything other than 'on', 'dhcp' or 'any' as + the name of an interface. (LP: #1621507) + - rework the stop conditions so that we properly handle the ROUNDTTT loop, + timing out after a short period of time and trying again after a short + sleep. + - add a 'done' parameter for both ip= and ip6= so that we can properly + exit the ROUNDTTT loop once we know that either there is no work to do, + or that we've achieved what we wanted (that is, to bring up IPv4, IPv6, + or possibly both). + - return ip=dhcp to the ipconfig use case; if set, then ipconfig will be + run using any interface available, or the BOOTIF if it was set. + + [ LaMont Jones ] + * Only source ipv4 config in configure_networking() if it exists. + + -- Mathieu Trudel-Lapierre Wed, 23 Nov 2016 15:50:50 -0500 + +initramfs-tools (0.122ubuntu8.5) xenial; urgency=medium + + * scripts/functions: Revert configure_networking changes to the state at + 0.122ubuntu8.1. (LP: #1631474) + + -- Mathieu Trudel-Lapierre Thu, 13 Oct 2016 17:19:56 -0400 + +initramfs-tools (0.122ubuntu8.4) xenial; urgency=medium + + * Fix case where ip=dhcp and ip=eth0 and other ip= instances exists on + the kernel command line (LP: #1631474) + * Also fixed an error discovered by the shellcheck static code analyzer + where "$DEVICES" would be processed as a single device where-as removing + the quotes allows the list to be correctly processed by the for loop. + + -- Dave Chiluk Fri, 07 Oct 2016 16:21:50 -0500 + +initramfs-tools (0.122ubuntu8.3) xenial; urgency=medium + + * scripts/functions: make sure we can try to start all available and suitable + interfaces if ip= isn't set when setting up the network, and exit as soon + as we get an IP address. This retains the old behavior from ipconfig when + ip= is unset, for really simple remote-root scenarios. (LP: #1628306) + * scripts/functions: retain bootp/rarp behavior using ipconfig. + + -- Mathieu Trudel-Lapierre Tue, 27 Sep 2016 16:27:38 -0400 + +initramfs-tools (0.122ubuntu8.2) xenial; urgency=medium + + [ Mathieu Trudel-Lapierre ] + * scripts/functions: update configure_networking to use dhclient. + (LP: #1621507) + + [ LaMont Jones ] + * Depend/Breaks isc-dhcp-client as needed to make sure that it has + initramfs support + + -- LaMont Jones Fri, 23 Sep 2016 16:01:48 -0600 + +initramfs-tools (0.122ubuntu8.1) xenial; urgency=medium + + * hook-functions: include ehci-msm in auto_add_modules_list + (LP: #1588946) + + -- dann frazier Mon, 06 Jun 2016 12:31:45 -0600 + initramfs-tools (0.122ubuntu8) xenial; urgency=medium * init: busybox hostname doesn't support the '-b' argument, and it's diff -Nru initramfs-tools-0.122ubuntu8/debian/control initramfs-tools-0.122ubuntu8.14/debian/control --- initramfs-tools-0.122ubuntu8/debian/control 2016-02-21 21:22:01.000000000 +0000 +++ initramfs-tools-0.122ubuntu8.14/debian/control 2018-09-18 09:18:47.000000000 +0000 @@ -18,7 +18,7 @@ Suggests: bash-completion Provides: linux-initramfs-tool Conflicts: linux-initramfs-tool, usplash (<< 0.5.50) -Breaks: cryptsetup (<< 2:1.6.6-4~), elilo (<< 3.12-3.1~), lilo (<< 22.8-8.2~), s390-tools (<< 1.8.3-2~), console-setup (<< 1.72), systemd-sysv (<< 186), lvm2 (<< 2.02.111-2.1~), initscripts (<< 2.88dsf-59.3~), mountall (<< 2.0~) +Breaks: cryptsetup (<< 2:1.6.6-4~), elilo (<< 3.12-3.1~), lilo (<< 22.8-8.2~), s390-tools (<< 1.8.3-2~), console-setup (<< 1.72), systemd-sysv (<< 186), lvm2 (<< 2.02.111-2.1~), initscripts (<< 2.88dsf-59.3~), mountall (<< 2.0~), isc-dhcp-client (= 4.3.3-5ubuntu13), nplan (<< 0.32~16.04.5) Description: generic modular initramfs generator (automation) This package builds a bootable initramfs for Linux kernel packages. The initramfs is loaded along with the kernel and is responsible for @@ -28,7 +28,7 @@ Architecture: all Multi-Arch: foreign Recommends: busybox (>= 1:1.01-3) | busybox-initramfs | busybox-static -Depends: initramfs-tools-bin (= ${binary:Version}), busybox-initramfs (>= 1:1.13.3-1ubuntu5), klibc-utils (>= 2.0.4-7~), cpio, kmod | module-init-tools, udev, ${misc:Depends}, klibc-utils (>= 2.0.4-1.2~) | busybox (>= 1:1.01-3) | busybox-initramfs | busybox-static +Depends: initramfs-tools-bin (= ${binary:Version}), busybox-initramfs (>= 1:1.13.3-1ubuntu5), klibc-utils (>= 2.0.4-7~), cpio, kmod | module-init-tools, udev, ${misc:Depends}, klibc-utils (>= 2.0.4-1.2~) | busybox (>= 1:1.01-3) | busybox-initramfs | busybox-static, coreutils (>= 8.24) Suggests: bash-completion Breaks: initramfs-tools (<< 0.121~) Replaces: initramfs-tools (<< 0.121~) diff -Nru initramfs-tools-0.122ubuntu8/debian/initramfs-tools.postinst initramfs-tools-0.122ubuntu8.14/debian/initramfs-tools.postinst --- initramfs-tools-0.122ubuntu8/debian/initramfs-tools.postinst 2016-02-21 21:22:01.000000000 +0000 +++ initramfs-tools-0.122ubuntu8.14/debian/initramfs-tools.postinst 2018-09-18 09:18:47.000000000 +0000 @@ -11,4 +11,21 @@ DPKG_MAINTSCRIPT_PACKAGE='' update-initramfs -u fi +# Remove all initrd old dkms files for which there is no +# corresponding initram image in /boot (LP: #1791959). +# One shot only: +# - bug only affected users that were upgrading packages +# - new users are not affected +# - LP: #1515513 took care of removing old dkms together with the kernel +if [ "x$1" = xconfigure ] && [ -n "$2" ] && dpkg --compare-versions "$2" lt "0.122ubuntu8.13"; then + for old_dkms_file in /boot/initrd-*.img.old-dkms \ + /boot/initramfs-*.img.old-dkms \ + /boot/initrd.img-*.old-dkms \ + /boot/initrd-*.old-dkms; do + if [ ! -e "${old_dkms_file%%.old-dkms}" ]; then + rm -fv "${old_dkms_file}" + fi + done +fi + #DEBHELPER# diff -Nru initramfs-tools-0.122ubuntu8/hook-functions initramfs-tools-0.122ubuntu8.14/hook-functions --- initramfs-tools-0.122ubuntu8/hook-functions 2016-04-13 17:34:08.000000000 +0000 +++ initramfs-tools-0.122ubuntu8.14/hook-functions 2018-09-18 09:18:47.000000000 +0000 @@ -477,8 +477,8 @@ for arg in "$@" ; do case "$arg" in base) - modules="$modules ehci-pci ehci-orion ehci-hcd ohci-hcd ohci-pci uhci-hcd usbhid" - modules="$modules xhci xhci-pci xhci-hcd" + modules="$modules ehci-pci ehci-orion ehci-hcd ehci-msm ohci-hcd ohci-pci uhci-hcd usbhid" + modules="$modules xhci xhci-pci xhci-hcd xhci-plat-hcd" modules="$modules btrfs ext2 ext3 ext4 ext4dev " modules="$modules isofs jfs reiserfs squashfs udf xfs" modules="$modules nfs nfsv2 nfsv3 nfsv4" @@ -519,6 +519,8 @@ macvtap.ko pcmcia sb1000.ko team tokenring \ tun.ko usb veth.ko wan wimax wireless \ xen-netback.ko + # Ubuntu backported bnxt driver + copy_modules_dir kernel/ubuntu/bnxt ;; ide) copy_modules_dir kernel/drivers/ide diff -Nru initramfs-tools-0.122ubuntu8/init initramfs-tools-0.122ubuntu8.14/init --- initramfs-tools-0.122ubuntu8/init 2016-04-15 20:43:37.000000000 +0000 +++ initramfs-tools-0.122ubuntu8.14/init 2018-12-12 20:41:58.000000000 +0000 @@ -43,6 +43,7 @@ export ROOTFLAGS= export ROOTFSTYPE= export IP= +export IP6= export BOOT= export BOOTIF= export UBIMTD= @@ -61,6 +62,7 @@ export forcefsck=n export fsckfix= export recovery= +export NETWORK_SKIP_ENSLAVED= # mdadm needs hostname to be set. This has to be done before the udev rules are called! @@ -125,6 +127,9 @@ ip=*) IP="${x#ip=}" ;; + ip6=*) + IP6="${x#ip6=}" + ;; boot=*) BOOT=${x#boot=} ;; @@ -315,6 +320,7 @@ unset ROOTDELAY unset ROOT unset IP +unset IP6 unset BOOT unset BOOTIF unset UBIMTD diff -Nru initramfs-tools-0.122ubuntu8/mkinitramfs initramfs-tools-0.122ubuntu8.14/mkinitramfs --- initramfs-tools-0.122ubuntu8/mkinitramfs 2016-02-21 21:22:01.000000000 +0000 +++ initramfs-tools-0.122ubuntu8.14/mkinitramfs 2018-09-18 09:18:47.000000000 +0000 @@ -163,10 +163,26 @@ depmod ${version} fi +# Prepare to clean up temporary files on exit +DESTDIR= +__TMPCPIOGZ= +__TMPEARLYCPIO= +clean_on_exit() { + if [ "${keep}" = "y" ]; then + echo "Working files in ${DESTDIR:-}, early initramfs in ${__TMPEARLYCPIO:-} and overlay in ${__TMPCPIOGZ:-}" + else + for path in "${DESTDIR}" "${__TMPCPIOGZ}" "${__TMPEARLYCPIO}"; do + test -z "${path}" || rm -rf "${path}" + done + fi +} +trap clean_on_exit EXIT +trap "exit 1" INT TERM # makes the EXIT trap effective even when killed + +# Create temporary directory and files for initramfs contents [ -n "${TMPDIR}" ] && [ ! -w "${TMPDIR}" ] && unset TMPDIR DESTDIR="$(mktemp -d ${TMPDIR:-/var/tmp}/mkinitramfs_XXXXXX)" || exit 1 chmod 755 "${DESTDIR}" - __TMPCPIOGZ="$(mktemp ${TMPDIR:-/var/tmp}/mkinitramfs-OL_XXXXXX)" || exit 1 __TMPEARLYCPIO="$(mktemp ${TMPDIR:-/var/tmp}/mkinitramfs-FW_XXXXXX)" || exit 1 @@ -387,12 +403,4 @@ cat "${__TMPCPIOGZ}" >>"${outfile}" || exit 1 fi -if [ "${keep}" = "y" ]; then - echo "Working files in ${DESTDIR}, early initramfs in ${__TMPEARLYCPIO} and overlay in ${__TMPCPIOGZ}" -else - rm -rf "${DESTDIR}" - rm -rf "${__TMPCPIOGZ}" - rm -rf "${__TMPEARLYCPIO}" -fi - exit 0 diff -Nru initramfs-tools-0.122ubuntu8/scripts/functions initramfs-tools-0.122ubuntu8.14/scripts/functions --- initramfs-tools-0.122ubuntu8/scripts/functions 2016-03-05 09:47:31.000000000 +0000 +++ initramfs-tools-0.122ubuntu8.14/scripts/functions 2018-12-12 20:41:58.000000000 +0000 @@ -194,6 +194,48 @@ return ${RET} } +all_netbootable_devices() +{ + local NETBOOTABLE + NETBOOTABLE="" + + for device in /sys/class/net/* ; do + if [ ! -e "$device/flags" ]; then + continue + fi + + loop=$(($(cat "$device/flags") & 0x8 && 1 || 0)) + bc=$(($(cat "$device/flags") & 0x2 && 1 || 0)) + ptp=$(($(cat "$device/flags") & 0x10 && 1 || 0)) + + # Skip any device that is a loopback + if [ $loop = 1 ]; then + continue + fi + + # Skip any device that isn't a broadcast + # or point-to-point. + if [ $bc = 0 ] && [ $ptp = 0 ]; then + continue + fi + + if [ "${NETWORK_SKIP_ENSLAVED:-0}" = 0 ]; then + NETBOOTABLE="$NETBOOTABLE $(basename $device)" + else + # Skip enslaved device (has "master" link + # attribute on it) + dev="$(basename $device)" + ip -o link show "$dev" | grep -q -w master + if [ "$?" -eq 0 ]; then + continue + fi + NETBOOTABLE="$NETBOOTABLE $dev" + fi + done + + echo "$NETBOOTABLE" +} + configure_networking() { if [ -n "${BOOTIF}" ]; then @@ -226,15 +268,13 @@ current_mac=$(cat "$device/address") if [ "$bootif_mac" = "$current_mac" ]; then DEVICE=${device##*/} + DEVICE6=${device##*/} break fi fi done fi - # networking already configured thus bail out - [ -n "${DEVICE}" ] && [ -e /run/net-"${DEVICE}".conf ] && return 0 - wait_for_udev 10 # support ip options see linux sources @@ -247,16 +287,42 @@ # Ip-Config tries to create this file and when it succeds # creating the file, ipconfig is not run again. for x in /run/net-"${DEVICE}".conf /run/net-*.conf ; do - [ -e "$x" ] && break 2 + if [ -e "$x" ]; then + IP=done + break + fi done + for x in /run/net6-"${DEVICE}".conf /run/net6-*.conf ; do + if [ -e "$x" ]; then + IP6=done + break + fi + done + + # if we've reached a point where both IP and IP6 are "done", + # then we're finished with network configuration. + if [ "$IP" = done ] && [ "$IP6" = done ]; then + break + fi + case ${IP} in - none|off) + none|done|off) # Do nothing + IP=done ;; ""|on|any) # Bring up device - ipconfig -t ${ROUNDTTT} "${DEVICE}" + # if we don't have a DEVICE specified, try to bring up + # all eligible devices one at a time. + if [ "${NETWORK_SKIP_ENSLAVED:-0}" != 0 ] && [ -z "${DEVICE}" ]; then + DEVICES=$(all_netbootable_devices) + for dev in ${DEVICES} ; do + ipconfig -t ${ROUNDTTT} "${dev}" + done + else + ipconfig -t ${ROUNDTTT} "${DEVICE}" + fi ;; dhcp|bootp|rarp|both) ipconfig -t ${ROUNDTTT} -c ${IP} -d "${DEVICE}" @@ -277,17 +343,276 @@ fi ;; esac + + case ${IP6} in + ""|none|done|off) + # Do nothing + IP6=done + ;; + *) + # if this is not the first loop, sleep to provide the backoff. + [ "$(($ROUNDTTT-2))" = "0" ] || sleep $ROUNDTTT + + # check the content of IP6, if we have something other + # than a device name there and BOOTIF isn't set, clear + # DEVICE6 and we'll try all available devices. + if echo "${IP6}" | grep -qv '^\(on\|dhcp\|any\)$'; then + DEVICE6="$IP6" + fi + + # if we don't have a device specified, try to bring up + # any eligible device. + if [ -z "${DEVICE6}" ]; then + DEVICE6=$(all_netbootable_devices) + fi + + # Bring up device + for dev in ${DEVICE6} ; do + dhclient -6 -1 -v "${dev}" + done + + DEVICE6=$dev + ;; + esac + done + + # source ipconfig output for either $DEVICE or the first one. + # If the user is booting with only IPv6, then DEVICE may be set, + # but no IPv4 conf files exist. + for conf in /run/net-${DEVICE}.conf /run/net-*.conf; do + if [ -e "${conf}" ]; then + # source specific bootdevice + . ${conf} + break + fi + done + + netinfo_to_resolv_conf /etc/resolv.conf \ + /run/net-${DEVICE}.conf /run/net-*.conf /run/net6-*.conf + netinfo_to_netplan /run/netplan \ + /run/net-${DEVICE}.conf /run/net-*.conf /run/net6-*.conf +} + +netinfo_to_resolv_conf() { + # netinfo_to_resolv_conf(output, files) + # write resolv_conf from /run/net- style files. + if [ "${_in_subshell:-0}" = "0" ]; then + # subshell to avoid modification of variables by '.' + ( _in_subshell=1; netinfo_to_resolv_conf "$@" ) + return + fi + local output="$1" search="" ns="" f="" n="" + shift + for f in "$@"; do + [ -f "$f" ] || continue + unset IPV4DNS0 IPV4DNS1 IPV6DNS0 IPV6DNS1 + unset DOMAINSEARCH IPV6DOMAINSEARCH + . "$f" || { echo "WARN: failed '. \"$f\"'" 1>&2; return 1; } + for n in "${IPV4DNS0}" "${IPV4DNS1}" \ + "${IPV6DNS0}" "${IPV6DNS1}"; do + [ -n "$n" -a "$n" != "0.0.0.0" ] || continue + # skip if 'n' already in list. + case " ${ns} " in + *\ $n\ *) continue;; + esac + ns="${ns} ${n}" + done + for n in "${DOMAINSEARCH}" "${IPV6DOMAINSEARCH}"; do + [ -n "$n" ] || continue + # skip if already in search. + case " ${search}" in + *\ $n\ *) continue;; + esac + search="$search $n" + done + search=${search# } + ns=${ns# } done - # source ipconfig output - if [ -n "${DEVICE}" ]; then - # source specific bootdevice - . /run/net-${DEVICE}.conf + local rconf="" CR=" +" + for n in ${ns}; do + rconf="${rconf}nameserver $n${CR}" + done + if [ -n "${search}" ]; then + rconf="${rconf}search ${search}${CR}" + fi + if [ -z "$rconf" ]; then + echo "no search or nameservers found in $*" 1>&2 + fi + if [ "$rconf" = "-" ]; then + echo -n "$rconf" else - # source any interface... - # ipconfig should have quit after first response - . /run/net-*.conf + echo -n "$rconf" > "$output" + fi +} + +mask2cidr() { + # https://forum.openwrt.org/viewtopic.php?pid=220781#p220781 + # Assumes there's no "255." after a non-255 byte in the mask + local x=${1##*255.} + set -- 0^^^128^192^224^240^248^252^254^ $(( (${#1} - ${#x})*2 )) ${x%%.*} + x=${1%%$3*} + echo $(( $2 + (${#x}/4) )) +} + +_declare_sh_append_var() { + # append_var(name, skip, strings) + # write a declaration of name that will append to any existing + local name="$1" skip="$2" add="" n="" + shift 2 + for n in "$@"; do + [ -n "$n" -a "$n" != "$skip" ] || continue + add="$add $n" + done + add=${add# } + [ -n "$add" ] || return 0 + echo "$name=\"\${${name}:+\${${name}} }${add}\"" +} + +_declare_ip_info() { + # declare_ip_info(version, proto, address, netmask, gateway) + local version="$1" proto="$2" address="$3" netmask="$4" gateway="$5" + local netprefix="" + if [ "$proto" = "dhcp" -o "$proto" = "dhcp4" -o "$proto" = "dhcp6" ]; then + echo "dhcp${version}=true" + elif [ "$proto" = "static" ]; then + if [ -n "$address" ]; then + netprefix=$netmask + if [ "$version" = "4" ]; then + netprefix=$(mask2cidr "$netmask") + fi + _declare_sh_append_var addresses "" "$address/$netprefix" + fi + if [ -n "$gateway" ]; then + echo "gateway${version}=$gateway" + fi + fi +} + +_render_netplan() { + # write a netplan stanza for the given device. + local name="$1" mac="$2" dhcp4="$3" dhcp6="$4" addrs="$5" \ + gateway4="$6" gateway6="$7" ns_addrs="$8" ns_search="$9" + local n found="" + echo "network:" + echo " version: 2" + echo " renderer: networkd" + echo " ethernets:" + echo " $name:" + if [ -n "$mac" ]; then + echo " match:" + echo " macaddress: \"$mac\"" + echo " set-name: $name" + fi + if [ -n "$dhcp4" ]; then + echo " dhcp4: $dhcp4" + echo " dhcp-identifier: mac" fi + [ -n "$dhcp6" ] && echo " dhcp6: $dhcp6" + ( [ -n "$dhcp4" ] || [ -n "$dhcp6" ] ) && echo " critical: true" + if [ -n "$addrs" ]; then + echo " addresses:" + found="," + for n in $addrs; do + # remove dups + [ "${found#*,$n,}" = "${found}" ] || continue + found="${found}$n," + echo " - \"$n\"" + done + fi + [ -n "$gateway4" ] && echo " gateway4: \"$gateway4\"" + [ -n "$gateway6" ] && echo " gateway6: \"$gateway6\"" + + if [ -n "$ns_addrs" ]; then + local alist="[" slist="" + for n in $ns_addrs; do + # do not put in duplicates + [ "${alist#*\"$n\"}" = "$alist" ] || continue + alist="${alist}\"$n\", "; + done + alist="${alist%, }]" + + if [ -n "$ns_search" ]; then + slist="[" + for n in ${ns_search}; do + # do not put in duplicates + [ "${slist#*\"$n\"}" = "$slist" ] || continue + slist="${slist}\"$n\", "; + done + slist="${slist%, }]" + fi + echo " nameservers:" + echo " addresses: $alist" + [ -n "$slist" ] && echo " search: $slist" + fi +} + +netinfo_to_netplan() { + # read /run/net-* files write netplan config. + if [ "${_in_subshell:-0}" = "0" ]; then + # subshell to avoid modification of variables by '.' + ( _in_subshell=1; netinfo_to_netplan "$@" ) + return + fi + local out_d="$1" tmpd + if command -v mktemp >/dev/null 2>&1; then + tmpd=$(mktemp -d "${TMPDIR:-/tmp}/${0##*/}.XXXXXX") + else + tmpd="${TMPDIR:-/tmp}/${0##*/}.niinfo.$$" + mkdir -p "$tmpd" || return + fi + + local devices="" pre="" mac="" + # we go through all the files presented and create per-device files in + # a tmpdir that are shell sourceable and closer to the netplan that + # we want to render. Then render those to netplan stanzas. + for f in "$@"; do + [ -f "$f" ] || continue + unset DEVICE DEVICE6 PROTO IPV6PROTO + unset IPV6ADDR IPV6NETMASK IPV6GATEWAY + unset IPV4ADDR IPV4NETMASK IPV4GATEWAY + . "$f" || { echo "WARN: failed '. \"$f\"'" 1>&2; return 1; } + local name="" + name=${DEVICE:-${DEVICE6}} + [ -n "$name" ] || { + echo "WARN: $f did not define DEVICE or DEVICE6" 1>&2; + return 1; + } + case " ${devices} " in + *\ ${name}\ *) :;; + *) devices="${devices} ${name}" + esac + if [ ! -e "$tmpd/$name" -a -r "/sys/class/net/$name/address" ]; then + read mac < /sys/class/net/$name/address && + echo "macaddress=$mac" > "$tmpd/$name" + fi + + { + if [ -n "$DEVICE" ]; then + _declare_ip_info 4 "$PROTO" "$IPV4ADDR" "$IPV4NETMASK" "$IPV4GATEWAY" + elif [ -n "$DEVICE6" ]; then + _declare_ip_info 6 "$IPV6PROTO" "$IPV6ADDR" "$IPV6NETMASK" \ + "$IPV6GATEWAY" + fi + _declare_sh_append_var ns_addresses "0.0.0.0" \ + "${IPV4DNS0}" "${IPV4DNS1}" "${IPV6DNS0}" "${IPV6DNS1}" + _declare_sh_append_var ns_search "" "$DOMAINSEARCH" "$IPV6DOMAINSEARCH" + } >> "$tmpd/$name" + done + + [ -d "$out_d" ] || mkdir -p "$out_d" || + { echo "WARN: failed mkdir $out_d"; return 1; } + + for name in $devices; do + local macaddress="" dhcp4="" dhcp6="" addresses="" + local gateway4="" gateway6="" ns_addresses="" ns_search="" + . "$tmpd/$name" + _render_netplan "$name" "$macaddress" "$dhcp4" "$dhcp6" "$addresses" \ + "$gateway4" "$gateway6" "$ns_addresses" "$ns_search" \ + > "${out_d}/$name.yaml" + done + rm -Rf "$tmpd" } # Wait for queued kernel/udev events diff -Nru initramfs-tools-0.122ubuntu8/scripts/local-premount/fixrtc initramfs-tools-0.122ubuntu8.14/scripts/local-premount/fixrtc --- initramfs-tools-0.122ubuntu8/scripts/local-premount/fixrtc 2016-02-03 17:07:11.000000000 +0000 +++ initramfs-tools-0.122ubuntu8.14/scripts/local-premount/fixrtc 2018-09-18 09:18:47.000000000 +0000 @@ -96,6 +96,11 @@ DATE="/bin/date -D%c" date -D%c 2>/dev/null || DATE=/bin/date + if [ "$MOUNTDATE" = "n/a" ]; then + # some versions of mkfs set n/a now, date is not happy with this so + # let us use some half way sane epoch instead + MOUNTDATE="Fri Jan 1 00:00:00 1999" + fi TIMESTR=$MOUNTDATE TIME=$(${DATE} --utc --date "${TIMESTR}" +%s) diff -Nru initramfs-tools-0.122ubuntu8/tests/run-tests initramfs-tools-0.122ubuntu8.14/tests/run-tests --- initramfs-tools-0.122ubuntu8/tests/run-tests 1970-01-01 00:00:00.000000000 +0000 +++ initramfs-tools-0.122ubuntu8.14/tests/run-tests 2018-09-18 09:18:47.000000000 +0000 @@ -0,0 +1,30 @@ +#!/bin/sh +# Simply call all files named 'test_*' in the same directory as this file. +# Record their exit code as pass or fail. exit 1 if any failed. +my_dir=$(dirname "$0") + +npass=0 +nfail=0 +for test_file in "${my_dir}/test_"*; do + [ -f "$test_file" -a -x "$test_file" ] || continue + echo "executing $test_file" 1>&2 + "$test_file" + ret=$? + if [ $ret -eq 0 ]; then + npass=$(($npass+1)) + else + nfail=$(($nfail+1)) + fails="${fails:+${fails} }${test_file}" + fi +done + +if [ $nfail -ne 0 ]; then + echo "Passed $npass tests. Failed $nfail tests: ${fails}." 1>&2 + exit 1 +elif [ $npass -eq 0 ]; then + echo "No tests executed?" 1>&2 +else + echo "Passed $npass tests. Failed 0 tests." 1>&2 +fi + +exit 0 diff -Nru initramfs-tools-0.122ubuntu8/tests/test_netinfo.d/ipv4/expected-resolv.conf initramfs-tools-0.122ubuntu8.14/tests/test_netinfo.d/ipv4/expected-resolv.conf --- initramfs-tools-0.122ubuntu8/tests/test_netinfo.d/ipv4/expected-resolv.conf 1970-01-01 00:00:00.000000000 +0000 +++ initramfs-tools-0.122ubuntu8.14/tests/test_netinfo.d/ipv4/expected-resolv.conf 2018-09-18 09:18:47.000000000 +0000 @@ -0,0 +1,2 @@ +nameserver 192.168.122.1 +search foo.com diff -Nru initramfs-tools-0.122ubuntu8/tests/test_netinfo.d/ipv4/net-eth1.conf initramfs-tools-0.122ubuntu8.14/tests/test_netinfo.d/ipv4/net-eth1.conf --- initramfs-tools-0.122ubuntu8/tests/test_netinfo.d/ipv4/net-eth1.conf 1970-01-01 00:00:00.000000000 +0000 +++ initramfs-tools-0.122ubuntu8.14/tests/test_netinfo.d/ipv4/net-eth1.conf 2018-09-18 09:18:47.000000000 +0000 @@ -0,0 +1,17 @@ +DEVICE='eth1' +PROTO='dhcp' +IPV4ADDR='192.168.122.89' +IPV4BROADCAST='192.168.122.255' +IPV4NETMASK='255.255.255.0' +IPV4GATEWAY='192.168.122.1' +IPV4DNS0='192.168.122.1' +IPV4DNS1='0.0.0.0' +HOSTNAME='foohost' +DNSDOMAIN='' +NISDOMAIN='' +ROOTSERVER='192.168.122.1' +ROOTPATH='' +filename='' +UPTIME='21' +DHCPLEASETIME='3600' +DOMAINSEARCH='foo.com' diff -Nru initramfs-tools-0.122ubuntu8/tests/test_netinfo.d/ipv4/netplan/eth1.yaml initramfs-tools-0.122ubuntu8.14/tests/test_netinfo.d/ipv4/netplan/eth1.yaml --- initramfs-tools-0.122ubuntu8/tests/test_netinfo.d/ipv4/netplan/eth1.yaml 1970-01-01 00:00:00.000000000 +0000 +++ initramfs-tools-0.122ubuntu8.14/tests/test_netinfo.d/ipv4/netplan/eth1.yaml 2018-09-18 09:18:47.000000000 +0000 @@ -0,0 +1,11 @@ +network: + version: 2 + renderer: networkd + ethernets: + eth1: + dhcp4: true + dhcp-identifier: mac + critical: true + nameservers: + addresses: ["192.168.122.1"] + search: ["foo.com"] diff -Nru initramfs-tools-0.122ubuntu8/tests/test_netinfo.d/ipv4and6/expected-resolv.conf initramfs-tools-0.122ubuntu8.14/tests/test_netinfo.d/ipv4and6/expected-resolv.conf --- initramfs-tools-0.122ubuntu8/tests/test_netinfo.d/ipv4and6/expected-resolv.conf 1970-01-01 00:00:00.000000000 +0000 +++ initramfs-tools-0.122ubuntu8.14/tests/test_netinfo.d/ipv4and6/expected-resolv.conf 2018-09-18 09:18:47.000000000 +0000 @@ -0,0 +1,3 @@ +nameserver 192.168.122.1 +nameserver 2001:67c:1562:8010::2:1 +search foo.com example.com ubuntu.com diff -Nru initramfs-tools-0.122ubuntu8/tests/test_netinfo.d/ipv4and6/net6-eth0.conf initramfs-tools-0.122ubuntu8.14/tests/test_netinfo.d/ipv4and6/net6-eth0.conf --- initramfs-tools-0.122ubuntu8/tests/test_netinfo.d/ipv4and6/net6-eth0.conf 1970-01-01 00:00:00.000000000 +0000 +++ initramfs-tools-0.122ubuntu8.14/tests/test_netinfo.d/ipv4and6/net6-eth0.conf 2018-09-18 09:18:47.000000000 +0000 @@ -0,0 +1,10 @@ +DEVICE6=eth0 +HOSTNAME= +DNSDOMAIN= +IPV6PROTO=dhcp6 +IPV6ADDR=2001:67c:1562:8010:0:1:: +IPV6NETMASK=64 +IPV6DNS0=2001:67c:1562:8010::2:1 +IPV6DOMAINSEARCH="example.com ubuntu.com" +HOSTNAME= +DNSDOMAIN= diff -Nru initramfs-tools-0.122ubuntu8/tests/test_netinfo.d/ipv4and6/net-eth0.conf initramfs-tools-0.122ubuntu8.14/tests/test_netinfo.d/ipv4and6/net-eth0.conf --- initramfs-tools-0.122ubuntu8/tests/test_netinfo.d/ipv4and6/net-eth0.conf 1970-01-01 00:00:00.000000000 +0000 +++ initramfs-tools-0.122ubuntu8.14/tests/test_netinfo.d/ipv4and6/net-eth0.conf 2018-09-18 09:18:47.000000000 +0000 @@ -0,0 +1,17 @@ +DEVICE='eth0' +PROTO='dhcp' +IPV4ADDR='192.168.122.89' +IPV4BROADCAST='192.168.122.255' +IPV4NETMASK='255.255.255.0' +IPV4GATEWAY='192.168.122.1' +IPV4DNS0='192.168.122.1' +IPV4DNS1='0.0.0.0' +HOSTNAME='foohost' +DNSDOMAIN='' +NISDOMAIN='' +ROOTSERVER='192.168.122.1' +ROOTPATH='' +filename='' +UPTIME='21' +DHCPLEASETIME='3600' +DOMAINSEARCH='foo.com' diff -Nru initramfs-tools-0.122ubuntu8/tests/test_netinfo.d/ipv4and6/netplan/eth0.yaml initramfs-tools-0.122ubuntu8.14/tests/test_netinfo.d/ipv4and6/netplan/eth0.yaml --- initramfs-tools-0.122ubuntu8/tests/test_netinfo.d/ipv4and6/netplan/eth0.yaml 1970-01-01 00:00:00.000000000 +0000 +++ initramfs-tools-0.122ubuntu8.14/tests/test_netinfo.d/ipv4and6/netplan/eth0.yaml 2018-09-18 09:18:47.000000000 +0000 @@ -0,0 +1,12 @@ +network: + version: 2 + renderer: networkd + ethernets: + eth0: + dhcp4: true + dhcp-identifier: mac + dhcp6: true + critical: true + nameservers: + addresses: ["192.168.122.1", "2001:67c:1562:8010::2:1"] + search: ["foo.com", "example.com", "ubuntu.com"] diff -Nru initramfs-tools-0.122ubuntu8/tests/test_netinfo.d/ipv4static/net-eth1.conf initramfs-tools-0.122ubuntu8.14/tests/test_netinfo.d/ipv4static/net-eth1.conf --- initramfs-tools-0.122ubuntu8/tests/test_netinfo.d/ipv4static/net-eth1.conf 1970-01-01 00:00:00.000000000 +0000 +++ initramfs-tools-0.122ubuntu8.14/tests/test_netinfo.d/ipv4static/net-eth1.conf 2018-09-18 09:18:47.000000000 +0000 @@ -0,0 +1,12 @@ +DEVICE='eth1' +PROTO='static' +IPV4ADDR='10.0.0.2' +IPV4BROADCAST='10.0.0.255' +IPV4NETMASK='255.255.255.0' +IPV4GATEWAY='10.0.0.1' +IPV4DNS0='0.0.0.0' +IPV4DNS1='0.0.0.0' +HOSTNAME='foohost' +UPTIME='21' +DHCPLEASETIME='' +DOMAINSEARCH='' diff -Nru initramfs-tools-0.122ubuntu8/tests/test_netinfo.d/ipv4static/netplan/eth1.yaml initramfs-tools-0.122ubuntu8.14/tests/test_netinfo.d/ipv4static/netplan/eth1.yaml --- initramfs-tools-0.122ubuntu8/tests/test_netinfo.d/ipv4static/netplan/eth1.yaml 1970-01-01 00:00:00.000000000 +0000 +++ initramfs-tools-0.122ubuntu8.14/tests/test_netinfo.d/ipv4static/netplan/eth1.yaml 2018-09-18 09:18:47.000000000 +0000 @@ -0,0 +1,8 @@ +network: + version: 2 + renderer: networkd + ethernets: + eth1: + addresses: + - "10.0.0.2/24" + gateway4: "10.0.0.1" diff -Nru initramfs-tools-0.122ubuntu8/tests/test_netinfo.d/ipv6/expected-resolv.conf initramfs-tools-0.122ubuntu8.14/tests/test_netinfo.d/ipv6/expected-resolv.conf --- initramfs-tools-0.122ubuntu8/tests/test_netinfo.d/ipv6/expected-resolv.conf 1970-01-01 00:00:00.000000000 +0000 +++ initramfs-tools-0.122ubuntu8.14/tests/test_netinfo.d/ipv6/expected-resolv.conf 2018-09-18 09:18:47.000000000 +0000 @@ -0,0 +1,2 @@ +nameserver 2001:67c:1562:8010::2:1 +search example.com ubuntu.com diff -Nru initramfs-tools-0.122ubuntu8/tests/test_netinfo.d/ipv6/net6-eth0.conf initramfs-tools-0.122ubuntu8.14/tests/test_netinfo.d/ipv6/net6-eth0.conf --- initramfs-tools-0.122ubuntu8/tests/test_netinfo.d/ipv6/net6-eth0.conf 1970-01-01 00:00:00.000000000 +0000 +++ initramfs-tools-0.122ubuntu8.14/tests/test_netinfo.d/ipv6/net6-eth0.conf 2018-09-18 09:18:47.000000000 +0000 @@ -0,0 +1,10 @@ +DEVICE6=eno1 +HOSTNAME= +DNSDOMAIN= +IPV6PROTO=dhcp6 +IPV6ADDR=2001:67c:1562:8010:0:1:: +IPV6NETMASK=64 +IPV6DNS0=2001:67c:1562:8010::2:1 +IPV6DOMAINSEARCH="example.com ubuntu.com" +HOSTNAME= +DNSDOMAIN= diff -Nru initramfs-tools-0.122ubuntu8/tests/test_netinfo.d/ipv6/netplan/eno1.yaml initramfs-tools-0.122ubuntu8.14/tests/test_netinfo.d/ipv6/netplan/eno1.yaml --- initramfs-tools-0.122ubuntu8/tests/test_netinfo.d/ipv6/netplan/eno1.yaml 1970-01-01 00:00:00.000000000 +0000 +++ initramfs-tools-0.122ubuntu8.14/tests/test_netinfo.d/ipv6/netplan/eno1.yaml 2018-09-18 09:18:47.000000000 +0000 @@ -0,0 +1,10 @@ +network: + version: 2 + renderer: networkd + ethernets: + eno1: + dhcp6: true + critical: true + nameservers: + addresses: ["2001:67c:1562:8010::2:1"] + search: ["example.com", "ubuntu.com"] diff -Nru initramfs-tools-0.122ubuntu8/tests/test_netinfo.sh initramfs-tools-0.122ubuntu8.14/tests/test_netinfo.sh --- initramfs-tools-0.122ubuntu8/tests/test_netinfo.sh 1970-01-01 00:00:00.000000000 +0000 +++ initramfs-tools-0.122ubuntu8.14/tests/test_netinfo.sh 2018-09-18 09:18:47.000000000 +0000 @@ -0,0 +1,96 @@ +#!/bin/sh + +data_dir="${0%.sh}.d" +my_dir=$(dirname "$0") +SCRIPTS_D=$(cd "$my_dir/../scripts" && pwd) +RET_SKIP=99 +RET_FAIL=2 +RET_PASS=0 + +PASSES=0 +FAILS=0 +SKIPS=0 + +logfail() { echo "FAIL:" "$@" 1>&2; return $RET_FAIL; } +logpass() { echo "PASS:" "$@" 1>&2; return $RET_PASS; } + +pass_on_nodiff() { + # log_on_diff(tname, expected, found) + local tname="$1" expected="$2" found="$3" out="" opts="-u" + [ -d "$expected" ] && opts="-Naur" + out=$(diff $opts "$expected" "$found") + r=$? + if [ $r -eq 0 ]; then + logpass "$tname" + else + logfail "$tname: expected output differed" + echo "$out" 1>&2 + return $RET_FAIL + fi +} + +_run_in_functions() { + local name="$1" r="" + shift + sh -ec '. "$1"; shift; "$@";' \ + "test-$name" "$SCRIPTS_D/functions" "$@" || { + r=$? + logfail "$name execution returned $r. ($*)" + return $r + } +} + +run_resolvconf() { + local bname="$1" testdir="$2" results_d="$3" + local tname="$bname-netinfo-to-resolv.conf" + shift 3 + local expected="$testdir/expected-resolv.conf" + local found="$results_d/resolv.conf" + [ -f "$expected" ] || return $RET_SKIP + _run_in_functions "$tname" netinfo_to_resolv_conf "$found" "$@" || return + + pass_on_nodiff "$tname" "$expected" "$found" +} + +run_netinfo_to_netplan() { + local bname="$1" testdir="$2" results_d="$3" + local tname="$bname-netinfo-to-netplan" + shift 3 + local found_d="$results_d/netplan" + local expected_d="$testdir/netplan" + [ -d "$expected_d" ] || return $RET_SKIP + + _run_in_functions "$tname" netinfo_to_netplan "$found_d" "$@" || return + pass_on_nodiff "$tname" "$expected_d" "$found_d" +} + +record() { + local ret="$1" + case "$ret" in + 0) PASSES=$(($PASSES+1));; + $RET_SKIP) SKIPS=$(($SKIPS+1));; + *) FAILS=$(($FAILS+1));; + esac +} + +for testdir in "${data_dir}"/*; do + [ -d "$testdir" ] || continue + dname="${testdir##*/}" + results_d=$(mktemp -d "${TMPDIR:-/tmp}/${0##*/}.XXXX") + confs=$( + for f in "${testdir}"/net-*.conf "${testdir}/net6-"*.conf; do + [ -f "$f" ] && echo "$f" + done + ) + run_resolvconf "$dname" "$testdir" "$results_d" $confs + record $? + + run_netinfo_to_netplan "$dname" "$testdir" "$results_d" $confs + record $? + + rm -Rf "${results_d}" +done + +echo "INFO: ran $(($PASSES+$FAILS)) tests: $PASSES pass. $FAILS fail." +[ $FAILS -eq 0 ] +exit diff -Nru initramfs-tools-0.122ubuntu8/update-initramfs initramfs-tools-0.122ubuntu8.14/update-initramfs --- initramfs-tools-0.122ubuntu8/update-initramfs 2016-02-21 21:22:01.000000000 +0000 +++ initramfs-tools-0.122ubuntu8.14/update-initramfs 2018-09-18 09:18:47.000000000 +0000 @@ -173,7 +173,7 @@ mv -f "${initramfs}.new" "${initramfs}" set_sha1 # Guard against an unclean shutdown - sync + sync -f "${initramfs}" else mkinitramfs_return="$?" remove_initramfs_bak