install-rb532.sh 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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. printf "Checking if sfdisk is installed"
  9. sfdisk=$(which sfdisk)
  10. if [ ! -z $sfdisk -a -x $sfdisk ];then
  11. printf "...okay\n"
  12. else
  13. printf "...failed\n"
  14. exit 1
  15. fi
  16. printf "Checking if parted is installed"
  17. parted=$(which parted)
  18. if [ ! -z $parted -a -x $parted ];then
  19. printf "...okay\n"
  20. else
  21. printf "...failed\n"
  22. exit 1
  23. fi
  24. printf "Checking if mke2fs is installed"
  25. mke2fs=$(which mke2fs)
  26. if [ ! -z $mke2fs -a -x $mke2fs ];then
  27. printf "...okay\n"
  28. else
  29. printf "...failed\n"
  30. exit 1
  31. fi
  32. printf "Checking if tune2fs is installed"
  33. tune2fs=$(which tune2fs)
  34. if [ ! -z $tune2fs -a -x $tune2fs ];then
  35. printf "...okay\n"
  36. else
  37. printf "...failed\n"
  38. exit 1
  39. fi
  40. if [ -z $1 ];then
  41. printf "Please give your compact flash or USB device as first parameter\n"
  42. exit 1
  43. else
  44. if [ -z $2 ];then
  45. printf "Please give your install tar archive as second parameter\n"
  46. exit 2
  47. fi
  48. if [ -f $2 ];then
  49. printf "Installing $2 on $1\n"
  50. else
  51. printf "$2 is not a file, Exiting\n"
  52. exit 1
  53. fi
  54. if [ -z $3 ];then
  55. printf "Please give the kernel as third parameter\n"
  56. exit 2
  57. fi
  58. if [ -f $3 ];then
  59. printf "Installing $3 on $1\n"
  60. else
  61. printf "$3 is not a file, Exiting\n"
  62. exit 1
  63. fi
  64. if [ -b $1 ];then
  65. printf "Using $1 as CF/USB disk for installation\n"
  66. printf "This will destroy all data on $1, are you sure?\n"
  67. printf "Type "y" to continue\n"
  68. read y
  69. if [ "$y" = "y" ];then
  70. $sfdisk -l $1 2>&1 |grep 'No medium'
  71. if [ $? -eq 0 ];then
  72. exit 1
  73. else
  74. printf "Starting with installation\n"
  75. fi
  76. else
  77. printf "Exiting.\n"
  78. exit 1
  79. fi
  80. else
  81. printf "Sorry $1 is not a block device\n"
  82. exit 1
  83. fi
  84. fi
  85. if [ $(mount | grep $1| wc -l) -ne 0 ];then
  86. printf "Block device $1 is in use, please umount first.\n"
  87. exit 1
  88. fi
  89. if [ $($sfdisk -l $1 2>/dev/null|grep Empty|wc -l) -ne 4 ];then
  90. printf "Partitions already exist, should I wipe them?\n"
  91. printf "Type y to continue\n"
  92. read y
  93. if [ $y = "y" ];then
  94. printf "Wiping existing partitions\n"
  95. dd if=/dev/zero of=$1 bs=512 count=1 >/dev/null 2>&1
  96. else
  97. printf "Exiting.\n"
  98. exit 1
  99. fi
  100. fi
  101. printf "Create partition and filesystem for rb532\n"
  102. rootpart=${1}2
  103. $parted -s $1 mklabel msdos
  104. sleep 2
  105. maxsize=$(env LC_ALL=C $parted $1 -s unit cyl print |awk '/^Disk/ { print $3 }'|sed -e 's/cyl//')
  106. rootsize=$(($maxsize-2))
  107. $parted -s $1 unit cyl mkpart primary ext2 0 1
  108. $parted -s $1 unit cyl mkpart primary ext2 1 $rootsize
  109. $parted -s $1 unit cyl mkpart primary fat32 $rootsize $maxsize
  110. $parted -s $1 set 1 boot on
  111. $sfdisk --change-id $1 1 27
  112. $sfdisk --change-id $1 3 88
  113. sleep 2
  114. $mke2fs ${1}2
  115. sync
  116. dd if=$3 of=${1}1 bs=2048
  117. sync
  118. sleep 2
  119. $tune2fs -c 0 -i 0 -m 1 ${rootpart} >/dev/null
  120. if [ $? -eq 0 ];then
  121. printf "Successfully disabled filesystem checks on ${rootpart}\n"
  122. else
  123. printf "Disabling filesystem checks failed, Exiting.\n"
  124. exit 1
  125. fi
  126. tmp=$(mktemp -d)
  127. mount -t ext2 ${rootpart} $tmp
  128. printf "Extracting install archive\n"
  129. tar -C $tmp -xzpf $2
  130. printf "Fixing permissions\n"
  131. chmod 1777 $tmp/tmp
  132. chmod 4755 $tmp/bin/busybox
  133. umount $tmp
  134. printf "Successfully installed.\n"
  135. exit 0