From 1faa69ad4719944a3ea9c7a02da21f7b5d0170d5 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Thu, 14 Jun 2012 20:55:18 +0200 Subject: [PATCH] Updating coding style in a first bunch of locations. --- scripts/boot/misc-helpers.sh | 65 +++++++----- scripts/boot/mountroot.sh | 26 +++-- scripts/boot/netbase.sh | 6 +- scripts/boot/networking.sh | 164 +++++++++++++++--------------- scripts/boot/overlay.sh | 59 ++++++----- scripts/boot/select-eth-device.sh | 68 +++++++------ 6 files changed, 212 insertions(+), 176 deletions(-) diff --git a/scripts/boot/misc-helpers.sh b/scripts/boot/misc-helpers.sh index 241bba1..cc39fcb 100755 --- a/scripts/boot/misc-helpers.sh +++ b/scripts/boot/misc-helpers.sh @@ -81,7 +81,6 @@ mount_images_in_directory () rootmnt="${2}" mac="${3}" - if match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.squashfs" || match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.ext2" || match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.ext3" || @@ -377,7 +376,8 @@ really_export () eval export "${STRING}"="${VALUE}" } -is_in_list_separator_helper () { +is_in_list_separator_helper () +{ local sep=${1} shift local element=${1} @@ -386,13 +386,15 @@ is_in_list_separator_helper () { echo ${list} | grep -qe "^\(.*${sep}\)\?${element}\(${sep}.*\)\?$" } -is_in_space_sep_list () { +is_in_space_sep_list () +{ local element=${1} shift is_in_list_separator_helper "[[:space:]]" "${element}" "${*}" } -is_in_comma_sep_list () { +is_in_comma_sep_list () +{ local element=${1} shift is_in_list_separator_helper "," "${element}" "${*}" @@ -501,10 +503,11 @@ where_is_mounted () grep -m1 "^${device} " /proc/mounts | cut -f2 -d ' ' } -trim_path () { - # remove all unnecessary /:s in the path, including last one (except - # if path is just "/") - echo ${1} | sed 's|//\+|/|g' | sed 's|^\(.*[^/]\)/$|\1|' +trim_path () +{ + # remove all unnecessary /:s in the path, including last one (except + # if path is just "/") + echo ${1} | sed 's|//\+|/|g' | sed 's|^\(.*[^/]\)/$|\1|' } what_is_mounted_on () @@ -761,7 +764,8 @@ mount_persistence_media () return 0 } -close_persistence_media () { +close_persistence_media () +{ local device=${1} local backing="$(where_is_mounted ${device})" @@ -945,8 +949,7 @@ find_persistence_media () # in order to probe any filesystem it contains, like we do # below. activate_custom_mounts() also depends on that any luks # device already has been opened. - if is_in_comma_sep_list luks ${PERSISTENCE_ENCRYPTION} && \ - is_luks_partition ${dev} + if is_in_comma_sep_list luks ${PERSISTENCE_ENCRYPTION} && is_luks_partition ${dev} then if luks_device=$(open_luks_device "${dev}") then @@ -991,8 +994,7 @@ find_persistence_media () fi # Close luks device if it isn't used - if [ -z "${result}" ] && [ -n "${luks_device}" ] && \ - is_active_luks_mapping "${luks_device}" + if [ -z "${result}" ] && [ -n "${luks_device}" ] && is_active_luks_mapping "${luks_device}" then /sbin/cryptsetup luksClose "${luks_device}" fi @@ -1034,7 +1036,8 @@ is_active_luks_mapping () /sbin/cryptsetup status "${device}" 1>/dev/null 2>&1 } -get_luks_backing_device () { +get_luks_backing_device () +{ device=${1} cryptsetup status ${device} 2> /dev/null | \ awk '{if ($1 == "device:") print $2}' @@ -1131,7 +1134,9 @@ link_files () return fi - find "${src_dir}" -mindepth 1 -maxdepth 1 | while read src; do + find "${src_dir}" -mindepth 1 -maxdepth 1 | \ + while read src + do local dest="${dest_dir}$(basename "${src}")" if [ -d "${src}" ] then @@ -1166,19 +1171,23 @@ do_union () local unionro1="${3}" # first underlying read-only branch (optional) local unionro2="${4}" # second underlying read-only branch (optional) - if [ "${UNIONTYPE}" = "aufs" ] - then - rw_opt="rw" - ro_opt="rr+wh" - noxino_opt="noxino" - elif [ "${UNIONTYPE}" = "unionfs-fuse" ] - then - rw_opt="RW" - ro_opt="RO" - else - rw_opt="rw" - ro_opt="ro" - fi + case "${UNIONTYPE}" in + aufs) + rw_opt="rw" + ro_opt="rr+wh" + noxino_opt="noxino" + ;; + + unionfs-fuse) + rw_opt="RW" + ro_opt="RO" + ;; + + *) + rw_opt="rw" + ro_opt="ro" + ;; + esac case "${UNIONTYPE}" in unionfs-fuse) diff --git a/scripts/boot/mountroot.sh b/scripts/boot/mountroot.sh index dbc66d4..5383747 100755 --- a/scripts/boot/mountroot.sh +++ b/scripts/boot/mountroot.sh @@ -4,8 +4,9 @@ mountroot () { - if [ -x /scripts/local-top/cryptroot ]; then - /scripts/local-top/cryptroot + if [ -x /scripts/local-top/cryptroot ] + then + /scripts/local-top/cryptroot fi exec 6>&1 @@ -136,7 +137,8 @@ mountroot () fi - if [ -n "${ROOT_PID}" ] ; then + if [ -n "${ROOT_PID}" ] + then echo "${ROOT_PID}" > "${rootmnt}"/live/root.pid fi @@ -144,10 +146,11 @@ mountroot () # unionfs-fuse needs /dev to be bind-mounted for the duration of # live-bottom; udev's init script will take care of things after that - if [ "${UNIONTYPE}" = unionfs-fuse ] - then - mount -n -o bind /dev "${rootmnt}/dev" - fi + case "${UNIONTYPE}" in + unionfs-fuse) + mount -n -o bind /dev "${rootmnt}/dev" + ;; + esac # Move to the new root filesystem so that programs there can get at it. if [ ! -d /root/live/image ] @@ -205,10 +208,11 @@ mountroot () ;; esac - if [ "${UNIONFS}" = unionfs-fuse ] - then - umount "${rootmnt}/dev" - fi + case "${UNIONFS}" in + unionfs-fuse) + umount "${rootmnt}/dev" + ;; + esac exec 1>&6 6>&- exec 2>&7 7>&- diff --git a/scripts/boot/netbase.sh b/scripts/boot/netbase.sh index 0528817..3f5f7af 100755 --- a/scripts/boot/netbase.sh +++ b/scripts/boot/netbase.sh @@ -17,7 +17,7 @@ Netbase () IFFILE="/root/etc/network/interfaces" - if [ "${STATICIP}" = "frommedia" -a -e "${IFFILE}" ] + if [ "${STATICIP}" = "frommedia" ] && [ -e "${IFFILE}" ] then # will use existent /etc/network/interfaces log_end_msg @@ -33,9 +33,9 @@ EOF udevadm trigger udevadm settle - if [ -z "${NETBOOT}" -a -n "${STATICIP}" -a "${STATICIP}" != "frommedia" ] + if [ -z "${NETBOOT}" ] && [ -n "${STATICIP}" ] && [ "${STATICIP}" != "frommedia" ] then - parsed=$(echo "${STATICIP}" | sed -e 's/,/ /g') + parsed=$(echo "${STATICIP}" | sed -e 's|,| |g') for ifline in ${parsed} do diff --git a/scripts/boot/networking.sh b/scripts/boot/networking.sh index 3d22a90..8c8d840 100755 --- a/scripts/boot/networking.sh +++ b/scripts/boot/networking.sh @@ -12,98 +12,101 @@ do_netsetup () [ -n "$ETHDEV_TIMEOUT" ] || ETHDEV_TIMEOUT=15 echo "Using timeout of $ETHDEV_TIMEOUT seconds for network configuration." - if [ -z "${NETBOOT}" ] && [ -z "${FETCH}" ] && \ - [ -z "${HTTPFS}" ] && [ -z "${FTPFS}" ] + if [ -z "${NETBOOT}" ] && [ -z "${FETCH}" ] && [ -z "${HTTPFS}" ] && [ -z "${FTPFS}" ] then + # support for Syslinux IPAPPEND parameter + # it sets the BOOTIF variable on the kernel parameter + if [ -n "${BOOTIF}" ] + then + # pxelinux sets BOOTIF to a value based on the mac address of the + # network card used to PXE boot, so use this value for DEVICE rather + # than a hard-coded device name from initramfs.conf. this facilitates + # network booting when machines may have multiple network cards. + # pxelinux sets BOOTIF to 01-$mac_address + + # strip off the leading "01-", which isn't part of the mac + # address + temp_mac=${BOOTIF#*-} + + # convert to typical mac address format by replacing "-" with ":" + bootif_mac="" + IFS='-' + for x in $temp_mac + do + if [ -z "$bootif_mac" ] + then + bootif_mac="$x" + else + bootif_mac="$bootif_mac:$x" + fi + done + unset IFS - # support for Syslinux IPAPPEND parameter - # it sets the BOOTIF variable on the kernel parameter + # look for devices with matching mac address, and set DEVICE to + # appropriate value if match is found. - if [ -n "${BOOTIF}" ] - then - # pxelinux sets BOOTIF to a value based on the mac address of the - # network card used to PXE boot, so use this value for DEVICE rather - # than a hard-coded device name from initramfs.conf. this facilitates - # network booting when machines may have multiple network cards. - # pxelinux sets BOOTIF to 01-$mac_address - - # strip off the leading "01-", which isn't part of the mac - # address - temp_mac=${BOOTIF#*-} - - # convert to typical mac address format by replacing "-" with ":" - bootif_mac="" - IFS='-' - for x in $temp_mac + for device in /sys/class/net/* + do + if [ -f "$device/address" ] + then + current_mac=$(cat "$device/address") + + if [ "$bootif_mac" = "$current_mac" ] + then + DEVICE=${device##*/} + break + fi + fi + done + fi + + # if ethdevice was not specified on the kernel command line + # make sure we try to get a working network configuration + # for *every* present network device (except for loopback of course) + if [ -z "$ETHDEVICE" ] + then + echo "If you want to boot from a specific device use bootoption ethdevice=..." + for device in /sys/class/net/* + do + dev=${device##*/} + if [ "$dev" != "lo" ] + then + ETHDEVICE="$ETHDEVICE $dev" + fi + done + fi + + # split args of ethdevice=eth0,eth1 into "eth0 eth1" + for device in $(echo $ETHDEVICE | sed 's/,/ /g') do - if [ -z "$bootif_mac" ] - then - bootif_mac="$x" - else - bootif_mac="$bootif_mac:$x" - fi + devlist="$devlist $device" done - unset IFS - - # look for devices with matching mac address, and set DEVICE to - # appropriate value if match is found. - for device in /sys/class/net/* + # this is tricky (and ugly) because ipconfig sometimes just hangs/runs into + # an endless loop; if execution fails give it two further tries, that's + # why we use '$devlist $devlist $devlist' for the other for loop + for dev in $devlist $devlist $devlist do - if [ -f "$device/address" ] + echo "Executing ipconfig -t $ETHDEV_TIMEOUT $dev" + ipconfig -t "$ETHDEV_TIMEOUT" $dev | tee -a /netboot.config & + jobid=$! + sleep "$ETHDEV_TIMEOUT" ; sleep 1 + if [ -r /proc/"$jobid"/status ] then - current_mac=$(cat "$device/address") - - if [ "$bootif_mac" = "$current_mac" ] - then - DEVICE=${device##*/} - break - fi + echo "Killing job $jobid for device $dev as ipconfig ran into recursion..." + kill -9 $jobid fi - done - fi - # if ethdevice was not specified on the kernel command line - # make sure we try to get a working network configuration - # for *every* present network device (except for loopback of course) - if [ -z "$ETHDEVICE" ] ; then - echo "If you want to boot from a specific device use bootoption ethdevice=..." - for device in /sys/class/net/*; do - dev=${device##*/} ; - if [ "$dev" != "lo" ] ; then - ETHDEVICE="$ETHDEVICE $dev" + # if configuration of device worked we should have an assigned + # IP address, if so let's use the device as $DEVICE for later usage. + # simple and primitive approach which seems to work fine + if ifconfig $dev | grep -q 'inet.*addr:' + then + export DEVICE="$dev" + break fi done - fi - - # split args of ethdevice=eth0,eth1 into "eth0 eth1" - for device in $(echo $ETHDEVICE | sed 's/,/ /g') ; do - devlist="$devlist $device" - done - - # this is tricky (and ugly) because ipconfig sometimes just hangs/runs into - # an endless loop; if execution fails give it two further tries, that's - # why we use '$devlist $devlist $devlist' for the other for loop - for dev in $devlist $devlist $devlist ; do - echo "Executing ipconfig -t $ETHDEV_TIMEOUT $dev" - ipconfig -t "$ETHDEV_TIMEOUT" $dev | tee -a /netboot.config & - jobid=$! - sleep "$ETHDEV_TIMEOUT" ; sleep 1 - if [ -r /proc/"$jobid"/status ] ; then - echo "Killing job $jobid for device $dev as ipconfig ran into recursion..." - kill -9 $jobid - fi - - # if configuration of device worked we should have an assigned - # IP address, if so let's use the device as $DEVICE for later usage. - # simple and primitive approach which seems to work fine - if ifconfig $dev | grep -q 'inet.*addr:' ; then - export DEVICE="$dev" - break - fi - done - else for interface in ${DEVICE}; do ipconfig -t "$ETHDEV_TIMEOUT" ${interface} | tee /netboot-${interface}.config @@ -115,7 +118,8 @@ do_netsetup () done fi - for interface in ${DEVICE}; do + for interface in ${DEVICE} + do # source relevant ipconfig output OLDHOSTNAME=${HOSTNAME} [ -e /tmp/net-${interface}.conf ] && . /tmp/net-${interface}.conf diff --git a/scripts/boot/overlay.sh b/scripts/boot/overlay.sh index 7b79df6..cb12c4b 100755 --- a/scripts/boot/overlay.sh +++ b/scripts/boot/overlay.sh @@ -22,10 +22,11 @@ setup_unionfs () ;; esac - if [ "${UNIONTYPE}" = unionfs-fuse ] - then - modprobe fuse - fi + case "${UNIONTYPE}" in + unionfs-fuse) + modprobe fuse + ;; + esac # run-init can't deal with images in a subdir, but we're going to # move all of these away before it runs anyway. No, we're not, @@ -111,25 +112,29 @@ setup_unionfs () fi fstype=$(get_fstype "${backdev}") - if [ "${fstype}" = "unknown" ] - then - panic "Unknown file system type on ${backdev} (${image})" - fi - - if [ -z "${fstype}" ] - then - fstype="${imagename##*.}" - log_warning_msg "Unknown file system type on ${backdev} (${image}), assuming ${fstype}." - fi + case "${fstype}" in + unknown) + panic "Unknown file system type on ${backdev} (${image})" + ;; + + "") + fstype="${imagename##*.}" + log_warning_msg "Unknown file system type on ${backdev} (${image}), assuming ${fstype}." + ;; + esac + + case "${UNIONTYPE}" in + unionmount) + mpoint="${rootmnt}" + rofslist="${rootmnt} ${rofslist}" + ;; + + *) + mpoint="${croot}/${imagename}" + rofslist="${mpoint} ${rofslist}" + ;; + esac - if [ "${UNIONTYPE}" != "unionmount" ] - then - mpoint="${croot}/${imagename}" - rofslist="${mpoint} ${rofslist}" - else - mpoint="${rootmnt}" - rofslist="${rootmnt} ${rofslist}" - fi mkdir -p "${mpoint}" log_begin_msg "Mounting \"${image}\" on \"${mpoint}\" via \"${backdev}\"" mount -t "${fstype}" -o ro,noatime "${backdev}" "${mpoint}" || panic "Can not mount ${backdev} (${image}) on ${mpoint}" @@ -189,9 +194,11 @@ setup_unionfs () removable) whitelistdev="$(removable_dev)" ;; + removable-usb) whitelistdev="$(removable_usb_dev)" ;; + *) whitelistdev="" ;; @@ -206,17 +213,20 @@ setup_unionfs () for media in $(find_persistence_media "${overlays}" "${whitelistdev}") do media="$(echo ${media} | tr ":" " ")" + case ${media} in ${old_root_overlay_label}=*) device="${media#*=}" fix_backwards_compatibility ${device} / union overlay_devices="${overlay_devices} ${device}" ;; + ${old_home_overlay_label}=*) device="${media#*=}" fix_backwards_compatibility ${device} /home bind overlay_devices="${overlay_devices} ${device}" ;; + ${custom_overlay_label}=*) device="${media#*=}" overlay_devices="${overlay_devices} ${device}" @@ -226,7 +236,7 @@ setup_unionfs () elif [ -n "${NFS_COW}" ] && [ -z "${NOPERSISTENCE}" ] then # check if there are any nfs options - if echo ${NFS_COW}|grep -q ',' + if echo ${NFS_COW} | grep -q ',' then nfs_cow_opts="-o nolock,$(echo ${NFS_COW}|cut -d, -f2-)" nfs_cow=$(echo ${NFS_COW}|cut -d, -f1) @@ -243,7 +253,7 @@ setup_unionfs () mac="$(get_mac)" if [ -n "${mac}" ] then - cowdevice=$(echo ${nfs_cow}|sed "s/client_mac_address/${mac}/") + cowdevice=$(echo ${nfs_cow} | sed "s/client_mac_address/${mac}/") cow_fstype="nfs" else panic "unable to determine mac address" @@ -354,6 +364,7 @@ setup_unionfs () unionfs-fuse) mount -o bind "${d}" "${live_rofs}" ;; + *) mount -o move "${d}" "${live_rofs}" ;; diff --git a/scripts/boot/select-eth-device.sh b/scripts/boot/select-eth-device.sh index 924b8bc..ed1da6f 100755 --- a/scripts/boot/select-eth-device.sh +++ b/scripts/boot/select-eth-device.sh @@ -6,7 +6,8 @@ Select_eth_device () bootconf=$(egrep '^BOOT=' /conf/initramfs.conf | tail -1) # can be superseded by command line (used by Debian-Live's netboot for example) - for ARGUMENT in $(cat /proc/cmdline); do + for ARGUMENT in $(cat /proc/cmdline) + do case "${ARGUMENT}" in netboot=*) NETBOOT="${ARGUMENT#netboot=}" @@ -14,14 +15,10 @@ Select_eth_device () esac done - if [ "$bootconf" != "BOOT=nfs" ] && - [ "$NETBOOT" = "" ] && - [ "$FETCH" = "" ] && - [ "$FTPFS" = "" ] && - [ "$HTTPFS" = "" ] + if [ "$bootconf" != "BOOT=nfs" ] && [ -z "$NETBOOT" ] && [ -z "$FETCH" ] && [ -z "$FTPFS" ] && [ -z "$HTTPFS" ] then - # Not a net boot : nothing to do - return + # Not a net boot : nothing to do + return fi # we want to do some basic IP @@ -30,33 +27,38 @@ Select_eth_device () # Available Ethernet interfaces ? l_interfaces="" echo "Waiting for ethernet card(s) up... If this fails, maybe the ethernet card is not supported by the kernel `uname -r`?" - while [ -z "$l_interfaces" ]; do - l_interfaces="$(cd /sys/class/net/ && ls -d eth* 2>/dev/null)" + while [ -z "$l_interfaces" ] + do + l_interfaces="$(cd /sys/class/net/ && ls -d eth* 2>/dev/null)" done - if [ $(echo $l_interfaces | wc -w) -lt 2 ]; then + if [ $(echo $l_interfaces | wc -w) -lt 2 ] + then # only one interface : no choice echo "DEVICE=$l_interfaces" >> /conf/param.conf return fi # If user force to use specific device, write it - for ARGUMENT in $(cat /proc/cmdline); do - case "${ARGUMENT}" in - live-netdev=*) - NETDEV="${ARGUMENT#live-netdev=}" - echo "DEVICE=$NETDEV" >> /conf/param.conf - echo "Found live-netdev parameter in /proc/cmdline. Force to use network device $NETDEV." - return - ;; - esac + for ARGUMENT in $(cat /proc/cmdline) + do + case "${ARGUMENT}" in + live-netdev=*) + NETDEV="${ARGUMENT#live-netdev=}" + echo "DEVICE=$NETDEV" >> /conf/param.conf + echo "Found live-netdev parameter in /proc/cmdline. Force to use network device $NETDEV." + return + ;; + esac done found_eth_dev="" - while true; do + while true + do echo -n "Looking for a connected Ethernet interface ..." - for interface in $l_interfaces; do + for interface in $l_interfaces + do # ATTR{carrier} is not set if this is not done echo -n " $interface ?" ipconfig -c none -d $interface -t 1 >/dev/null 2>&1 @@ -64,18 +66,24 @@ Select_eth_device () echo '' - for step in 1 2 3 4 5; do - for interface in $l_interfaces; do + for step in 1 2 3 4 5 + do + for interface in $l_interfaces + do carrier=$(cat /sys/class/net/$interface/carrier \ 2>/dev/null) # link detected - if [ "$carrier" = 1 ]; then - echo "Connected $interface found" - # inform initrd's init script : - found_eth_dev="$found_eth_dev $interface" - fi + + case "${carrier}" in + 1) + echo "Connected $interface found" + # inform initrd's init script : + found_eth_dev="$found_eth_dev $interface" + ;; + esac done - if [ -n "$found_eth_dev" ]; then + if [ -n "$found_eth_dev" ] + then echo "DEVICE='$found_eth_dev'" >> /conf/param.conf return else