# # (c) 2007 Paul Sokolovsky # # If root is explicitly specified, skip interactive selection if [ -z "$ROOT_DEVICE" ]; then ############################## E="\033[" MOUNTLOC="tmp" LOOP_IMG_MASK='*.img' if ! (echo " " | read -n1 foo) >/dev/null 2>&1; then echo "'read' command lacks -n switch support, aborting" exit 1 fi mkdir -p $MOUNTLOC list="" add_menu_item() { if [ -n "$list" ]; then list="$list\n" fi list="$list$1" } show_menu() { echo -e -n "${E}3;0H" cnt=0 echo -e $list | \ while read l; do if [ $cnt == $num ]; then echo -e -n "${E}1m" fi echo -e "$cnt: $l${E}0m" cnt=$((cnt + 1)) done } get_menu_selection() { cnt=0 sel=`echo -e $list | \ while read l; do if [ $cnt == $num ]; then echo $l break fi cnt=$((cnt + 1)) done` } get_partition_type() { # fstype=`mount -f --guess-fstype /dev/$dev $MOUNTLOC` fstype=`fstype /dev/null`; do add_menu_item "$dev/$img (loop img on vfat)" done cd $p umount $MOUNTLOC } # Scan all available device/partitions while read maj min nblk dev; do if [ -z "$maj" -o "$maj" == "major" ]; then continue; fi get_partition_type if [ "$fstype" != "ext2" -a "$fstype" != "ext3" -a "$fstype" != "vfat" -a "$fstype" != "jffs2" ]; then # continue true fi if [ "$fstype" == "vfat" ]; then scan_for_loopimgs continue fi add_menu_item "$dev ($fstype)" done < /proc/partitions add_menu_item "NFS (nfsroot=192.168.2.200:/srv/nfs/oe/image)" add_menu_item "Shell" total=`echo -e $list | wc -l` num=0 # Draw UI stty -echo echo -e -n "${E}2J" echo -e -n "${E}0;0H" echo "Select boot image:" # Main loop show_menu while read -n1 i; do case "$i" in "A") num=$((num - 1)) if [ $num -lt 0 ]; then num=$(($total - 1)) fi ;; ["B"-"Z"]) num=$((num + 1)) if [ $num -ge $total ]; then num=0 fi ;; "q") exec sh ;; "") break ;; esac show_menu # echo "*$esc$i" done stty echo # Process results of user selection, prepare input arguments # for boot modules get_menu_selection echo Selected: $sel dev=`expr "$sel" : '\([^ /]*\)'` path=`expr "$sel" : '[^/]*\([^ ]*\).*'` fstype=`expr "$sel" : '[^ ]* *\(.*\)'` if [ "$dev" == "Shell" ]; then exec /bin/sh elif [ "$dev" == "NFS" ]; then ROOT_DEVICE="/dev/nfs" CMDLINE="$CMDLINE root=/dev/nfs nfsroot=192.168.2.200:/srv/nfs/oe/image" elif [ -n "$path" ]; then ROOT_DEVICE="/dev/loop" CMDLINE="$CMDLINE root=/dev/loop looproot=/dev/$dev:$path" else ROOT_DEVICE="/dev/$dev" # jffs2 is not recognized by mount automagically if [ "$fstype" == "(jffs2)" ]; then ROOT_FSTYPE="jffs2" fi CMDLINE="$CMDLINE root=$ROOT_DEVICE" fi echo ROOT_DEVICE=$ROOT_DEVICE echo CMDLINE=$CMDLINE ############################## fi