Guest User

Untitled

a guest
Mar 16th, 2015
240
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.74 KB | None | 0 0
  1. #!/bin/sh
  2.  
  3. DEVICES=`fdisk -lu|grep '^/dev/.*FAT'|sed 's,^\([^ ]\+\) \+\(\*\?\) \+\([^ ]\+ \+\)\{2\}\([0-9]\+\) \+ [^ ]\+ \+\(.*\)$,\1 - \4 kB \5\t\2,'`
  4.  
  5. FS="$IFS"
  6. IFS='|'
  7.  
  8. if [ -z "$DEVICES" ]; then
  9.     echo "No FAT partitions found!"
  10.     exit
  11. fi
  12.  
  13. choice=''
  14. while [ -z "$choice" ]; do
  15.     num=1
  16.     echo -e "\nAvailable partitions to install LEAF:"
  17.     for i in $DEVICES; do
  18.     echo "$num) $i"
  19.     num=$(($num + 1))
  20.     done
  21.     echo -en "\nSelect partition: "
  22.     read choice
  23.     choice=$(echo "$choice" | sed 's,[^0-9],,g')
  24.     if [ -n "$choice" ] && [ "$(($choice>0 && $choice<$num))" -eq 0 ]; then
  25.     echo "Wrong value selected!"
  26.     choice=""
  27.     fi
  28. done
  29.  
  30. IFS="$FS"
  31.  
  32. LINE=$(echo "$DEVICES" | sed -n -e $choice'{p;q}')
  33. DEVICE=$(echo "$LINE"|awk '{print $1}')
  34. ACTIVE=$(echo "$LINE"|awk '{print $6}')
  35. MDEVICE=$(echo "$DEVICE"|sed 's,[0-9]\+,,')
  36.  
  37. # check mounts
  38. if [ -n "`mount|grep "$DEVICE "`" ]; then
  39.     echo "Partition is already mounted!!! Exitting..."
  40.     sleep 1
  41.     exit 1
  42. fi
  43.  
  44. echo -e "\nSyslinux will be installed to $DEVICE, and MBR code on $MDEVICE will be updated. "
  45. echo -n "Are you sure (y/N)? "
  46. read choice
  47.  
  48. if [ "$choice" != "y" ] && [ "$choice" != "Y" ]; then
  49.     echo "Cancelling operation..."
  50.     sleep 1
  51.     exit 1
  52. fi
  53.  
  54. echo -n "Updating MBR... "
  55. # write MBR
  56. dd if=/usr/share/syslinux/mbr.bin of=$MDEVICE bs=440 count=1
  57. if [ $? -ne 0 ]; then
  58.     echo "Failed! Exitting..."
  59.     sleep 1
  60.     exit 1
  61. fi
  62.  
  63. echo -n "Ok. Installing syslinux... "
  64. syslinux -s $DEVICE
  65. if [ $? -ne 0 ]; then
  66.     echo "Failed! Exitting..."
  67.     sleep 1
  68.     exit 1
  69. fi
  70. echo "Ok."
  71. echo "Now you can unpack LEAF tarball to $DEVICE."
  72. if [ -z "$ACTIVE" ]; then
  73.     echo "Please, set partition $DEVICE active via fdisk to boot LEAF!"
  74. fi
Advertisement
Add Comment
Please, Sign In to add comment