install-solidrun.sh 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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. echo "Installation is only possible as root"
  6. exit 1
  7. fi
  8. f=0
  9. for tool in parted sfdisk mkfs.ext4;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. datadir=0
  17. keep=0
  18. while getopts "dk" ch; do
  19. case $ch in
  20. d)
  21. datadir=1
  22. ;;
  23. k)
  24. keep=1
  25. ;;
  26. esac
  27. done
  28. shift $((OPTIND - 1))
  29. if [ -z $1 ];then
  30. echo "Please give your SD card device as first parameter"
  31. exit 1
  32. else
  33. if [ -z $2 ];then
  34. echo "Please give your install tar archive as second parameter"
  35. exit 1
  36. fi
  37. if [ -f $2 ];then
  38. echo "Installing $2 on $1"
  39. else
  40. echo "$2 is not a file, exiting"
  41. exit 1
  42. fi
  43. if [ -z $3 ];then
  44. echo "Please give your firmware directory as third parameter"
  45. exit 1
  46. fi
  47. if [ ! -d $3 ];then
  48. echo "$3 is not a directory, exiting"
  49. exit 1
  50. fi
  51. if [ -b $1 ];then
  52. echo "Using $1 as SD card disk for installation"
  53. echo "WARNING: This will destroy all data on $1 - type Yes to continue!"
  54. read y
  55. if [ "$y" = "Yes" ];then
  56. env LC_ALL=C sfdisk -l $1 2>&1 |grep 'No medium'
  57. if [ $? -eq 0 ];then
  58. echo "No medium found"
  59. exit 1
  60. else
  61. echo "Starting with installation"
  62. fi
  63. else
  64. echo "Exiting."
  65. exit 1
  66. fi
  67. else
  68. echo "Sorry $1 is not a block device"
  69. exit 1
  70. fi
  71. fi
  72. if [ $(mount | grep $1| wc -l) -ne 0 ];then
  73. echo "Block device $1 is in use, please umount first"
  74. exit 1
  75. fi
  76. maxsize=$(env LC_ALL=C parted $1 -s unit s print |awk '/^Disk/ { print $3 }'|sed -e 's/s//')
  77. maxsize=$(($maxsize-1))
  78. if [ $datadir -eq 0 ];then
  79. rootsize=$(($maxsize-32768))
  80. rootsizeend=$(($rootsize+1))
  81. else
  82. rootsize=$(($maxsize-32768-131072))
  83. rootsizeend=$(($rootsize+1))
  84. datasize=$(($maxsize-32768))
  85. datasizeend=$(($datasize+1))
  86. fi
  87. echo "Install bootloader for cubox-i/hummingboard"
  88. parted -s $1 mklabel msdos >/dev/null 2>&1
  89. dd if=${3}/SPL of=${1} bs=1K seek=1 >/dev/null 2>&1
  90. dd if=${3}/u-boot.img of=${1} bs=1K seek=42 >/dev/null 2>&1
  91. if [ $datadir -eq 0 ];then
  92. parted -a optimal -s $1 unit s mkpart primary ext2 -- 2048 $rootsize >/dev/null 2>&1
  93. parted -a optimal -s $1 unit s mkpart primary fat32 -- $rootsizeend $maxsize
  94. sfdisk --change-id $1 2 88 >/dev/null 2>&1
  95. else
  96. parted -a optimal -s $1 unit s mkpart primary ext2 -- 2048 $rootsize
  97. parted -a optimal -s $1 unit s mkpart primary ext2 -- $rootsizeend $datasize
  98. parted -a optimal -s $1 unit s mkpart primary fat32 -- $datasizeend $maxsize
  99. sfdisk --change-id $1 3 88
  100. fi
  101. echo "Creating filesystem"
  102. mkfs.ext4 -F -q -O ^huge_file ${1}1
  103. sync
  104. if [ $datadir -eq 1 ];then
  105. if [ $keep -eq 0 ];then
  106. mkfs.ext4 -F -q -O ^huge_file ${1}2
  107. fi
  108. fi
  109. tmp=$(mktemp -d)
  110. mount -t ext4 ${1}1 $tmp
  111. if [ $datadir -eq 1 ];then
  112. if [ $keep -eq 0 ];then
  113. mkdir $tmp/data
  114. mount -t ext4 ${1}2 $tmp/data
  115. mkdir $tmp/data/mpd $tmp/data/xbmc
  116. umount $tmp/data
  117. fi
  118. fi
  119. echo "Extracting install archive"
  120. tar -C $tmp -xzpf $2
  121. if [ $datadir -eq 1 ];then
  122. echo "/dev/mmcblk0p2 /data ext4 rw 0 0" >>$tmp/etc/fstab
  123. fi
  124. echo "Fixing permissions"
  125. chmod 1777 $tmp/tmp
  126. chmod 4755 $tmp/bin/busybox
  127. cp ${3}/*.dtb $tmp/boot/
  128. umount $tmp
  129. echo "Successfully installed."
  130. exit 0