install.sh 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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. TOPDIR=$(pwd)
  5. if [ $(id -u) -ne 0 ];then
  6. printf "Installation is only possible as root\n"
  7. exit 1
  8. fi
  9. printf "Checking if mke2fs is installed"
  10. mke2fs=$(which mke2fs)
  11. if [ ! -z $mke2fs -a -x $mke2fs ];then
  12. printf "...okay\n"
  13. else
  14. printf "...failed\n"
  15. exit 1
  16. fi
  17. cfgfs=1
  18. quiet=0
  19. console=0
  20. serial=0
  21. while getopts "nq" option
  22. do
  23. case $option in
  24. q)
  25. quiet=1
  26. ;;
  27. n)
  28. cfgfs=0
  29. ;;
  30. *)
  31. printf "Option not recognized\n"
  32. exit 1
  33. ;;
  34. esac
  35. done
  36. shift $(($OPTIND - 1))
  37. if [ -z $1 ];then
  38. printf "Please give your compact flash or USB device as first parameter\n"
  39. exit 1
  40. else
  41. if [ -z $2 ];then
  42. printf "Please give your install tar archive as second parameter\n"
  43. exit 2
  44. fi
  45. if [ -f $2 ];then
  46. printf "Installing $2 on $1\n"
  47. else
  48. printf "$2 is not a file, Exiting\n"
  49. exit 1
  50. fi
  51. if [ -b $1 ];then
  52. printf "Using $1 as CF/USB disk for installation\n"
  53. if [ $quiet -eq 0 ];then
  54. printf "This will destroy all data on $1, are you sure?\n"
  55. printf "Type "y" to continue\n"
  56. read y
  57. fi
  58. else
  59. printf "Sorry $1 is not a block device\n"
  60. exit 1
  61. fi
  62. fi
  63. if [ $(mount | grep $1| wc -l) -ne 0 ];then
  64. printf "Block device $1 is in use, please umount first.\n"
  65. exit 1
  66. fi
  67. case $2 in
  68. wrap*)
  69. speed=38400
  70. ;;
  71. *)
  72. speed=115200
  73. ;;
  74. esac
  75. rootpart=${1}1
  76. pt=$TOPDIR/bin/tools/pt
  77. # get sector size from block device
  78. maxsector=$(sudo $pt -g $1)
  79. head=16
  80. sect=63
  81. rsize=$(($maxsector / 2))
  82. printf "Creating partition table ...\n"
  83. table=$(mktemp)
  84. # generate partition table
  85. $pt -o $table -s $sect -h $head -p ${rsize}K
  86. # write partition table to block device
  87. dd if=$table of=$1 bs=512 count=1 2> /dev/null
  88. printf "Creating ext2 filesystem ...\n"
  89. $mke2fs -q ${1}1
  90. printf "Extracting install archive ...\n"
  91. tmp=$(mktemp -d)
  92. mount -t ext2 ${rootpart} $tmp
  93. tar -C $tmp -xzpf $2
  94. printf "Fixing permissions ...\n"
  95. chmod 1777 $tmp/tmp
  96. chmod 4755 $tmp/bin/busybox
  97. printf "Installing GRUB bootloader ...\n"
  98. mkdir -p $tmp/boot/grub
  99. cat << EOF > $tmp/boot/grub/grub.cfg
  100. set default=0
  101. set timeout=1
  102. terminal_output console
  103. terminal_input console
  104. menuentry "GNU/Linux (OpenADK)" {
  105. insmod ext2
  106. set root=(hd0,1)
  107. linux /boot/vmlinuz-adk init=/init
  108. }
  109. EOF
  110. ./bin/tools/sbin/grub-install \
  111. --grub-setup=./bin/tools/sbin/grub-setup \
  112. --grub-mkimage=./bin/tools/bin/grub-mkimage \
  113. --grub-mkdevicemap=./bin/tools/sbin/grub-mkdevicemap \
  114. --no-floppy --modules=ext2 --root-directory=$tmp $1
  115. umount $tmp
  116. printf "Successfully installed.\n"
  117. rm -rf $tmp
  118. exit 0