install-rpi.sh 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. for tool in parted sfdisk mkfs.vfat mkfs.ext4;do
  9. if ! which $tool >/dev/null; then
  10. echo "Checking if $tool is installed... failed"
  11. f=1
  12. fi
  13. done
  14. [[ $f -eq 1 ]] && exit 1
  15. if [ -z $1 ];then
  16. echo "Please give your SD card device as first parameter"
  17. exit 1
  18. else
  19. if [ -z $2 ];then
  20. echo "Please give your install tar archive as second parameter"
  21. exit 1
  22. fi
  23. if [ -f $2 ];then
  24. echo "Installing $2 on $1"
  25. else
  26. echo "$2 is not a file, exiting"
  27. exit 1
  28. fi
  29. if [ -b $1 ];then
  30. echo "Using $1 as SD card disk for installation"
  31. echo "WARNING: This will destroy all data on $1 - type Yes to continue!"
  32. read y
  33. if [ "$y" = "Yes" ];then
  34. $sfdisk -l $1 2>&1 |grep 'No medium'
  35. if [ $? -eq 0 ];then
  36. echo "No medium found"
  37. exit 1
  38. else
  39. echo "Starting with installation"
  40. fi
  41. else
  42. echo "Exiting."
  43. exit 1
  44. fi
  45. else
  46. echo "Sorry $1 is not a block device"
  47. exit 1
  48. fi
  49. fi
  50. if [ $(mount | grep $1| wc -l) -ne 0 ];then
  51. echo "Block device $1 is in use, please umount first"
  52. exit 1
  53. fi
  54. echo "Wiping existing partitions"
  55. dd if=/dev/zero of=$1 bs=512 count=1 >/dev/null 2>&1
  56. sync
  57. echo "Create partition and filesystem for raspberry pi"
  58. rootpart=${1}2
  59. parted -s $1 mklabel msdos
  60. sleep 2
  61. maxsize=$(env LC_ALL=C parted $1 -s unit cyl print |awk '/^Disk/ { print $3 }'|sed -e 's/cyl//')
  62. rootsize=$(($maxsize-34))
  63. datasize=$(($maxsize-2))
  64. parted -s $1 unit cyl mkpart primary fat32 -- 0 16
  65. parted -s $1 unit cyl mkpart primary ext2 -- 16 $rootsize
  66. parted -s $1 unit cyl mkpart primary ext2 $rootsize $datasize
  67. parted -s $1 unit cyl mkpart primary fat32 $datasize $maxsize
  68. parted -s $1 set 1 boot on
  69. sfdisk --change-id $1 4 88
  70. sleep 2
  71. mkfs.vfat ${1}1 >/dev/null
  72. mkfs.ext4 -q -O ^huge_file ${1}2
  73. mkfs.ext4 -q -O ^huge_file ${1}3
  74. sync
  75. sleep 2
  76. tmp=$(mktemp -d)
  77. mount -t ext4 ${rootpart} $tmp
  78. mkdir $tmp/boot
  79. mkdir $tmp/data
  80. mount -t ext4 ${1}3 $tmp/data
  81. mkdir $tmp/data/mpd $tmp/data/xbmc
  82. mount -t vfat ${1}1 $tmp/boot
  83. sleep 1
  84. echo "Extracting install archive"
  85. tar -C $tmp -xzpf $2
  86. echo "Fixing permissions"
  87. chmod 1777 $tmp/tmp
  88. chmod 4755 $tmp/bin/busybox
  89. echo "/dev/mmcblk0p3 /data ext4 rw 0 0" >>$tmp/etc/fstab
  90. umount $tmp/data
  91. umount $tmp/boot
  92. umount $tmp
  93. echo "Successfully installed."
  94. exit 0