From adfa636f228aea89341ddcfd7cd9c927d8dd2242 Mon Sep 17 00:00:00 2001 From: Dieter Plaetinck Date: Tue, 8 Feb 2011 22:14:16 +0100 Subject: Cleanup grub / label/uuid related code * indentation fixes * simplify label/uuid code * simplify variable names * remove some cruft * fix/improve some code and spelling --- TODO | 1 - src/core/libs/lib-blockdevices-filesystems.sh | 34 ++--- src/core/libs/lib-ui-interactive.sh | 179 ++++++++++++-------------- 3 files changed, 95 insertions(+), 119 deletions(-) diff --git a/TODO b/TODO index 71e7d71..c26db5c 100644 --- a/TODO +++ b/TODO @@ -1,6 +1,5 @@ See also the FIXME's and TODO's in the code, and http://bugs.archlinux.org/toplevel/proj6 -fix /vmlinuz depending on separate /boot -> $subdir wrong CURRENT ISSUES: * fix (hd0,0) not showing up in automatic procedure diff --git a/src/core/libs/lib-blockdevices-filesystems.sh b/src/core/libs/lib-blockdevices-filesystems.sh index 6533b7c..03f6a95 100644 --- a/src/core/libs/lib-blockdevices-filesystems.sh +++ b/src/core/libs/lib-blockdevices-filesystems.sh @@ -181,28 +181,26 @@ $ANSWER_DEVICES" } -# getuuid(). taken and modified from setup. this can probably be more improved. return an exit code, rely on blkid's exit codes etc. -# converts /dev/[hs]d?[0-9] devices to UUIDs -# # parameters: device file # outputs: UUID on success # nothing on failure -# returns: nothing -getuuid() -{ +# returns: 0 if the attribute is found, 1 otherwise +getuuid() { [ -n "$1" -a -b "$1" ] || die_error "getuuid needs a device file argument" - echo "$(blkid -s UUID -o value ${1})" + uuid=$(blkid -s UUID -o value ${1}) + echo $uuid + [ -n "$uuid" ] } - # parameters: device file # outputs: LABEL on success # nothing on failure -# returns: nothing -getlabel() -{ +# returns: 0 if the attribute is found, 1 otherwise +getlabel() { [ -n "$1" -a -b "$1" ] || die_error "getlabel needs a device file argument" - echo "$(blkid -s LABEL -o value ${1})" + label=$(blkid -s LABEL -o value ${1}) + echo "$label" + [ -n "$label" ] } # find partitionable blockdevices @@ -858,17 +856,9 @@ process_filesystem () then case "$PART_ACCESS" in label) - local _label="$(getlabel $part)" - if [ -n "${_label}" ]; then - part="LABEL=${_label}" - fi - ;; + local label="$(getlabel $part)" && part="LABEL=$label";; uuid) - local _uuid="$(getuuid $part)" - if [ -n "${_uuid}" ]; then - part="UUID=${_uuid}" - fi - ;; + local uuid="$(getuuid $part)" && part="UUID=$uuid";; esac if ! grep -q "$part $fs_mountpoint $fs_type defaults 0 " $TMP_FSTAB 2>/dev/null #$TMP_FSTAB may not exist yet then diff --git a/src/core/libs/lib-ui-interactive.sh b/src/core/libs/lib-ui-interactive.sh index e0ad6c9..f3ed2e1 100644 --- a/src/core/libs/lib-ui-interactive.sh +++ b/src/core/libs/lib-ui-interactive.sh @@ -998,7 +998,8 @@ interactive_grub() { generate_grub_menulst() { get_device_with_mount '/' || return 1 - local _rootpart=$ANSWER_DEVICE + local rootpart=$ANSWER_DEVICE + local subdir= # Determine what is the device that acts as grub's root # This is the blockdevice where /boot lives, normally a seperate partition. @@ -1009,39 +1010,34 @@ generate_grub_menulst() { # # We get at last in grubdev the blockdevice in grub-legacy notation (ex: (hd0,0) # - # We do may things double here and in interactive_grub_install - # Better way would be to determine/ask neccassary things once and then - # fill (and present) menu.lst to user. If user mean there is something - # wrong with menu.lst settings (wrong boot device or wrong root=/device) - # he better should re-run the interactive grub install and select correct - # settings. - debug FS "Grub _rootpart: ${_rootpart}" - debug FS "Grub bootdev: "$bootdev + # We may do things double here and in interactive_grub_install + # Better way would be to determine/ask neccassary things once and then + # fill (and present) menu.lst to user. If user mean there is something + # wrong with menu.lst settings (wrong boot device or wrong root=/device) + # he better re-runs the interactive grub install and select correct settings. + debug FS "Grub rootpart: $rootpart" + debug FS "Grub bootdev: $bootdev" + # No seperate /boot partition if [ -z $bootdev ]; then - # Special handling on md raid + subdir="/boot" if [ $onraid ]; then - grubdev=$(mapdev $(mdraid_slave0 ${_rootpart})) - debug FS "onraid no sep boot slave0: "$(mdraid_slave0 ${_rootpart}) - debug FS "onraid no sep boot grubdev: "$grubdev + grubdev=$(mapdev $(mdraid_slave0 $rootpart)) + debug FS "onraid no sep boot slave0: $(mdraid_slave0 $rootpart)" + debug FS "onraid no sep boot grubdev: $grubdev" else - # No raid - grubdev=$(mapdev ${_rootpart}) - debug FS "no sep boot grubdev: "$grubdev + grubdev=$(mapdev $rootpart) + debug FS "no sep boot grubdev: $grubdev" fi - # Without seperate /boot partiton we have to specify this path - subdir="/boot" # with seperate /boot partition else - # Special handling on md raid if [ $onraid ]; then grubdev=$(mapdev $(mdraid_slave0 $bootdev)) - debug FS "onraid with sep boot slave0: "$(mdraid_slave0 $bootdev) - debug FS "onraid with sep boot grubdev: "$grubdev + debug FS "onraid with sep boot slave0: $(mdraid_slave0 $bootdev)" + debug FS "onraid with sep boot grubdev: $grubdev" else - # No raid grubdev=$(mapdev $bootdev) - debug FS "onraid with sep boot grubdev: "$grubdev + debug FS "onraid with sep boot grubdev: $grubdev" fi fi # Now that we have our grub-legacy root device (grubdev). @@ -1057,9 +1053,6 @@ generate_grub_menulst() { get_kernel_parameters || return $? - # No seperate /boot partition - [[ -z "$bootdev" ]] && local subdir="/boot" - cat >>$grubmenu </tmp/grub.log 2>&1 </tmp/grub.log 2>&1 <$LOG - if grep "Error [0-9]*: " /tmp/grub.log >/dev/null; then - notify "Error installing GRUB. (see $LOG for output)" - return 1 - fi + cat /tmp/grub.log >$LOG + if grep -q "Error [0-9]*: " /tmp/grub.log; then + notify "Error installing GRUB. (see $LOG for output)" + return 1 + fi } -get_kernel_parameters() -{ - +get_kernel_parameters() { get_device_with_mount '/' || return 1 - local _rootpart="$ANSWER_DEVICE" + local rootpart="$ANSWER_DEVICE" case "$PART_ACCESS" in label) - local _label="$(getlabel $_rootpart)" - [[ "${_label}" ]] && _rootpart="/dev/disk/by-label/${_label}" - ;; + local label="$(getlabel $rootpart)" && \ + rootpart="/dev/disk/by-label/$label" ;; uuid) - local _uuid="$(getuuid $_rootpart)" - [[ "${_uuid}" ]] && _rootpart="/dev/disk/by-uuid/${_uuid}" - ;; + local uuid="$(getuuid $rootpart)" && \ + rootpart="/dev/disk/by-uuid/$uuid" ;; esac - kernel_parameters="root=$_rootpart ro" + kernel_parameters="root=$rootpart ro" local raw_device crypt_device lv_device - + if get_anchestors_mount ';/;'; then if echo "$ANSWER_DEVICES" | sed -n '1p' | grep -q 'dm_crypt$' && echo "$ANSWER_DEVICES" | sed -n '2p' | grep -q 'raw$' - then - debug 'FS' 'get_kernel_parameters - Found / on dm_crypt on raw' - raw_device="$(echo "$ANSWER_DEVICES" | sed -n '2p' | cut -d ' ' -f1)" - crypt_device="$(echo "$ANSWER_DEVICES" | sed -n '1p' | cut -d ' ' -f1)" - kernel_parameters="root=$crypt_device cryptdevice=$raw_device:`basename $crypt_device` ro" - elif echo "$ANSWER_DEVICES" | sed -n '1p' | grep -q 'lvm-lv$' && echo "$ANSWER_DEVICES" | sed -n '4p' | grep -q 'dm_crypt$' && echo "$ANSWER_DEVICES" | sed -n '5p' | grep -q 'raw$' - then + then + debug 'FS' 'get_kernel_parameters - Found / on dm_crypt on raw' + raw_device="$(echo "$ANSWER_DEVICES" | sed -n '2p' | cut -d ' ' -f1)" + crypt_device="$(echo "$ANSWER_DEVICES" | sed -n '1p' | cut -d ' ' -f1)" + kernel_parameters="root=$crypt_device cryptdevice=$raw_device:`basename $crypt_device` ro" + elif echo "$ANSWER_DEVICES" | sed -n '1p' | grep -q 'lvm-lv$' && echo "$ANSWER_DEVICES" | sed -n '4p' | grep -q 'dm_crypt$' && echo "$ANSWER_DEVICES" | sed -n '5p' | grep -q 'raw$' + then debug 'FS' 'get_kernel_parameters - Found / on lvm on dm_crypt on raw' - lv_device="$(echo "$ANSWER_DEVICES" | sed -n '1p' | cut -d ' ' -f1)" - crypt_device="$(echo "$ANSWER_DEVICES" | sed -n '4p' | cut -d ' ' -f1)" - raw_device="$(echo "$ANSWER_DEVICES" | sed -n '5p' | cut -d ' ' -f1)" - kernel_parameters="root=$lv_device cryptdevice=$raw_device:`basename $crypt_device` ro" - elif echo "$ANSWER_DEVICES" | sed -n '1p' | grep -q 'dm_crypt$' && echo "$ANSWER_DEVICES" | sed -n '2p' | grep -q 'lvm-lv$' && echo "$ANSWER_DEVICES" | sed -n '5p' | grep -q 'raw$' - then - debug 'FS' 'get_kernel_parameters - Found / on dm_crypt on lvm on raw' - crypt_device="$(echo "$ANSWER_DEVICES" | sed -n '1p' | cut -d ' ' -f1)" - lv_device="$(echo "$ANSWER_DEVICES" | sed -n '2p' | cut -d ' ' -f1)" - kernel_parameters="root=$crypt_device cryptdevice=$lv_device:`basename $crypt_device` ro" - elif echo "$ANSWER_DEVICES" | sed -n '1p' | grep -q 'raw$' - then - debug 'FS' 'get_kernel_parameters - Found / on raw' - elif echo "$ANSWER_DEVICES" | sed -n '1p' | grep -q 'lvm-lv$' && echo "$ANSWER_DEVICES" | sed -n '4p' | grep -q 'raw$' - then - debug 'FS' 'get_kernel_parameters - Found / on lvm on raw' - else - debug 'FS' 'get_kernel_parameters - Could not figure this one out' - show_warning "Disk setup detection" "Are you using some really fancy dm_crypt/lvm/softraid setup?\nI could not figure it out, so the kernel line will be the default: you'll probably need to edit it.\nPlease file a bug for this and supply all files from /tmp/aif/" + lv_device="$(echo "$ANSWER_DEVICES" | sed -n '1p' | cut -d ' ' -f1)" + crypt_device="$(echo "$ANSWER_DEVICES" | sed -n '4p' | cut -d ' ' -f1)" + raw_device="$(echo "$ANSWER_DEVICES" | sed -n '5p' | cut -d ' ' -f1)" + kernel_parameters="root=$lv_device cryptdevice=$raw_device:`basename $crypt_device` ro" + elif echo "$ANSWER_DEVICES" | sed -n '1p' | grep -q 'dm_crypt$' && echo "$ANSWER_DEVICES" | sed -n '2p' | grep -q 'lvm-lv$' && echo "$ANSWER_DEVICES" | sed -n '5p' | grep -q 'raw$' + then + debug 'FS' 'get_kernel_parameters - Found / on dm_crypt on lvm on raw' + crypt_device="$(echo "$ANSWER_DEVICES" | sed -n '1p' | cut -d ' ' -f1)" + lv_device="$(echo "$ANSWER_DEVICES" | sed -n '2p' | cut -d ' ' -f1)" + kernel_parameters="root=$crypt_device cryptdevice=$lv_device:`basename $crypt_device` ro" + elif echo "$ANSWER_DEVICES" | sed -n '1p' | grep -q 'raw$' + then + debug 'FS' 'get_kernel_parameters - Found / on raw' + elif echo "$ANSWER_DEVICES" | sed -n '1p' | grep -q 'lvm-lv$' && echo "$ANSWER_DEVICES" | sed -n '4p' | grep -q 'raw$' + then + debug 'FS' 'get_kernel_parameters - Found / on lvm on raw' + else + debug 'FS' 'get_kernel_parameters - Could not figure this one out' + show_warning "Disk setup detection" "Are you using some really fancy dm_crypt/lvm/softraid setup?\nI could not figure it out, so the kernel line will be the default: you'll probably need to edit it.\nPlease file a bug for this and supply all files from /tmp/aif/" fi else show_warning "Disk setup detection" "Could not find out where your / is. Did you setup filesystems/blockdevices? manual/autoprepare? If yes, please file a bug and tell us about this" @@ -1196,8 +1184,7 @@ get_kernel_parameters() # # params: none # returns: nothing -interactive_select_source() -{ +interactive_select_source() { var_PKG_SOURCE_TYPE= var_FILE_URL="file:///src/core/pkg" var_SYNC_URL= -- cgit v1.2.3