install.sh 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. #!/bin/sh
  2. # $Id$
  3. if [ $(id -u) -ne 0 ];then
  4. printf "Installation is only possible as root\n"
  5. exit 1
  6. fi
  7. cfgfs=1
  8. while getopts "n" option
  9. do
  10. case $option in
  11. n)
  12. cfgfs=0
  13. ;;
  14. *)
  15. printf "Option not recognized\n"
  16. exit 1
  17. ;;
  18. esac
  19. done
  20. shift $(($OPTIND - 1))
  21. printf "Checking if grub is installed"
  22. grub=$(which grub)
  23. if [ -x $grub ];then
  24. printf "...okay\n"
  25. else
  26. printf "...failed\n"
  27. exit 1
  28. fi
  29. printf "Checking if sfdisk is installed"
  30. sfdisk=$(which sfdisk)
  31. if [ -x $sfdisk ];then
  32. printf "...okay\n"
  33. else
  34. printf "...failed\n"
  35. exit 1
  36. fi
  37. printf "Checking if parted is installed"
  38. parted=$(which parted)
  39. if [ -x $parted ];then
  40. printf "...okay\n"
  41. else
  42. printf "...failed\n"
  43. exit 1
  44. fi
  45. printf "Checking if mke2fs is installed"
  46. mke2fs=$(which mke2fs)
  47. if [ -x $mke2fs ];then
  48. printf "...okay\n"
  49. else
  50. printf "...failed\n"
  51. exit 1
  52. fi
  53. printf "Checking if tune2fs is installed"
  54. tune2fs=$(which tune2fs)
  55. if [ -x $tune2fs ];then
  56. printf "...okay\n"
  57. else
  58. printf "...failed\n"
  59. exit 1
  60. fi
  61. if [ -z $1 ];then
  62. printf "Please give your compact flash device node as first parameter\n"
  63. exit 1
  64. else
  65. if [ -z $2 ];then
  66. printf "Please give your install tar as second parameter\n"
  67. exit 2
  68. fi
  69. if [ -f $2 ];then
  70. printf "Installing $2 on $1\n"
  71. else
  72. printf "$2 is not a file, Exiting\n"
  73. exit 1
  74. fi
  75. if [ -b $1 ];then
  76. printf "Using $1 as CF disk for installation\n"
  77. printf "This will destroy all data on $1, are you sure?\n"
  78. printf "Type "y" to continue\n"
  79. read y
  80. if [ $y = "y" ];then
  81. $sfdisk -l $1 2>&1 |grep 'No medium'
  82. if [ $? -eq 0 ];then
  83. exit 1
  84. else
  85. printf "Starting with installation\n"
  86. fi
  87. else
  88. printf "Exiting.\n"
  89. exit 1
  90. fi
  91. else
  92. printf "Sorry $1 is not a block device\n"
  93. exit 1
  94. fi
  95. fi
  96. if [ $(mount | grep $1| wc -l) -ne 0 ];then
  97. printf "Block device $1 is in use, please umount first.\n"
  98. exit 1
  99. fi
  100. if [ $($sfdisk -l $1 2>/dev/null|grep Empty|wc -l) -ne 4 ];then
  101. printf "Partitions already exist, should I wipe them?\n"
  102. printf "Type y to continue\n"
  103. read y
  104. if [ $y = "y" ];then
  105. printf "Wiping existing partitions\n"
  106. else
  107. printf "Exiting.\n"
  108. exit 1
  109. fi
  110. fi
  111. printf "Create partition and filesystem\n"
  112. if [ $cfgfs -eq 0 ];then
  113. $sfdisk $1 << EOF
  114. ,,L
  115. ;
  116. ;
  117. ;
  118. y
  119. EOF
  120. $mke2fs ${1}1
  121. else
  122. declare -i maxsize
  123. maxsize=$(parted $1 -s unit cyl print |awk '/^Disk/ { print $3 }'|sed -e 's/cyl//')
  124. let rootsize=$maxsize-1
  125. $parted -s $1 mklabel msdos
  126. $parted -s $1 unit cyl mkpartfs primary ext2 0 $rootsize
  127. $parted -s $1 unit cyl mkpart primary ext2 $rootsize $maxsize
  128. $parted -s $1 set 1 boot on
  129. fi
  130. if [ $? -eq 0 ];then
  131. printf "Successfully created partition ${1}1\n"
  132. else
  133. printf "Partition creation failed, Exiting.\n"
  134. exit 1
  135. fi
  136. sleep 4
  137. $tune2fs -c 0 -i 0 ${1}1 >/dev/null
  138. if [ $? -eq 0 ];then
  139. printf "Successfully disabled filesystem checks on ${1}1\n"
  140. else
  141. printf "Disabling filesystem checks failed, Exiting.\n"
  142. fi
  143. tmp=$(mktemp -d)
  144. mount -t ext2 ${1}1 $tmp
  145. printf "Extracting install archive\n"
  146. tar -C $tmp -xzpf $2
  147. printf "Fixing permissions\n"
  148. chmod 1777 $tmp/tmp
  149. chmod 4755 $tmp/bin/busybox
  150. printf "Copying grub files\n"
  151. mkdir $tmp/boot/grub
  152. cp /boot/grub/stage1 $tmp/boot/grub
  153. cp /boot/grub/stage2 $tmp/boot/grub
  154. cp /boot/grub/e2fs_stage1_5 $tmp/boot/grub
  155. cat << EOF > $tmp/boot/grub/menu.lst
  156. serial --unit=0 --speed=115200 --word=8 --parity=no --stop=1
  157. terminal --timeout=2 serial console
  158. timeout 2
  159. default 0
  160. hiddenmenu
  161. title linux
  162. root (hd0,0)
  163. kernel /boot/kernel root=/dev/sda1 init=/init console=ttyS0,115200 console=tty0 panic=10 rw
  164. EOF
  165. printf "Installing Grub bootloader\n"
  166. $grub --batch --no-curses --no-floppy --device-map=/dev/null >/dev/null << EOF
  167. device (hd0) $1
  168. root (hd0,0)
  169. setup (hd0)
  170. quit
  171. EOF
  172. printf "Creating device nodes\n"
  173. mknod -m 666 $tmp/dev/null c 1 3
  174. mknod -m 622 $tmp/dev/console c 5 1
  175. mknod -m 666 $tmp/dev/tty c 5 0
  176. umount $tmp
  177. printf "Successfully installed.\n"
  178. exit 0