1
0

install-rb532.sh 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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 [ -b $1 ];then
  31. printf "Using $1 as CF disk for installation\n"
  32. echo "WARNING: This will destroy all data on $1 - type Yes to continue!"
  33. read y
  34. if [ "$y" = "Yes" ];then
  35. env LC_ALL=C sfdisk -l $1 2>&1 |grep 'No medium'
  36. if [ $? -eq 0 ];then
  37. echo "No medium found"
  38. exit 1
  39. else
  40. printf "Starting with installation\n"
  41. fi
  42. else
  43. printf "Exiting.\n"
  44. exit 1
  45. fi
  46. else
  47. printf "Sorry $1 is not a block device\n"
  48. exit 1
  49. fi
  50. fi
  51. if [ $(mount | grep $1| wc -l) -ne 0 ];then
  52. printf "Block device $1 is in use, please umount first.\n"
  53. exit 1
  54. fi
  55. printf "Create partition and filesystem for rb532\n"
  56. rootpart=${1}2
  57. parted -s $1 mklabel msdos >/dev/null 2>&1
  58. sleep 2
  59. maxsize=$(env LC_ALL=C parted $1 -s unit cyl print |awk '/^Disk/ { print $3 }'|sed -e 's/cyl//')
  60. rootsize=$(($maxsize-2))
  61. parted -s $1 unit cyl mkpart primary ext2 0 2 >/dev/null 2>&1
  62. parted -s $1 unit cyl mkpart primary ext2 2 $rootsize >/dev/null 2>&1
  63. parted -s $1 unit cyl mkpart primary fat32 $rootsize $maxsize >/dev/null 2>&1
  64. parted -s $1 set 1 boot on >/dev/null 2>&1
  65. sfdisk --change-id $1 1 27 >/dev/null 2>&1
  66. sfdisk --change-id $1 3 88 >/dev/null 2>&1
  67. sleep 1
  68. mkfs.ext4 -q -O ^huge_file ${1}2
  69. tune2fs -c 0 -i 0 -m 1 ${rootpart} >/dev/null 2>&1
  70. if [ $? -eq 0 ];then
  71. printf "Successfully disabled filesystem checks on ${rootpart}\n"
  72. else
  73. printf "Disabling filesystem checks failed, Exiting.\n"
  74. exit 1
  75. fi
  76. tmp=$(mktemp -d)
  77. mount -t ext4 ${rootpart} $tmp
  78. printf "Extracting install archive\n"
  79. tar -C $tmp -xzpf $2
  80. dd if=$tmp/boot/kernel of=${1}1 bs=2048 >/dev/null 2>&1
  81. if [ $? -eq 0 ];then
  82. printf "Installation of kernel successful.\n"
  83. rm $tmp/boot/kernel
  84. else
  85. printf "Installation of kernel failed.\n"
  86. fi
  87. printf "Fixing permissions\n"
  88. chmod 1777 $tmp/tmp
  89. chmod 4755 $tmp/bin/busybox
  90. umount $tmp
  91. printf "Successfully installed.\n"
  92. exit 0