adkinstall.rb532 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #!/bin/sh
  2. # installs a rootfs tar archive from OpenADK onto
  3. # a Compact Flash disk or NAND device
  4. # special script for routerboard rb532
  5. nandinstall=0
  6. cfinstall=0
  7. if [ -z $1 ];then
  8. printf "Please give your target device as first parameter [cf|nand]\n"
  9. exit 1
  10. fi
  11. if [ -z $2 ];then
  12. printf "Please give your root tar archive as second parameter\n"
  13. exit 1
  14. fi
  15. case $1 in
  16. nand)
  17. nandinstall=1
  18. ;;
  19. cf)
  20. cfinstall=1
  21. ;;
  22. *)
  23. printf "Target device not known.\n"
  24. exit 1
  25. ;;
  26. esac
  27. if [ $cfinstall -eq 1 ];then
  28. if [ -z $3 ];then
  29. printf "Please give your kernel as third parameter\n"
  30. exit 1
  31. fi
  32. fi
  33. if [ $cfinstall -eq 1 ];then
  34. # create empty partition table
  35. printf "Creating partition scheme\n"
  36. parted -s /dev/sda mklabel msdos
  37. sleep 2
  38. maxsize=$(env LC_ALL=C parted /dev/sda -s unit cyl print |awk '/^Disk/ { print $3 }'|sed -e 's/cyl//')
  39. rootsize=$(($maxsize-2))
  40. parted -s /dev/sda unit cyl mkpart primary ext2 0 1
  41. parted -s /dev/sda unit cyl mkpart primary ext2 1 $rootsize
  42. parted -s /dev/sda unit cyl mkpart primary fat32 $rootsize $maxsize
  43. parted -s /dev/sda set 1 boot on
  44. sfdisk --change-id /dev/sda 1 27 >/dev/null 2>&1
  45. sfdisk --change-id /dev/sda 3 88 >/dev/null 2>&1
  46. sleep 2
  47. mke2fs /dev/sda2
  48. sync
  49. printf "Installing kernel\n"
  50. dd if=$3 of=/dev/sda1 bs=2048 >/dev/null 2>&1
  51. sync
  52. mount -t ext2 /dev/sda2 /mnt
  53. fi
  54. if [ $nandinstall -eq 1 ];then
  55. printf "Preparing mountpoints\n"
  56. mount -t yaffs2 /dev/mtdblock1 /mnt
  57. rm -rf /mnt/* >/dev/null 2>&1
  58. mkdir /mnt/boot
  59. mount -t yaffs2 /dev/mtdblock0 /mnt/boot
  60. fi
  61. printf "Extracting install archive\n"
  62. tar -C /mnt -xzpf $2
  63. if [ $? -ne 0 ];then
  64. printf "Extracting of install archive failed"
  65. exit 1
  66. fi
  67. chmod 1777 /mnt/tmp
  68. chmod 4755 /mnt/bin/busybox
  69. sync
  70. if [ $nandinstall -eq 1 ];then
  71. umount /mnt/boot
  72. fi
  73. umount /mnt
  74. if [ $? -ne 0 ];then
  75. printf "Unmounting filesystem failed"
  76. exit 1
  77. else
  78. printf "Successfully installed.\n"
  79. exit 0
  80. fi