install-rb532.sh 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. #!/usr/bin/env bash
  2. # This file is part of the OpenADK project. OpenADK is copyrighted
  3. # material, please see the LICENCE file in the top-level directory.
  4. if [ $(id -u) -ne 0 ];then
  5. printf "Installation is only possible as root\n"
  6. exit 1
  7. fi
  8. f=0
  9. for tool in parted sfdisk mkfs.ext4 tune2fs;do
  10. if ! which $tool >/dev/null; then
  11. echo "Checking if $tool is installed... failed"
  12. f=1
  13. fi
  14. done
  15. if [ $f -eq 1 ];then exit 1;fi
  16. if [ -z $1 ];then
  17. printf "Please give your compact flash device as first parameter\n"
  18. exit 1
  19. else
  20. if [ -z $2 ];then
  21. printf "Please give your install tar archive as second parameter\n"
  22. exit 2
  23. fi
  24. if [ -f $2 ];then
  25. printf "Installing $2 on $1\n"
  26. else
  27. printf "$2 is not a file, Exiting\n"
  28. exit 1
  29. fi
  30. if [ -z $3 ];then
  31. printf "Please give the kernel as third parameter\n"
  32. exit 2
  33. fi
  34. if [ -f $3 ];then
  35. printf "Installing $3 on $1\n"
  36. else
  37. printf "$3 is not a file, Exiting\n"
  38. exit 1
  39. fi
  40. if [ -b $1 ];then
  41. printf "Using $1 as CF disk for installation\n"
  42. echo "WARNING: This will destroy all data on $1 - type Yes to continue!"
  43. read y
  44. if [ "$y" = "Yes" ];then
  45. env LC_ALL=C sfdisk -l $1 2>&1 |grep 'No medium'
  46. if [ $? -eq 0 ];then
  47. echo "No medium found"
  48. exit 1
  49. else
  50. printf "Starting with installation\n"
  51. fi
  52. else
  53. printf "Exiting.\n"
  54. exit 1
  55. fi
  56. else
  57. printf "Sorry $1 is not a block device\n"
  58. exit 1
  59. fi
  60. fi
  61. if [ $(mount | grep $1| wc -l) -ne 0 ];then
  62. printf "Block device $1 is in use, please umount first.\n"
  63. exit 1
  64. fi
  65. printf "Create partition and filesystem for rb532\n"
  66. rootpart=${1}2
  67. parted -s $1 mklabel msdos >/dev/null 2>&1
  68. sleep 2
  69. maxsize=$(env LC_ALL=C parted $1 -s unit cyl print |awk '/^Disk/ { print $3 }'|sed -e 's/cyl//')
  70. rootsize=$(($maxsize-2))
  71. parted -s $1 unit cyl mkpart primary ext2 0 2 >/dev/null 2>&1
  72. parted -s $1 unit cyl mkpart primary ext2 2 $rootsize >/dev/null 2>&1
  73. parted -s $1 unit cyl mkpart primary fat32 $rootsize $maxsize >/dev/null 2>&1
  74. parted -s $1 set 1 boot on >/dev/null 2>&1
  75. sfdisk --change-id $1 1 27 >/dev/null 2>&1
  76. sfdisk --change-id $1 3 88 >/dev/null 2>&1
  77. sleep 2
  78. mkfs.ext4 -q -O ^huge_file ${1}2
  79. sync
  80. dd if=$3 of=${1}1 bs=2048 >/dev/null 2>&1
  81. if [ $? -eq 0 ];then
  82. printf "Installation of kernel successful.\n"
  83. else
  84. printf "Installation of kernel failed.\n"
  85. fi
  86. sync
  87. sleep 2
  88. tune2fs -c 0 -i 0 -m 1 ${rootpart} >/dev/null 2>&1
  89. if [ $? -eq 0 ];then
  90. printf "Successfully disabled filesystem checks on ${rootpart}\n"
  91. else
  92. printf "Disabling filesystem checks failed, Exiting.\n"
  93. exit 1
  94. fi
  95. tmp=$(mktemp -d)
  96. mount -t ext4 ${rootpart} $tmp
  97. printf "Extracting install archive\n"
  98. tar -C $tmp -xzpf $2
  99. printf "Fixing permissions\n"
  100. chmod 1777 $tmp/tmp
  101. chmod 4755 $tmp/bin/busybox
  102. umount $tmp
  103. printf "Successfully installed.\n"
  104. exit 0