install.sh 2.5 KB

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