1
0

install-rpi.sh 2.7 KB

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